From 1d37a4487cb7453fdc6f1d544c7c1fc6abb94e50 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sat, 8 Jan 2022 18:49:13 +0100 Subject: [PATCH 1/7] personal: Add model WrittenConsent --- mpicms/personal/models.py | 13 +++++++++++++ mpicms/personal/wagtail_hooks.py | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index e7c8035..c1b12bd 100644 --- a/mpicms/personal/models.py +++ b/mpicms/personal/models.py @@ -180,3 +180,16 @@ class Meta: # noqa verbose_name = 'Group' verbose_name_plural = 'Groups' ordering = ['-priority'] + + +class WrittenConsent(models.Model): + ref = models.CharField("ID", max_length=10, unique=True) + comment = models.TextField("comment", blank=True) + valid = models.BooleanField(_("valid"), default=True) + contacts = models.ManyToManyField(Contact, blank = True) + + def __str__(self): + return "Written Consent #" + self.ref + " (" + ", ".join(str(c) for c in self.contacts.all()) + ")" + + class Meta: + ordering = ['ref'] diff --git a/mpicms/personal/wagtail_hooks.py b/mpicms/personal/wagtail_hooks.py index 0548aa9..bc588ab 100644 --- a/mpicms/personal/wagtail_hooks.py +++ b/mpicms/personal/wagtail_hooks.py @@ -6,6 +6,7 @@ from wagtail.contrib.modeladmin.views import EditView, InspectView, DeleteView, InstanceSpecificView from .models import Contact, Group, Position +from .models import WrittenConsent class ContactInstanceView(InstanceSpecificView): @@ -75,13 +76,19 @@ class PositionAdmin(ModelAdmin): search_fields = ['title'] +class WrittenConsentAdmin(ModelAdmin): + model = WrittenConsent + menu_icon='doc-full' + + class ContactGroup(ModelAdminGroup): menu_label = _('Contacts') menu_icon = 'user' items = [ ContactAdmin, GroupAdmin, - PositionAdmin + PositionAdmin, + WrittenConsentAdmin, ] From ab30a5c2fc15f1576dc0423b70f64bdb8a374891 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sat, 8 Jan 2022 19:18:24 +0100 Subject: [PATCH 2/7] personal: Add academic_suffix --- mpicms/personal/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index c1b12bd..64b9a47 100644 --- a/mpicms/personal/models.py +++ b/mpicms/personal/models.py @@ -95,6 +95,7 @@ class Contact(index.Indexed, ClusterableModel): title = models.CharField(_("title"), max_length=5, blank=True) first_name = models.CharField(_("first name"), max_length=50, blank=True) last_name = models.CharField(_("last name"), max_length=50, blank=True) + academic_suffix = models.CharField(_("academic_suffix"), max_length=50, blank=True) email = models.EmailField(_("email"), blank=True) phone = models.CharField(_("phone number"), blank=True, max_length=50) room = models.CharField(_("room"), max_length=50, blank=True) @@ -110,6 +111,7 @@ class Contact(index.Indexed, ClusterableModel): FieldPanel('title', classname=''), FieldPanel('first_name'), FieldPanel('last_name'), + FieldPanel('academic_suffix'), ], heading='Name'), InlinePanel( 'positions', label="Positions", From 29592fa93d8f55390ed3c0a9129c8e72cfcc169e Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sat, 8 Jan 2022 19:33:49 +0100 Subject: [PATCH 3/7] personal: Add Status, SpecialFunction --- mpicms/personal/models.py | 25 +++++++++++++++++++++++++ mpicms/personal/wagtail_hooks.py | 14 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index 64b9a47..bbf9e55 100644 --- a/mpicms/personal/models.py +++ b/mpicms/personal/models.py @@ -79,6 +79,31 @@ def __str__(self): return self.title +class Status(models.Model): + title = models.CharField(_("status"), max_length=50) + + panels = [ + FieldPanel('title') + ] + + def __str__(self): + return self.title + + class Meta: + verbose_name_plural = "status" + + +class SpecialFunction(models.Model): + title = models.CharField(_("special function"), max_length=50) + + panels = [ + FieldPanel('title') + ] + + def __str__(self): + return self.title + + @register_snippet class Contact(index.Indexed, ClusterableModel): """ diff --git a/mpicms/personal/wagtail_hooks.py b/mpicms/personal/wagtail_hooks.py index bc588ab..8e3565b 100644 --- a/mpicms/personal/wagtail_hooks.py +++ b/mpicms/personal/wagtail_hooks.py @@ -6,6 +6,8 @@ from wagtail.contrib.modeladmin.views import EditView, InspectView, DeleteView, InstanceSpecificView from .models import Contact, Group, Position +from .models import Status +from .models import SpecialFunction from .models import WrittenConsent @@ -76,6 +78,16 @@ class PositionAdmin(ModelAdmin): search_fields = ['title'] +class StatusAdmin(ModelAdmin): + model = Status + menu_icon = 'tag' + + +class SpecialFunctionAdmin(ModelAdmin): + model = SpecialFunction + menu_icon = 'tag' + + class WrittenConsentAdmin(ModelAdmin): model = WrittenConsent menu_icon='doc-full' @@ -88,6 +100,8 @@ class ContactGroup(ModelAdminGroup): ContactAdmin, GroupAdmin, PositionAdmin, + StatusAdmin, + SpecialFunctionAdmin, WrittenConsentAdmin, ] From a8d236ac19971bac838153c101e163bb8dface8d Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sat, 8 Jan 2022 20:37:24 +0100 Subject: [PATCH 4/7] personal: Add status and special_functions to Contact --- mpicms/personal/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index bbf9e55..6c1d657 100644 --- a/mpicms/personal/models.py +++ b/mpicms/personal/models.py @@ -128,6 +128,8 @@ class Contact(index.Indexed, ClusterableModel): priority = models.PositiveSmallIntegerField( _("priority"), blank=True, default=0, validators=[MaxValueValidator(999)], help_text=_("Priority from 0-999 to determine the sorting order.")) + status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True) + special_functions = models.ManyToManyField(SpecialFunction, blank=True) objects = ContactManager() @@ -138,9 +140,12 @@ class Contact(index.Indexed, ClusterableModel): FieldPanel('last_name'), FieldPanel('academic_suffix'), ], heading='Name'), + FieldPanel('status'), InlinePanel( 'positions', label="Positions", - panels=None), + panels=None + ), + FieldPanel('special_functions'), FieldPanel('email'), FieldPanel('phone'), FieldPanel('room'), @@ -213,7 +218,7 @@ class WrittenConsent(models.Model): ref = models.CharField("ID", max_length=10, unique=True) comment = models.TextField("comment", blank=True) valid = models.BooleanField(_("valid"), default=True) - contacts = models.ManyToManyField(Contact, blank = True) + contacts = models.ManyToManyField(Contact, blank=True) def __str__(self): return "Written Consent #" + self.ref + " (" + ", ".join(str(c) for c in self.contacts.all()) + ")" From b529e33c82a18b8e759d0c6ba1e84f05c7c056b0 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 11 Jan 2022 14:06:34 +0100 Subject: [PATCH 5/7] personal: Add modeltranslations for new models --- mpicms/personal/translation.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mpicms/personal/translation.py b/mpicms/personal/translation.py index bf716aa..156b175 100644 --- a/mpicms/personal/translation.py +++ b/mpicms/personal/translation.py @@ -2,6 +2,8 @@ from modeltranslation.decorators import register from .models import Position, Group +from .models import Status +from .models import SpecialFunction @register(Position) @@ -16,3 +18,17 @@ class GroupTR(TranslationOptions): fields = ( 'name', ) + + +@register(Status) +class StatusTR(TranslationOptions): + fields = ( + 'title', + ) + + +@register(SpecialFunction) +class SpecialFunctionTR(TranslationOptions): + fields = ( + 'title', + ) From 65eb0cf4d0bd4b063c812130450f7860356eacf2 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 11 Jan 2022 16:19:33 +0100 Subject: [PATCH 6/7] person: fix name of group and position field to singular --- mpicms/personal/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index 6c1d657..c78989f 100644 --- a/mpicms/personal/models.py +++ b/mpicms/personal/models.py @@ -28,7 +28,7 @@ class ContactGroups(Orderable, models.Model): 'personal.Group', related_name='contacts', on_delete=models.CASCADE, - verbose_name=_('groups') + verbose_name=_('group') ) panels = [ @@ -47,7 +47,7 @@ class ContactPositions(Orderable, models.Model): 'personal.Position', related_name='contacts', on_delete=models.CASCADE, - verbose_name=_('positions') + verbose_name=_('position') ) panels = [ From ac09609c0fe262bdf39eebfcdb9287ddf19116ee Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 11 Jan 2022 16:23:50 +0100 Subject: [PATCH 7/7] Contact: make "special functions" attribute translatable --- mpicms/personal/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index c78989f..9eb5967 100644 --- a/mpicms/personal/models.py +++ b/mpicms/personal/models.py @@ -129,7 +129,7 @@ class Contact(index.Indexed, ClusterableModel): _("priority"), blank=True, default=0, validators=[MaxValueValidator(999)], help_text=_("Priority from 0-999 to determine the sorting order.")) status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True) - special_functions = models.ManyToManyField(SpecialFunction, blank=True) + special_functions = models.ManyToManyField(SpecialFunction, verbose_name=_('special functions'), blank=True) objects = ContactManager()