Skip to content

Expand Contacts #124

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 48 additions & 3 deletions mpicms/personal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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 = [
Expand Down Expand Up @@ -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):
"""
Expand All @@ -95,13 +120,16 @@ 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)
is_active = models.BooleanField(_("is active"), default=True)
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()

Expand All @@ -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'),
Expand Down Expand Up @@ -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']
16 changes: 16 additions & 0 deletions mpicms/personal/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from modeltranslation.decorators import register

from .models import Position, Group
from .models import Status
from .models import SpecialFunction


@register(Position)
Expand All @@ -16,3 +18,17 @@ class GroupTR(TranslationOptions):
fields = (
'name',
)


@register(Status)
class StatusTR(TranslationOptions):
fields = (
'title',
)


@register(SpecialFunction)
class SpecialFunctionTR(TranslationOptions):
fields = (
'title',
)
23 changes: 22 additions & 1 deletion mpicms/personal/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
]


Expand Down