- {% blocktrans trimmed %}
- This agenda doesn't have any custody rules yet.
- {% endblocktrans %}
+
+
+
+
+ {% trans "Custody rules" %}
+ {% if has_holidays %}
+ {% trans "Custody rules during holidays" %}
+ {% endif %}
+ {% trans "Exceptional custody periods" %}
+
+
+
+
+ {% if agenda.rules.all %}
+
+ {% else %}
+
+ {% blocktrans trimmed %}
+ This agenda doesn't have any custody rules yet.
+ {% endblocktrans %}
+
+ {% endif %}
+
+
+ {% if has_holidays %}
+
+ {% if agenda.holiday_rules.all %}
+
+ {% else %}
+
+ {% blocktrans trimmed %}
+ This agenda doesn't specify any custody rules during holidays. It means normal rules will be applied.
+ {% endblocktrans %}
+
+ {% endif %}
{% endif %}
+
+
+ {% if exceptional_periods %}
+
+ {% else %}
+
+ {% blocktrans trimmed %}
+ This agenda doesn't have any custody period. They can be used to specify explicit moments when one of the guardian should have custody, regardless of global rules.
+ {% endblocktrans %}
+
+ {% endif %}
+
+
-
-{% if has_holidays %}
-
-
{% trans "Custody rules during holidays" %}
-
- {% if agenda.holiday_rules.all %}
-
- {% else %}
-
- {% blocktrans trimmed %}
- This agenda doesn't specify any custody rules during holidays. It means normal rules will be applied.
- {% endblocktrans %}
-
- {% endif %}
-
-
-{% endif %}
-
-
-
{% trans "Exceptional custody periods" %}
-
- {% if exceptional_periods %}
-
- {% else %}
-
- {% blocktrans trimmed %}
- This agenda doesn't have any custody period. They can be used to specify explicit moments when one of the guardian should have custody, regardless of global rules.
- {% endblocktrans %}
-
- {% endif %}
-
{% endblock %}
diff --git a/chrono/manager/views.py b/chrono/manager/views.py
index 1f2fc074..db720ca3 100644
--- a/chrono/manager/views.py
+++ b/chrono/manager/views.py
@@ -3517,6 +3517,7 @@ unavailability_calendar_import_unavailabilities = UnavailabilityCalendarImportUn
class SharedCustodyAgendaMixin:
agenda = None
+ tab_anchor = None
def set_agenda(self, **kwargs):
self.agenda = get_object_or_404(SharedCustodyAgenda, id=kwargs.get('pk'))
@@ -3547,7 +3548,10 @@ class SharedCustodyAgendaMixin:
return kwargs
def get_success_url(self):
- return reverse('chrono-manager-shared-custody-agenda-settings', kwargs={'pk': self.agenda.id})
+ url = reverse('chrono-manager-shared-custody-agenda-settings', kwargs={'pk': self.agenda.id})
+ if self.tab_anchor:
+ url += '#open:%s' % self.tab_anchor
+ return url
class SharedCustodyAgendaView(SharedCustodyAgendaMixin, RedirectView):
@@ -3671,6 +3675,7 @@ class SharedCustodyAgendaAddHolidayRuleView(SharedCustodyAgendaMixin, CreateView
template_name = 'chrono/manager_agenda_form.html'
form_class = SharedCustodyHolidayRuleForm
model = SharedCustodyHolidayRule
+ tab_anchor = 'holidays'
shared_custody_agenda_add_holiday_rule = SharedCustodyAgendaAddHolidayRuleView.as_view()
@@ -3682,6 +3687,7 @@ class SharedCustodyAgendaEditHolidayRuleView(SharedCustodyAgendaMixin, UpdateVie
form_class = SharedCustodyHolidayRuleForm
model = SharedCustodyHolidayRule
pk_url_kwarg = 'rule_pk'
+ tab_anchor = 'holidays'
shared_custody_agenda_edit_holiday_rule = SharedCustodyAgendaEditHolidayRuleView.as_view()
@@ -3691,6 +3697,7 @@ class SharedCustodyAgendaDeleteHolidayRuleView(SharedCustodyAgendaMixin, DeleteV
template_name = 'chrono/manager_confirm_delete.html'
model = SharedCustodyHolidayRule
pk_url_kwarg = 'rule_pk'
+ tab_anchor = 'holidays'
shared_custody_agenda_delete_holiday_rule = SharedCustodyAgendaDeleteHolidayRuleView.as_view()
@@ -3701,6 +3708,7 @@ class SharedCustodyAgendaAddPeriodView(SharedCustodyAgendaMixin, CreateView):
template_name = 'chrono/manager_agenda_form.html'
form_class = SharedCustodyPeriodForm
model = SharedCustodyPeriod
+ tab_anchor = 'time-periods'
shared_custody_agenda_add_period = SharedCustodyAgendaAddPeriodView.as_view()
@@ -3712,6 +3720,7 @@ class SharedCustodyAgendaEditPeriodView(SharedCustodyAgendaMixin, UpdateView):
form_class = SharedCustodyPeriodForm
model = SharedCustodyPeriod
pk_url_kwarg = 'period_pk'
+ tab_anchor = 'time-periods'
shared_custody_agenda_edit_period = SharedCustodyAgendaEditPeriodView.as_view()
@@ -3721,6 +3730,7 @@ class SharedCustodyAgendaDeletePeriodView(SharedCustodyAgendaMixin, DeleteView):
template_name = 'chrono/manager_confirm_delete.html'
model = SharedCustodyPeriod
pk_url_kwarg = 'period_pk'
+ tab_anchor = 'time-periods'
shared_custody_agenda_delete_period = SharedCustodyAgendaDeletePeriodView.as_view()
diff --git a/tests/manager/test_shared_custody_agenda.py b/tests/manager/test_shared_custody_agenda.py
index 824e4a2c..4f6f7ec2 100644
--- a/tests/manager/test_shared_custody_agenda.py
+++ b/tests/manager/test_shared_custody_agenda.py
@@ -44,7 +44,9 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
resp.form['guardian'] = father.pk
resp.form['days'] = list(range(7))
resp.form['weeks'] = 'even'
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/' % agenda.pk)
+ resp = resp.follow()
assert 'Custody rules are not complete.' in resp.text
assert 'John Doe, daily, on even weeks' in resp.text
@@ -59,7 +61,9 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
resp = resp.click('John Doe, daily, on even weeks')
resp.form['days'] = list(range(6))
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/' % agenda.pk)
+ resp = resp.follow()
assert 'Custody rules are not complete.' in resp.text
resp = resp.click('John Doe, from Monday to Saturday, on even weeks')
@@ -72,7 +76,9 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
resp = resp.form.submit().follow()
resp = resp.click('remove', index=1)
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/' % agenda.pk)
+ resp = resp.follow()
assert SharedCustodyRule.objects.count() == 1
@@ -92,13 +98,17 @@ def test_shared_custody_agenda_settings_periods(app, admin_user):
resp.form['guardian'] = father.pk
resp.form['date_start'] = '2022-03-01'
resp.form['date_end'] = '2022-03-03'
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/#open:time-periods' % agenda.pk)
+ resp = resp.follow()
assert 'This agenda doesn\'t have any custody period.' not in resp.text
assert 'John Doe, 03/01/2022 → 03/03/2022' in resp.text
resp = resp.click('John Doe, 03/01/2022 → 03/03/2022')
resp.form['guardian'] = mother.pk
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/#open:time-periods' % agenda.pk)
+ resp = resp.follow()
assert 'Jane Doe, 03/01/2022 → 03/03/2022' in resp.text
resp = resp.click('Add custody period')
@@ -115,7 +125,9 @@ def test_shared_custody_agenda_settings_periods(app, admin_user):
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk)
resp = resp.click('remove', href='delete')
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/#open:time-periods' % agenda.pk)
+ resp = resp.follow()
assert not SharedCustodyPeriod.objects.exists()
@@ -243,14 +255,18 @@ def test_shared_custody_agenda_holiday_rules(app, admin_user):
resp.form['holiday'].select(text='Vacances de Noël')
resp.form['years'] = 'odd'
resp.form['periodicity'] = 'first-half'
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/#open:holidays' % agenda.pk)
+ resp = resp.follow()
assert SharedCustodyHolidayRule.objects.count() == 1
assert SharedCustodyPeriod.objects.count() == 3
assert 'This agenda doesn\'t have any custody period.' in resp.text
resp = resp.click('John Doe, Vacances de Noël, the first half, on odd years')
resp.form['years'] = ''
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/#open:holidays' % agenda.pk)
+ resp = resp.follow()
assert 'John Doe, Vacances de Noël, the first half' in resp.text
assert SharedCustodyHolidayRule.objects.count() == 1
assert SharedCustodyPeriod.objects.count() == 6
@@ -270,7 +286,9 @@ def test_shared_custody_agenda_holiday_rules(app, admin_user):
assert SharedCustodyPeriod.objects.count() == 12
resp = resp.click('remove', index=1)
- resp = resp.form.submit().follow()
+ resp = resp.form.submit()
+ assert resp.location.endswith('/manage/shared-custody/%s/settings/#open:holidays' % agenda.pk)
+ resp = resp.follow()
assert SharedCustodyHolidayRule.objects.count() == 1
assert SharedCustodyPeriod.objects.count() == 6