manager: allow exporting agendas by category (#77790)
gitea/chrono/pipeline/head This commit looks good
Details
gitea/chrono/pipeline/head This commit looks good
Details
This commit is contained in:
parent
c19cc93e39
commit
80b2b70654
|
@ -37,6 +37,7 @@ from django.utils.encoding import force_str
|
||||||
from django.utils.formats import date_format
|
from django.utils.formats import date_format
|
||||||
from django.utils.html import format_html, mark_safe
|
from django.utils.html import format_html, mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.utils.translation import pgettext
|
||||||
|
|
||||||
from chrono.agendas.models import (
|
from chrono.agendas.models import (
|
||||||
WEEK_CHOICES,
|
WEEK_CHOICES,
|
||||||
|
@ -46,6 +47,7 @@ from chrono.agendas.models import (
|
||||||
AgendaNotificationsSettings,
|
AgendaNotificationsSettings,
|
||||||
AgendaReminderSettings,
|
AgendaReminderSettings,
|
||||||
Booking,
|
Booking,
|
||||||
|
Category,
|
||||||
Desk,
|
Desk,
|
||||||
Event,
|
Event,
|
||||||
EventsType,
|
EventsType,
|
||||||
|
@ -1505,7 +1507,7 @@ class AgendaReminderTestForm(forms.Form):
|
||||||
|
|
||||||
|
|
||||||
class AgendasExportForm(forms.Form):
|
class AgendasExportForm(forms.Form):
|
||||||
agendas = forms.BooleanField(label=_('Agendas'), required=False, initial=True)
|
agendas = forms.ChoiceField(label=_('Agendas'), required=True)
|
||||||
resources = forms.BooleanField(label=_('Resources'), required=False, initial=True)
|
resources = forms.BooleanField(label=_('Resources'), required=False, initial=True)
|
||||||
unavailability_calendars = forms.BooleanField(
|
unavailability_calendars = forms.BooleanField(
|
||||||
label=_('Unavailability calendars'), required=False, initial=True
|
label=_('Unavailability calendars'), required=False, initial=True
|
||||||
|
@ -1520,6 +1522,10 @@ class AgendasExportForm(forms.Form):
|
||||||
self.fields['shared_custody'].initial = False
|
self.fields['shared_custody'].initial = False
|
||||||
self.fields['shared_custody'].widget = forms.HiddenInput()
|
self.fields['shared_custody'].widget = forms.HiddenInput()
|
||||||
|
|
||||||
|
self.fields['agendas'].choices = [('all', pgettext('agendas', 'All')), ('none', _('None'))] + [
|
||||||
|
(x.id, x.label) for x in Category.objects.all()
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class SharedCustodyRuleForm(forms.ModelForm):
|
class SharedCustodyRuleForm(forms.ModelForm):
|
||||||
guardian = forms.ModelChoiceField(label=_('Guardian'), queryset=Person.objects.none())
|
guardian = forms.ModelChoiceField(label=_('Guardian'), queryset=Person.objects.none())
|
||||||
|
|
|
@ -15,12 +15,10 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import itertools
|
|
||||||
|
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.core.exceptions import FieldDoesNotExist
|
from django.core.exceptions import FieldDoesNotExist
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Q
|
|
||||||
|
|
||||||
from chrono.agendas.models import (
|
from chrono.agendas.models import (
|
||||||
Agenda,
|
Agenda,
|
||||||
|
@ -34,7 +32,7 @@ from chrono.agendas.models import (
|
||||||
|
|
||||||
|
|
||||||
def export_site(
|
def export_site(
|
||||||
agendas=True,
|
agendas='all',
|
||||||
unavailability_calendars=True,
|
unavailability_calendars=True,
|
||||||
events_types=True,
|
events_types=True,
|
||||||
resources=True,
|
resources=True,
|
||||||
|
@ -51,10 +49,11 @@ def export_site(
|
||||||
data['events_types'] = [x.export_json() for x in EventsType.objects.all()]
|
data['events_types'] = [x.export_json() for x in EventsType.objects.all()]
|
||||||
if unavailability_calendars:
|
if unavailability_calendars:
|
||||||
data['unavailability_calendars'] = [x.export_json() for x in UnavailabilityCalendar.objects.all()]
|
data['unavailability_calendars'] = [x.export_json() for x in UnavailabilityCalendar.objects.all()]
|
||||||
if agendas:
|
if agendas != 'none':
|
||||||
qs1 = Agenda.objects.filter(~Q(kind='virtual'))
|
qs = Agenda.objects.all()
|
||||||
qs2 = Agenda.objects.filter(kind='virtual')
|
if agendas != 'all':
|
||||||
data['agendas'] = [x.export_json() for x in itertools.chain(qs1, qs2)]
|
qs = qs.filter(category=agendas)
|
||||||
|
data['agendas'] = [x.export_json() for x in sorted(qs, key=lambda x: x == 'virtual')]
|
||||||
if shared_custody:
|
if shared_custody:
|
||||||
data['shared_custody_settings'] = SharedCustodySettings.get_singleton().export_json()
|
data['shared_custody_settings'] = SharedCustodySettings.get_singleton().export_json()
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -9,6 +9,7 @@ from webtest import Upload
|
||||||
from chrono.agendas.models import (
|
from chrono.agendas.models import (
|
||||||
Agenda,
|
Agenda,
|
||||||
Booking,
|
Booking,
|
||||||
|
Category,
|
||||||
Desk,
|
Desk,
|
||||||
Event,
|
Event,
|
||||||
MeetingType,
|
MeetingType,
|
||||||
|
@ -54,7 +55,7 @@ def test_export_site(app, admin_user):
|
||||||
assert len(site_json['categories']) == 0
|
assert len(site_json['categories']) == 0
|
||||||
|
|
||||||
resp = app.get('/manage/agendas/export/')
|
resp = app.get('/manage/agendas/export/')
|
||||||
resp.form['agendas'] = False
|
resp.form['agendas'] = 'none'
|
||||||
resp.form['events_types'] = False
|
resp.form['events_types'] = False
|
||||||
resp.form['resources'] = False
|
resp.form['resources'] = False
|
||||||
resp.form['categories'] = False
|
resp.form['categories'] = False
|
||||||
|
@ -302,3 +303,21 @@ def test_export_site_shared_custody_settings(app, admin_user):
|
||||||
|
|
||||||
site_json = json.loads(resp.text)
|
site_json = json.loads(resp.text)
|
||||||
assert 'management_role' in site_json['shared_custody_settings']
|
assert 'management_role' in site_json['shared_custody_settings']
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_site_agendas_of_category(app, admin_user):
|
||||||
|
category_a = Category.objects.create(label='Category A')
|
||||||
|
category_b = Category.objects.create(label='Category B')
|
||||||
|
Agenda.objects.create(label='Foo A', kind='meetings', category=category_a)
|
||||||
|
Agenda.objects.create(label='Bar A', kind='meetings', category=category_a)
|
||||||
|
Agenda.objects.create(label='Foo B', kind='meetings', category=category_b)
|
||||||
|
Agenda.objects.create(label='Bar', kind='meetings')
|
||||||
|
|
||||||
|
login(app)
|
||||||
|
resp = app.get('/manage/agendas/export/')
|
||||||
|
resp.form['agendas'].select(text='Category A')
|
||||||
|
resp = resp.form.submit()
|
||||||
|
|
||||||
|
site_json = json.loads(resp.text)
|
||||||
|
assert len(site_json['agendas']) == 2
|
||||||
|
assert [x['label'] for x in site_json['agendas']] == ['Bar A', 'Foo A']
|
||||||
|
|
Loading…
Reference in New Issue