51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from __future__ import unicode_literals
|
|
from django.db import models
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from ..validators import IdStringValidator
|
|
|
|
BOOTSTRAP_CONTEXT_CHOICES = (
|
|
('default', 'default'),
|
|
('primary', 'primary'),
|
|
('success', 'success'),
|
|
('info', 'info'),
|
|
('warning', 'warning'),
|
|
('danger', 'danger'),
|
|
('black', 'black'),
|
|
)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class EventStatus(models.Model):
|
|
code = models.CharField(primary_key=True, max_length=254, validators=[IdStringValidator])
|
|
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 = _('Veranstaltungsstatus')
|
|
verbose_name_plural = _('Veranstaltungsstati')
|
|
ordering = ['severity']
|
|
|
|
def __str__(self):
|
|
return '{severity} - {code} ({label})'.format(code=self.code,
|
|
severity=self.severity,
|
|
label=self.label)
|
|
|
|
|
|
def get_or_create_event_status(code):
|
|
try:
|
|
obj = EventStatus.objects.get(code=code)
|
|
except EventStatus.DoesNotExist as e:
|
|
from ..workflow import DEFAULT_EVENT_STATI
|
|
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
|