1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.conf import settings
6 from django.core.exceptions import ValidationError
7 from django.db import models
8 from django.utils.translation import ugettext_lazy as _, ugettext
9 from fnpdjango.utils.models.translation import add_translatable
12 class Event(models.Model):
13 date = models.DateTimeField(_('date'), max_length=255, db_index=True)
14 date_end = models.DateTimeField(_('end date'), max_length=255,
15 db_index=True, blank=True)
16 link = models.URLField(_('link'))
19 verbose_name = _('event')
20 verbose_name_plural = _('events')
23 def __unicode__(self):
28 if self.date_end < self.date:
29 raise ValidationError(
30 ugettext("End date must not be earlier than start."))
32 self.date_end = self.date
33 for lc, ln in settings.LANGUAGES:
34 if (getattr(self, "published_%s" % lc) and
35 not getattr(self, "title_%s" % lc)):
36 raise ValidationError(
37 ugettext("Published event should have a title in relevant language (%s).") % lc)
40 add_translatable(Event, {
41 'title': models.CharField(_('title'), max_length=255, blank=True),
42 'organizer': models.CharField(_('organizer'), max_length=255,
43 db_index=True, blank=True),
44 'place': models.CharField(_('place'), max_length=255, blank=True),
45 'published': models.BooleanField(_('published'), default=False),