From abf70dba29b46047ca3cafe13303ba2e0a3c3083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Fri, 10 Jun 2022 10:17:38 +0200 Subject: [PATCH] agendas: remove CheckType & CheckTypeGroup models (#66015) --- .../migrations/0137_remove_check_type.py | 21 ++ chrono/agendas/models.py | 105 -------- chrono/api/views.py | 15 +- chrono/manager/forms.py | 26 -- chrono/manager/static/css/style.scss | 13 +- .../chrono/manager_check_type_form.html | 36 --- .../chrono/manager_check_type_group_form.html | 31 --- .../chrono/manager_check_type_list.html | 59 ---- .../manager_events_agenda_settings.html | 29 -- .../templates/chrono/manager_home.html | 1 - chrono/manager/urls.py | 36 --- chrono/manager/utils.py | 8 - chrono/manager/views.py | 207 +------------- tests/api/test_agenda.py | 27 +- tests/manager/test_check_type.py | 254 ------------------ tests/manager/test_event.py | 2 +- tests/manager/test_import_export.py | 73 ----- tests/test_agendas.py | 20 -- tests/test_import_export.py | 86 ------ 19 files changed, 33 insertions(+), 1016 deletions(-) create mode 100644 chrono/agendas/migrations/0137_remove_check_type.py delete mode 100644 chrono/manager/templates/chrono/manager_check_type_form.html delete mode 100644 chrono/manager/templates/chrono/manager_check_type_group_form.html delete mode 100644 chrono/manager/templates/chrono/manager_check_type_list.html delete mode 100644 tests/manager/test_check_type.py diff --git a/chrono/agendas/migrations/0137_remove_check_type.py b/chrono/agendas/migrations/0137_remove_check_type.py new file mode 100644 index 00000000..c120c3f4 --- /dev/null +++ b/chrono/agendas/migrations/0137_remove_check_type.py @@ -0,0 +1,21 @@ +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('agendas', '0136_remove_check_type'), + ] + + operations = [ + migrations.RemoveField( + model_name='agenda', + name='check_type_group', + ), + migrations.DeleteModel( + name='CheckType', + ), + migrations.DeleteModel( + name='CheckTypeGroup', + ), + ] diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py index 59568a83..d8260959 100644 --- a/chrono/agendas/models.py +++ b/chrono/agendas/models.py @@ -201,13 +201,6 @@ class Agenda(models.Model): category = models.ForeignKey( 'Category', verbose_name=_('Category'), blank=True, null=True, on_delete=models.SET_NULL ) - check_type_group = models.ForeignKey( - 'CheckTypeGroup', - verbose_name=_('Check type group'), - blank=True, - null=True, - on_delete=models.SET_NULL, - ) default_view = models.CharField(_('Default view'), max_length=20, choices=AGENDA_VIEWS) booking_form_url = models.CharField( _('Booking form URL'), max_length=200, blank=True, validators=[django_template_validator] @@ -398,7 +391,6 @@ class Agenda(models.Model): agenda['events'] = [x.export_json() for x in self.event_set.filter(primary_event__isnull=True)] if hasattr(self, 'notifications_settings'): agenda['notifications_settings'] = self.notifications_settings.export_json() - agenda['check_type_group'] = self.check_type_group.slug if self.check_type_group else None agenda['exceptions_desk'] = self.desk_set.get().export_json() agenda['minimal_booking_delay_in_working_days'] = self.minimal_booking_delay_in_working_days agenda['booking_user_block_template'] = self.booking_user_block_template @@ -445,11 +437,6 @@ class Agenda(models.Model): data['category'] = Category.objects.get(slug=data['category']) except Category.DoesNotExist: del data['category'] - if data.get('check_type_group'): - try: - data['check_type_group'] = CheckTypeGroup.objects.get(slug=data['check_type_group']) - except CheckTypeGroup.DoesNotExist: - raise AgendaImportError(_('Missing "%s" check type group') % data['check_type_group']) if data.get('events_type'): try: data['events_type'] = EventsType.objects.get(slug=data['events_type']) @@ -3059,98 +3046,6 @@ class AgendaReminderSettings(models.Model): return new_settings -class CheckTypeGroup(models.Model): - slug = models.SlugField(_('Identifier'), max_length=160, unique=True) - label = models.CharField(_('Label'), max_length=150) - - class Meta: - ordering = ['label'] - - def __str__(self): - return self.label - - def save(self, *args, **kwargs): - if not self.slug: - self.slug = generate_slug(self) - super().save(*args, **kwargs) - - @property - def base_slug(self): - return slugify(self.label) - - @classmethod - def import_json(cls, data, overwrite=False): - check_types = data.pop('check_types', []) - data = clean_import_data(cls, data) - group, created = cls.objects.update_or_create(slug=data['slug'], defaults=data) - - if overwrite: - CheckType.objects.filter(group=group).delete() - - for check_type in check_types: - check_type['group'] = group - CheckType.import_json(check_type) - - return created, group - - def export_json(self): - return { - 'label': self.label, - 'slug': self.slug, - 'check_types': [a.export_json() for a in self.check_types.all()], - } - - -class CheckTypeManager(models.Manager): - def absences(self): - return self.filter(kind='absence', disabled=False) - - def presences(self): - return self.filter(kind='presence', disabled=False) - - -class CheckType(models.Model): - group = models.ForeignKey(CheckTypeGroup, on_delete=models.CASCADE, related_name='check_types') - slug = models.SlugField(_('Identifier'), max_length=160) - label = models.CharField(_('Label'), max_length=150) - kind = models.CharField( - _('Kind'), - max_length=8, - choices=[('absence', _('Absence')), ('presence', _('Presence'))], - default='absence', - ) - disabled = models.BooleanField(_('Disabled'), default=False) - objects = CheckTypeManager() - - class Meta: - ordering = ['label'] - unique_together = ['group', 'slug'] - - def __str__(self): - return self.label - - def save(self, *args, **kwargs): - if not self.slug: - self.slug = generate_slug(self, group=self.group) - super().save(*args, **kwargs) - - @property - def base_slug(self): - return slugify(self.label) - - @classmethod - def import_json(cls, data): - data = clean_import_data(cls, data) - cls.objects.update_or_create(slug=data['slug'], group=data['group'], defaults=data) - - def export_json(self): - return { - 'label': self.label, - 'slug': self.slug, - 'kind': self.kind, - } - - class Subscription(models.Model): agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE, related_name='subscriptions') user_external_id = models.CharField(max_length=250) diff --git a/chrono/api/views.py b/chrono/api/views.py index 3d1d4353..26a823fe 100644 --- a/chrono/api/views.py +++ b/chrono/api/views.py @@ -380,17 +380,6 @@ def get_agenda_detail(request, agenda, check_events=False): } if check_events: agenda_detail['opened_events_available'] = bool(agenda.get_open_events().filter(full=False)) - if agenda.check_type_group: - agenda_detail['absence_reasons'] = [ - {'id': r.slug, 'slug': r.slug, 'text': r.label, 'label': r.label} - for r in agenda.check_type_group.check_types.all() - if r.kind == 'absence' - ] - agenda_detail['presence_reasons'] = [ - {'id': r.slug, 'slug': r.slug, 'text': r.label, 'label': r.label} - for r in agenda.check_type_group.check_types.all() - if r.kind == 'presence' - ] elif agenda.accept_meetings(): agenda_detail['api'] = { 'meetings_url': request.build_absolute_uri( @@ -742,8 +731,8 @@ class Agendas(APIView): def get(self, request, format=None): agendas_queryset = ( Agenda.objects.all() - .select_related('check_type_group', 'category', 'edit_role', 'view_role', 'events_type') - .prefetch_related('resources', 'check_type_group__check_types') + .select_related('category', 'edit_role', 'view_role', 'events_type') + .prefetch_related('resources') .order_by('label') ) diff --git a/chrono/manager/forms.py b/chrono/manager/forms.py index 592bcb31..317eed13 100644 --- a/chrono/manager/forms.py +++ b/chrono/manager/forms.py @@ -46,8 +46,6 @@ from chrono.agendas.models import ( AgendaNotificationsSettings, AgendaReminderSettings, Booking, - CheckType, - CheckTypeGroup, Desk, Event, EventsType, @@ -73,20 +71,6 @@ from . import widgets from .widgets import SplitDateTimeField, WeekdaysWidget -class CheckTypeForm(forms.ModelForm): - class Meta: - model = CheckType - fields = ['label', 'slug', 'disabled'] - - def clean_slug(self): - slug = self.cleaned_data['slug'] - - if self.instance.group.check_types.filter(slug=slug).exclude(pk=self.instance.pk).exists(): - raise ValidationError(_('Another check type exists with the same identifier.')) - - return slug - - class AgendaAddForm(forms.ModelForm): edit_role = forms.ModelChoiceField( label=_('Edit Role'), required=False, queryset=Group.objects.all().order_by('name') @@ -1326,20 +1310,11 @@ class AgendaBookingCheckSettingsForm(forms.ModelForm): class Meta: model = Agenda fields = [ - 'check_type_group', 'booking_check_filters', 'mark_event_checked_auto', 'disable_check_update', ] - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - if not CheckTypeGroup.objects.exists(): - del self.fields['check_type_group'] - elif Booking.objects.filter(event__agenda=self.instance, user_check_type_slug__isnull=False).exists(): - # not possible to update check_type_group if bookings with non null check_type exist - del self.fields['check_type_group'] - class AgendaNotificationsForm(forms.ModelForm): class Meta: @@ -1438,7 +1413,6 @@ class AgendasExportForm(forms.Form): label=_('Unavailability calendars'), required=False, initial=True ) categories = forms.BooleanField(label=_('Categories'), required=False, initial=True) - check_type_groups = forms.BooleanField(label=_('Check type groups'), required=False, initial=True) events_types = forms.BooleanField(label=_('Events types'), required=False, initial=True) shared_custody = forms.BooleanField(label=_('Shared custody'), required=False, initial=True) diff --git a/chrono/manager/static/css/style.scss b/chrono/manager/static/css/style.scss index 46f207f0..b4f10d88 100644 --- a/chrono/manager/static/css/style.scss +++ b/chrono/manager/static/css/style.scss @@ -72,9 +72,7 @@ h2 span.identifier { margin-top: 0; } -.timeperiods .timeperiod a.add::before, -.check-type-group h3 a.delete::before, -.check-type-group a.add::before { +.timeperiods .timeperiod a.add::before { content: "\f055"; /* plus-circle */ font-family: FontAwesome; padding-right: 1ex; @@ -88,15 +86,6 @@ a.timeperiod-exception-all { content: "\f0ad"; /* wrench */ } -.check-type-group h3 a.delete { - width: 1em; - overflow: hidden; - &::before { - content: "\f057"; /* remove-sign */ - padding-right: 3em; - } -} - .dayview h2 a, .monthview h2 a { padding: 0 1ex; diff --git a/chrono/manager/templates/chrono/manager_check_type_form.html b/chrono/manager/templates/chrono/manager_check_type_form.html deleted file mode 100644 index 09027850..00000000 --- a/chrono/manager/templates/chrono/manager_check_type_form.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "chrono/manager_check_type_list.html" %} -{% load i18n %} - -{% block breadcrumb %} -{{ block.super }} -{% if form.instance.pk %} -{{ form.instance }} -{% else %} -{% trans "New check type" %} -{% endif %} -{% endblock %} - -{% block appbar %} -{% if form.instance.pk %} -

{{ form.instance.group }} - {% trans "Edit check type" %}

-{% else %} -

{{ form.instance.group }} - {% trans "New check type" %}

-{% endif %} -{% endblock %} - -{% block content %} - -
- {% csrf_token %} - {% if is_used %} -

- {% trans "This check type is set on some existing bookings, modify it with caution." %} -

- {% endif %} - {{ form.as_p }} -
- - {% trans 'Cancel' %} -
-
-{% endblock %} diff --git a/chrono/manager/templates/chrono/manager_check_type_group_form.html b/chrono/manager/templates/chrono/manager_check_type_group_form.html deleted file mode 100644 index e7270e8b..00000000 --- a/chrono/manager/templates/chrono/manager_check_type_group_form.html +++ /dev/null @@ -1,31 +0,0 @@ -{% extends "chrono/manager_check_type_list.html" %} -{% load i18n %} - -{% block breadcrumb %} -{{ block.super }} -{% if object.pk %} -{{ object }} -{% else %} -{% trans "New check type group" %} -{% endif %} -{% endblock %} - -{% block appbar %} -{% if object.pk %} -

{% trans "Edit check type group" %}

-{% else %} -

{% trans "New check type group" %}

-{% endif %} -{% endblock %} - -{% block content %} - -
- {% csrf_token %} - {{ form.as_p }} -
- - {% trans 'Cancel' %} -
-
-{% endblock %} diff --git a/chrono/manager/templates/chrono/manager_check_type_list.html b/chrono/manager/templates/chrono/manager_check_type_list.html deleted file mode 100644 index 09893c8e..00000000 --- a/chrono/manager/templates/chrono/manager_check_type_list.html +++ /dev/null @@ -1,59 +0,0 @@ -{% extends "chrono/manager_base.html" %} -{% load i18n %} - -{% block breadcrumb %} -{{ block.super }} -{% trans "Check types" %} -{% endblock %} - -{% block appbar %} -

{% trans 'Check types' %}

- -{% trans 'New group' %} - -{% endblock %} - -{% block content %} -
-

{% trans "Define here check types used in events agendas to check bookings." %}

-
-{% for object in object_list %} -
-

- {{ object }} - - {% trans "Export"%} - {% trans "Delete"%} - -

-
- -
-
-{% empty %} -
- {% blocktrans %} - This site doesn't have any check type group yet. Click on the "New group" button in the top - right of the page to add a first one. - {% endblocktrans %} -
-{% endfor %} -{% endblock %} diff --git a/chrono/manager/templates/chrono/manager_events_agenda_settings.html b/chrono/manager/templates/chrono/manager_events_agenda_settings.html index 274b56a5..6d226390 100644 --- a/chrono/manager/templates/chrono/manager_events_agenda_settings.html +++ b/chrono/manager/templates/chrono/manager_events_agenda_settings.html @@ -98,35 +98,6 @@