|
from django.utils import timezone
|
|
from django.conf import settings
|
|
from django.db import models
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from ckeditor.fields import RichTextField
|
|
|
|
channel_choices = (
|
|
('mailto', _('Email')),
|
|
('homepage', _('Homepage'))
|
|
)
|
|
|
|
class Category(models.Model):
|
|
name = models.CharField(max_length=64, blank=False, null=False)
|
|
ctime = models.DateTimeField(auto_now_add=True)
|
|
|
|
def __unicode__(self):
|
|
return self.name
|
|
|
|
|
|
class Announce(models.Model):
|
|
category = models.ForeignKey('Category', verbose_name=_('category'))
|
|
title = models.CharField(_('title'), max_length=256,
|
|
help_text=_('maximum 256 characters'))
|
|
text = RichTextField(_('Content'))
|
|
publication_time = models.DateTimeField(_('publication time'), blank=True,
|
|
null=True)
|
|
expiration_time = models.DateTimeField(_('Expires on'), blank=True,
|
|
null=True)
|
|
ctime = models.DateTimeField(_('creation time'), auto_now_add=True)
|
|
mtime = models.DateTimeField(_('modification time'), auto_now=True)
|
|
|
|
def __unicode__(self):
|
|
return u'{title} ({id}) at {mtime}'.format(title=self.title,
|
|
id=self.id, mtime=self.mtime)
|
|
|
|
def is_expired(self):
|
|
if self.expiration_time:
|
|
return self.expiration_time < timezone.now()
|
|
return False
|
|
|
|
def is_published(self):
|
|
if self.is_expired():
|
|
return False
|
|
if self.publication_time:
|
|
return self.publication_time <= timezone.now()
|
|
return False
|
|
|
|
class Meta:
|
|
verbose_name = _('announce')
|
|
ordering = ('-mtime',)
|
|
|
|
|
|
class Broadcast(models.Model):
|
|
announce = models.ForeignKey(Announce, verbose_name=_('announce'))
|
|
time = models.DateTimeField(_('sent time'), auto_now_add=True)
|
|
result = models.TextField(_('result'), blank=True)
|
|
|
|
def __unicode__(self):
|
|
return u'announce {id} sent via {channel} at {time}'.format(
|
|
id=self.announce.id, channel=self.channel, time=self.time)
|
|
|
|
class Meta:
|
|
verbose_name = _('sent')
|
|
ordering = ('-time',)
|
|
|
|
|
|
class Subscription(models.Model):
|
|
category = models.ForeignKey('Category', verbose_name=_('Category'))
|
|
uuid = models.CharField(_('User identifier'), max_length=128, blank=True)
|
|
identifier = models.CharField(_('identifier'), max_length=128, blank=True,
|
|
help_text=_('ex.: mailto, homepage, ...'))
|
|
class Meta:
|
|
unique_together = ('category', 'identifier', 'uuid')
|