CONT: continue the previous change.

This commit is contained in:
2019-01-29 17:25:03 +01:00
parent e6a5f9818a
commit 7667277862
14 changed files with 281 additions and 252 deletions

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from ..validators import IdStringValidator
@@ -12,34 +12,6 @@ BOOTSTRAP_CONTEXT_CHOICES = (
('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_facebook': (68, _(u'Veröffentlichung Facebook'), 'warning'),
'publishing_web': (69, _(u'Veröffentlichung Web'), 'warning'),
'publishing': (70, _(u'Veröffentlichung'), 'warning'),
'published_facebook': (78, _(u'Veröffentlicht Facebook'), 'success'),
'published_web': (79, _(u'Veröffentlicht Web'), 'success'),
'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):
@@ -60,5 +32,24 @@ class EventStatus(models.Model):
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)
return format_html(u'<span class="label label-{context}">{label}</span>',
context=context,
label=self.label)
#return u'<span class="label label-{context}">{label}</span>'.format(context=context,
# 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