0003-manager-extra_data-selection-for-timesheet-61070.patch
chrono/manager/forms.py | ||
---|---|---|
370 | 370 |
label=_('End date'), |
371 | 371 |
widget=forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'), |
372 | 372 |
) |
373 |
extra_data = forms.CharField( |
|
374 |
label=_('Extra datas'), |
|
375 |
max_length=250, |
|
376 |
required=False, |
|
377 |
help_text=_('Comma separated list of keys defined in extra_data.'), |
|
378 |
) |
|
373 | 379 | |
374 | 380 |
def __init__(self, *args, **kwargs): |
375 | 381 |
self.agenda = kwargs.pop('agenda') |
376 | 382 |
super().__init__(*args, **kwargs) |
377 | 383 | |
378 | 384 |
def get_slots(self): |
385 |
extra_data = self.cleaned_data['extra_data'].split(',') |
|
386 |
extra_data = [d.strip() for d in extra_data if d.strip()] |
|
379 | 387 |
min_start = make_aware( |
380 | 388 |
datetime.datetime.combine(self.cleaned_data['date_start'], datetime.time(0, 0)) |
381 | 389 |
) |
... | ... | |
420 | 428 |
'user_id': subscription.user_external_id, |
421 | 429 |
'user_first_name': subscription.user_first_name, |
422 | 430 |
'user_last_name': subscription.user_last_name, |
431 |
'extra_data': {k: (subscription.extra_data or {}).get(k) or '' for k in extra_data}, |
|
423 | 432 |
'events': copy.deepcopy(event_slots), |
424 | 433 |
} |
425 | 434 | |
... | ... | |
444 | 453 |
'user_id': user_id, |
445 | 454 |
'user_first_name': booking.user_first_name, |
446 | 455 |
'user_last_name': booking.user_last_name, |
456 |
'extra_data': {k: (booking.extra_data or {}).get(k) or '' for k in extra_data}, |
|
447 | 457 |
'events': copy.deepcopy(event_slots), |
448 | 458 |
} |
449 | 459 |
if booking.cancellation_datetime is not None: |
... | ... | |
463 | 473 |
'dates': dates, |
464 | 474 |
'events': events, |
465 | 475 |
'users': users, |
476 |
'extra_data': extra_data, |
|
466 | 477 |
} |
467 | 478 | |
468 | 479 |
def clean(self): |
chrono/manager/templates/chrono/manager_events_timesheet.html | ||
---|---|---|
27 | 27 |
<tr> |
28 | 28 |
<th>{% trans "First name" %}</th> |
29 | 29 |
<th>{% trans "Last name" %}</th> |
30 |
{% for k in slots.extra_data %}<th>{{ k }}</th>{% endfor %} |
|
30 | 31 |
{% if events_num > 1 %}<th>{% trans "Activity" %}</th>{% endif %} |
31 | 32 |
{% for date in slots.dates %}<th class="date">{{ date|date:"D d/m" }}</th>{% endfor %} |
32 | 33 |
</tr> |
... | ... | |
37 | 38 |
{% if forloop.first %} |
38 | 39 |
<td {% if events_num > 1 %}rowspan="{{ events_num }}"{% endif %}>{{ user.user_first_name }}</td> |
39 | 40 |
<td {% if events_num > 1 %}rowspan="{{ events_num }}"{% endif %}>{{ user.user_last_name }}</td> |
41 |
{% for k in slots.extra_data %}<td {% if events_num > 1 %}rowspan="{{ events_num }}"{% endif %}>{{ user.extra_data|get:k }}</td>{% endfor %} |
|
40 | 42 |
{% endif %} |
41 | 43 |
{% if events_num > 1 %}<td>{{ event.event }}</td>{% endif %} |
42 | 44 |
{% for date in slots.dates %} |
tests/manager/test_event.py | ||
---|---|---|
2123 | 2123 |
'user_id': 'user:1', |
2124 | 2124 |
'user_first_name': 'Subscription', |
2125 | 2125 |
'user_last_name': '42', |
2126 |
'extra_data': {}, |
|
2126 | 2127 |
'events': [ |
2127 | 2128 |
{ |
2128 | 2129 |
'event': event2, |
... | ... | |
2147 | 2148 |
], |
2148 | 2149 |
}, |
2149 | 2150 |
] |
2151 |
assert slots['extra_data'] == [] |
|
2150 | 2152 | |
2151 | 2153 | |
2152 | 2154 |
@pytest.mark.freeze_time('2022-02-15') |
... | ... | |
2493 | 2495 |
'dates': {datetime.date(2022, 2, 15): False}, |
2494 | 2496 |
}, |
2495 | 2497 |
] |
2498 | ||
2499 | ||
2500 |
def test_events_timesheet_extra_data(app, admin_user): |
|
2501 |
agenda = Agenda.objects.create(label='Events', kind='events') |
|
2502 |
event = Event.objects.create( |
|
2503 |
start_datetime=make_aware(datetime.datetime(2022, 2, 15, 17, 0)), places=10, agenda=agenda |
|
2504 |
) |
|
2505 |
Booking.objects.create( |
|
2506 |
event=event, |
|
2507 |
user_first_name='User', |
|
2508 |
user_last_name='42', |
|
2509 |
user_external_id='user:1', |
|
2510 |
extra_data={'foo': 'bar', 'baz': 'blah'}, |
|
2511 |
) |
|
2512 | ||
2513 |
login(app) |
|
2514 |
resp = app.get('/manage/agendas/%s/events/timesheet' % agenda.pk) |
|
2515 |
resp.form['date_start'] = '2022-02-01' |
|
2516 |
resp.form['date_end'] = '2022-02-28' |
|
2517 |
resp.form['extra_data'] = ' foo ' |
|
2518 |
resp = resp.form.submit() |
|
2519 |
slots = resp.context['form'].get_slots() |
|
2520 | ||
2521 |
assert len(slots['users']) == 1 |
|
2522 |
assert slots['extra_data'] == ['foo'] |
|
2523 |
assert slots['users'][0]['extra_data']['foo'] == 'bar' |
|
2524 | ||
2525 |
resp.form['extra_data'] = ' foo ,baz,,' |
|
2526 |
resp = resp.form.submit() |
|
2527 |
slots = resp.context['form'].get_slots() |
|
2528 | ||
2529 |
assert len(slots['users']) == 1 |
|
2530 |
assert slots['extra_data'] == ['foo', 'baz'] |
|
2531 |
assert slots['users'][0]['extra_data']['foo'] == 'bar' |
|
2532 |
assert slots['users'][0]['extra_data']['baz'] == 'blah' |
|
2533 | ||
2534 |
resp.form['extra_data'] = 'unknown' |
|
2535 |
resp = resp.form.submit() |
|
2536 |
slots = resp.context['form'].get_slots() |
|
2537 | ||
2538 |
assert len(slots['users']) == 1 |
|
2539 |
assert slots['extra_data'] == ['unknown'] |
|
2540 |
assert slots['users'][0]['extra_data']['unknown'] == '' |
|
2541 | ||
2542 |
Subscription.objects.create( |
|
2543 |
agenda=agenda, |
|
2544 |
user_external_id='user:1', |
|
2545 |
user_first_name='Subscription', |
|
2546 |
user_last_name='41', |
|
2547 |
date_start=datetime.date(2022, 2, 1), |
|
2548 |
date_end=datetime.date(2022, 3, 1), |
|
2549 |
extra_data={'foo': 'baz'}, |
|
2550 |
) |
|
2551 | ||
2552 |
resp.form['extra_data'] = ' foo ' |
|
2553 |
resp = resp.form.submit() |
|
2554 |
slots = resp.context['form'].get_slots() |
|
2555 | ||
2556 |
assert len(slots['users']) == 1 |
|
2557 |
assert slots['extra_data'] == ['foo'] |
|
2558 |
assert slots['users'][0]['extra_data']['foo'] == 'baz' |
|
2559 | ||
2560 |
resp.form['extra_data'] = ' foo ,baz,,' |
|
2561 |
resp = resp.form.submit() |
|
2562 |
slots = resp.context['form'].get_slots() |
|
2563 | ||
2564 |
assert len(slots['users']) == 1 |
|
2565 |
assert slots['extra_data'] == ['foo', 'baz'] |
|
2566 |
assert slots['users'][0]['extra_data']['foo'] == 'baz' |
|
2567 |
assert slots['users'][0]['extra_data']['baz'] == '' |
|
2496 |
- |