manager: do not display shared custody slots before agenda date start (#71588)

This commit is contained in:
Valentin Deniaud 2022-11-23 11:08:00 +01:00 committed by Gitea
parent cb641dac28
commit d8399d3b38
2 changed files with 44 additions and 2 deletions

View File

@ -18,7 +18,11 @@
<tr>
<th>{% trans "Week" %} {{ week }}</th>
{% for slot in slots %}
<td class="guardian {% if slot.guardian == agenda.first_guardian %}first-guardian{% else %}second-guardian{% endif %}">{{ slot }}</td>
{% if slot.date < agenda.date_start %}
<td></td>
{% else %}
<td class="guardian {% if slot.guardian == agenda.first_guardian %}first-guardian{% else %}second-guardian{% endif %}">{{ slot }}</td>
{% endif %}
{% endfor %}
</tr>

View File

@ -157,7 +157,7 @@ def test_shared_custody_agenda_month_view(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, date_start=datetime.date(2022, 1, 1)
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='even')
@ -211,6 +211,44 @@ def test_shared_custody_agenda_month_view(app, admin_user):
app.get('/manage/shared-custody/%s/42/42/' % agenda.pk, status=404)
@pytest.mark.freeze_time('2022-02-01 14:00') # Tuesday
def test_shared_custody_agenda_month_view_date_start(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=datetime.date(2022, 1, 1)
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
app = login(app)
# custody for the whole month
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
assert resp.text.count('<td></td>') == 0
assert len([x.text for x in resp.pyquery('tbody tr td.guardian')]) == 35
# all days are shown
days = [x.text for x in resp.pyquery('tbody tr th span')]
assert len(days) == 7 * 5
# custody for half the month
agenda.date_start = datetime.date(2022, 2, 14)
agenda.save()
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
assert resp.text.count('<td></td>') == 14
assert len([x.text for x in resp.pyquery('tbody tr td.guardian')]) == 21
# all days are still shown
new_days = [x.text for x in resp.pyquery('tbody tr th span')]
assert days == new_days
# month before date_start
resp = resp.click('')
assert resp.text.count('<td></td>') == 42
assert len([x.text for x in resp.pyquery('tbody tr td.guardian')]) == 0
def test_shared_custody_agenda_month_view_queries(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')