X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/3f6f55a25872c1d1465f7bdb59e8a766da9c51cc..a20146248fcfa1c17416ccf3c97277f656242158:/events/models.py diff --git a/events/models.py b/events/models.py index 9c216af..1151a11 100644 --- a/events/models.py +++ b/events/models.py @@ -2,13 +2,17 @@ # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from django.conf import settings +from django.core.exceptions import ValidationError from django.db import models -from django.utils.translation import ugettext_lazy as _ -from migdal.helpers import add_translatable +from django.utils.translation import ugettext_lazy as _, ugettext +from fnpdjango.utils.models.translation import add_translatable class Event(models.Model): date = models.DateTimeField(_('date'), max_length=255, db_index=True) + date_end = models.DateTimeField(_('end date'), max_length=255, + db_index=True, blank=True) link = models.URLField(_('link')) class Meta: @@ -19,9 +23,24 @@ class Event(models.Model): def __unicode__(self): return self.title + def clean(self): + if self.date_end: + if self.date_end < self.date: + raise ValidationError( + ugettext("End date must not be earlier than start.")) + else: + self.date_end = self.date + for lc, ln in settings.LANGUAGES: + if (getattr(self, "published_%s" % lc) and + not getattr(self, "title_%s" % lc)): + raise ValidationError( + ugettext("Published event should have a title in relevant language (%s).") % lc) + add_translatable(Event, { - 'title': models.CharField(_('title'), max_length=255), - 'organizer': models.CharField(_('organizer'), max_length=255, db_index=True), - 'place': models.CharField(_('place'), max_length=255), + 'title': models.CharField(_('title'), max_length=255, blank=True), + 'organizer': models.CharField(_('organizer'), max_length=255, + db_index=True, blank=True), + 'place': models.CharField(_('place'), max_length=255, blank=True), + 'published': models.BooleanField(_('published'), default=False), })