diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index e7c8035..9eb5967 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 = [ @@ -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): """ @@ -95,6 +120,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) @@ -102,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, verbose_name=_('special functions'), blank=True) objects = ContactManager() @@ -110,10 +138,14 @@ class Contact(index.Indexed, ClusterableModel): FieldPanel('title', classname=''), FieldPanel('first_name'), 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'), @@ -180,3 +212,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/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', + ) diff --git a/mpicms/personal/wagtail_hooks.py b/mpicms/personal/wagtail_hooks.py index 0548aa9..8e3565b 100644 --- a/mpicms/personal/wagtail_hooks.py +++ b/mpicms/personal/wagtail_hooks.py @@ -6,6 +6,9 @@ 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 class ContactInstanceView(InstanceSpecificView): @@ -75,13 +78,31 @@ 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' + + class ContactGroup(ModelAdminGroup): menu_label = _('Contacts') menu_icon = 'user' items = [ ContactAdmin, GroupAdmin, - PositionAdmin + PositionAdmin, + StatusAdmin, + SpecialFunctionAdmin, + WrittenConsentAdmin, ]