1
|
from django.utils import timezone
|
2
|
from django.conf import settings
|
3
|
from django.db import models
|
4
|
from django.utils.translation import ugettext_lazy as _
|
5
|
|
6
|
from ckeditor.fields import RichTextField
|
7
|
|
8
|
channel_choices = (
|
9
|
('mailto', _('Email')),
|
10
|
('homepage', _('Homepage'))
|
11
|
)
|
12
|
|
13
|
class Category(models.Model):
|
14
|
name = models.CharField(max_length=64, blank=False, null=False)
|
15
|
ctime = models.DateTimeField(auto_now_add=True)
|
16
|
|
17
|
def __unicode__(self):
|
18
|
return self.name
|
19
|
|
20
|
|
21
|
class Announce(models.Model):
|
22
|
category = models.ForeignKey('Category', verbose_name=_('category'))
|
23
|
title = models.CharField(_('title'), max_length=256,
|
24
|
help_text=_('maximum 256 characters'))
|
25
|
text = RichTextField(_('Content'))
|
26
|
publication_time = models.DateTimeField(_('publication time'), blank=True,
|
27
|
null=True)
|
28
|
expiration_time = models.DateTimeField(_('Expires on'), blank=True,
|
29
|
null=True)
|
30
|
ctime = models.DateTimeField(_('creation time'), auto_now_add=True)
|
31
|
mtime = models.DateTimeField(_('modification time'), auto_now=True)
|
32
|
|
33
|
def __unicode__(self):
|
34
|
return u'{title} ({id}) at {mtime}'.format(title=self.title,
|
35
|
id=self.id, mtime=self.mtime)
|
36
|
|
37
|
def is_expired(self):
|
38
|
if self.expiration_time:
|
39
|
return self.expiration_time < timezone.now()
|
40
|
return False
|
41
|
|
42
|
def is_published(self):
|
43
|
if self.is_expired():
|
44
|
return False
|
45
|
if self.publication_time:
|
46
|
return self.publication_time <= timezone.now()
|
47
|
return False
|
48
|
|
49
|
class Meta:
|
50
|
verbose_name = _('announce')
|
51
|
ordering = ('-mtime',)
|
52
|
|
53
|
|
54
|
class Broadcast(models.Model):
|
55
|
announce = models.ForeignKey(Announce, verbose_name=_('announce'))
|
56
|
deliver_time = models.DateTimeField(_('Deliver time'), null=True)
|
57
|
result = models.TextField(_('result'), blank=True)
|
58
|
|
59
|
def __unicode__(self):
|
60
|
if self.deliver_time:
|
61
|
return u'announce {id} delivered via at {time}'.format(
|
62
|
id=self.announce.id, time=self.deliver_time)
|
63
|
return u'announce {id} to deliver'.format(id=self.announce.id)
|
64
|
|
65
|
class Meta:
|
66
|
verbose_name = _('sent')
|
67
|
ordering = ('-deliver_time',)
|
68
|
|
69
|
|
70
|
class Subscription(models.Model):
|
71
|
category = models.ForeignKey('Category', verbose_name=_('Category'))
|
72
|
uuid = models.CharField(_('User identifier'), max_length=128, blank=True)
|
73
|
identifier = models.CharField(_('identifier'), max_length=128, blank=True,
|
74
|
help_text=_('ex.: mailto, homepage, ...'))
|
75
|
class Meta:
|
76
|
unique_together = ('category', 'identifier', 'uuid')
|