manager: default_view for meetings agenda (#51907)
This commit is contained in:
parent
ad0bcd7a88
commit
7535f2be6b
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def set_default_view(apps, schema_editor):
|
||||
Agenda = apps.get_model('agendas', 'Agenda')
|
||||
Agenda.objects.exclude(kind='events').update(default_view='day')
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('agendas', '0076_event_recurrence_end_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(set_default_view, migrations.RunPython.noop),
|
||||
]
|
|
@ -61,6 +61,7 @@ AGENDA_KINDS = (
|
|||
)
|
||||
|
||||
AGENDA_VIEWS = (
|
||||
('day', _('Day view')),
|
||||
('month', _('Month view')),
|
||||
('open_events', _('Open events')),
|
||||
)
|
||||
|
|
|
@ -90,8 +90,11 @@ class AgendaEditForm(forms.ModelForm):
|
|||
def __init__(self, *args, **kwargs):
|
||||
super(AgendaEditForm, self).__init__(*args, **kwargs)
|
||||
if kwargs['instance'].kind != 'events':
|
||||
del self.fields['default_view']
|
||||
del self.fields['booking_form_url']
|
||||
self.initial['default_view'] = 'day'
|
||||
self.fields['default_view'].choices = [
|
||||
(k, v) for k, v in self.fields['default_view'].choices if k != 'open_events'
|
||||
]
|
||||
|
||||
|
||||
class AgendaBookingDelaysForm(forms.ModelForm):
|
||||
|
|
|
@ -797,8 +797,7 @@ agenda_delete = AgendaDeleteView.as_view()
|
|||
|
||||
class AgendaView(ViewableAgendaMixin, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
if self.agenda.kind != 'events':
|
||||
# meetings or virtual - redirect to today view
|
||||
if self.agenda.default_view == 'day':
|
||||
today = datetime.date.today()
|
||||
return redirect(
|
||||
'chrono-manager-agenda-day-view',
|
||||
|
@ -808,9 +807,9 @@ class AgendaView(ViewableAgendaMixin, View):
|
|||
day=today.day,
|
||||
)
|
||||
|
||||
# events agenda - redirect to month or open events view
|
||||
if self.agenda.default_view == 'month':
|
||||
return redirect('chrono-manager-agenda-month-redirect-view', pk=self.agenda.pk)
|
||||
|
||||
return redirect('chrono-manager-agenda-open-events-view', pk=self.agenda.pk)
|
||||
|
||||
|
||||
|
@ -819,12 +818,14 @@ agenda_view = AgendaView.as_view()
|
|||
|
||||
class AgendaMonthRedirectView(ViewableAgendaMixin, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
today = datetime.date.today()
|
||||
if self.agenda.kind != 'events':
|
||||
return redirect('chrono-manager-agenda-view', pk=self.agenda.pk)
|
||||
return redirect(
|
||||
'chrono-manager-agenda-month-view', pk=self.agenda.pk, year=today.year, month=today.month
|
||||
)
|
||||
|
||||
# redirect to monthly view, to first month where there are events,
|
||||
# otherwise to latest month with events, otherwise to this month.
|
||||
today = datetime.date.today()
|
||||
event = self.agenda.event_set.filter(
|
||||
start_datetime__gte=datetime.date(today.year, today.month, 1)
|
||||
).first()
|
||||
|
|
|
@ -216,15 +216,15 @@ def test_events_agenda_month_redirect(app, admin_user):
|
|||
resp = app.get('/manage/agendas/%s/month/' % agenda.pk, status=302)
|
||||
assert resp.location.endswith('/manage/agendas/%s/2020/8/' % agenda.pk)
|
||||
|
||||
# wrong kind
|
||||
# don't check events for meetings
|
||||
agenda.kind = 'virtual'
|
||||
agenda.save()
|
||||
resp = app.get('/manage/agendas/%s/month/' % agenda.pk, status=302)
|
||||
assert resp.location.endswith('/manage/agendas/%s/' % agenda.pk)
|
||||
assert resp.location.endswith('/manage/agendas/%s/2020/7/' % agenda.pk)
|
||||
agenda.kind = 'meetings'
|
||||
agenda.save()
|
||||
resp = app.get('/manage/agendas/%s/month/' % agenda.pk, status=302)
|
||||
assert resp.location.endswith('/manage/agendas/%s/' % agenda.pk)
|
||||
assert resp.location.endswith('/manage/agendas/%s/2020/7/' % agenda.pk)
|
||||
|
||||
|
||||
@freezegun.freeze_time('2020-07-12')
|
||||
|
@ -233,6 +233,11 @@ def test_meetings_agenda_redirect(app, admin_user):
|
|||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/agendas/%s/' % agenda.pk, status=302)
|
||||
assert resp.location.endswith('/manage/agendas/%s/month/' % agenda.pk)
|
||||
|
||||
agenda.default_view = 'day'
|
||||
agenda.save()
|
||||
resp = app.get('/manage/agendas/%s/' % agenda.pk, status=302)
|
||||
assert resp.location.endswith('/manage/agendas/%s/2020/7/12/' % agenda.pk)
|
||||
|
||||
|
||||
|
@ -242,6 +247,11 @@ def test_virtual_agenda_redirect(app, admin_user):
|
|||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/agendas/%s/' % agenda.pk, status=302)
|
||||
assert resp.location.endswith('/manage/agendas/%s/month/' % agenda.pk)
|
||||
|
||||
agenda.default_view = 'day'
|
||||
agenda.save()
|
||||
resp = app.get('/manage/agendas/%s/' % agenda.pk, status=302)
|
||||
assert resp.location.endswith('/manage/agendas/%s/2020/7/12/' % agenda.pk)
|
||||
|
||||
|
||||
|
@ -962,6 +972,8 @@ def test_options_agenda(app, admin_user):
|
|||
resp.form['label'] = 'Foo baz'
|
||||
resp.form['anonymize_delay'] = 365
|
||||
assert 'default_view' in resp.context['form'].fields
|
||||
assert resp.context['form'].initial['default_view'] == 'month'
|
||||
assert 'open_events' in [k for k, v in resp.context['form'].fields['default_view'].choices]
|
||||
assert 'booking_form_url' in resp.context['form'].fields
|
||||
resp = resp.form.submit()
|
||||
assert resp.location.endswith('/manage/agendas/%s/settings' % agenda_events.pk)
|
||||
|
@ -973,11 +985,15 @@ def test_options_agenda(app, admin_user):
|
|||
assert agenda_events.anonymize_delay == 365
|
||||
|
||||
resp = app.get('/manage/agendas/%s/edit' % agenda_meetings.pk)
|
||||
assert 'default_view' not in resp.context['form'].fields
|
||||
assert 'default_view' in resp.context['form'].fields
|
||||
assert resp.context['form'].initial['default_view'] == 'day'
|
||||
assert 'open_events' not in [k for k, v in resp.context['form'].fields['default_view'].choices]
|
||||
assert 'booking_form_url' not in resp.context['form'].fields
|
||||
resp = app.get('/manage/agendas/%s/edit' % agenda_virtual.pk)
|
||||
assert 'default_view' not in resp.context['form'].fields
|
||||
assert 'default_view' in resp.context['form'].fields
|
||||
assert 'booking_form_url' not in resp.context['form'].fields
|
||||
assert resp.context['form'].initial['default_view'] == 'day'
|
||||
assert 'open_events' not in [k for k, v in resp.context['form'].fields['default_view'].choices]
|
||||
|
||||
|
||||
def test_options_agenda_cant_unset_delays(app, admin_user):
|
||||
|
@ -3676,7 +3692,7 @@ def test_meetings_agenda_time_period_exception_source_try_disable_ics(app, admin
|
|||
source = TimePeriodExceptionSource.objects.create(desk=desk, ics_url='https://example.com/test.ics')
|
||||
|
||||
login(app)
|
||||
resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
|
||||
resp = app.get('/manage/agendas/%d/' % agenda.pk).follow().follow()
|
||||
resp = resp.click('Settings')
|
||||
resp = resp.click('manage exceptions')
|
||||
assert 'test.ics' in resp.text
|
||||
|
@ -3699,8 +3715,7 @@ def test_meetings_agenda_time_period_exception_source_from_settings(app, admin_u
|
|||
edit_url = reverse('chrono-manager-time-period-exception-edit', kwargs={'pk': new_year.pk})
|
||||
|
||||
login(app)
|
||||
resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
|
||||
resp = resp.click('Settings')
|
||||
resp = app.get('/manage/agendas/%d/settings' % agenda.pk)
|
||||
assert 'New year' in resp.text
|
||||
assert remove_url not in resp.text and edit_url not in resp.text
|
||||
|
||||
|
|
Loading…
Reference in New Issue