Added a model for event state (including data migration, signal based

notifications, etc.)
This commit is contained in:
2018-07-04 16:56:13 +02:00
parent 0e7c14ace9
commit 3c7ef05099
27 changed files with 712 additions and 355 deletions

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from ..validators import LowerAlphanumericValidator
BOOTSTRAP_CONTEXT_CHOICES = (
('default', 'default'),
('primary', 'primary'),
('success', 'success'),
('info', 'info'),
('warning', 'warning'),
('danger', 'danger'),
)
DEFAULT_EVENT_STATI = {
'void': (0, _(u'Ungültig'), None),
'draft': (10, _(u'Entwurf'), 'info'),
'submitted': (30, _(u'Eingereicht'), 'danger'),
'accepted': (50, _(u'Freigegeben'), 'warning'),
'publishing': (70, _(u'Veröffentlichung'), 'warning'),
'published': (80, _(u'Veröffentlicht'), 'success'),
'expired': (100, _(u'Ausgelaufen'), None),
}
def get_event_status(code):
try:
obj = EventStatus.objects.get(code=code)
except EventStatus.DoesNotExist as e:
if code not in DEFAULT_EVENT_STATI:
raise e
severity = DEFAULT_EVENT_STATI[code][0]
label = DEFAULT_EVENT_STATI[code][1]
obj = EventStatus(code=code, severity=severity, label=label)
if DEFAULT_EVENT_STATI[code][2]:
obj.bootstrap_context = DEFAULT_EVENT_STATI[code][2]
obj.save()
return obj
class EventStatus(models.Model):
code = models.CharField(primary_key=True, max_length=254, validators=[LowerAlphanumericValidator])
severity = models.IntegerField(unique=True)
label = models.CharField(unique=True, max_length=254)
bootstrap_context = models.CharField(max_length=20, blank=True, choices=BOOTSTRAP_CONTEXT_CHOICES)
class Meta:
verbose_name = _(u'Veranstaltungsstatus')
verbose_name_plural = _(u'Veranstaltungsstati')
ordering = ['severity']
def __unicode__(self):
return u'{label} ({severity} {code})'.format(code=self.code,
severity=self.severity,
label=self.label)
def get_bootstrap_label(self):
context = self.bootstrap_context or 'default'
return u'<span class="label label-{context}">{label}</span>'.format(context=context,
label=self.label)