Projet

Général

Profil

Télécharger (2,55 ko) Statistiques
| Branche: | Tag: | Révision:

root / corbo / models.py @ 8759c981

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
    time = models.DateTimeField(_('sent time'), auto_now_add=True)
57
    result = models.TextField(_('result'), blank=True)
58

    
59
    def __unicode__(self):
60
        return u'announce {id} sent via {channel} at {time}'.format(
61
                id=self.announce.id, channel=self.channel, time=self.time)
62

    
63
    class Meta:
64
        verbose_name = _('sent')
65
        ordering = ('-time',)
66

    
67

    
68
class Subscription(models.Model):
69
    category = models.ForeignKey('Category', verbose_name=_('Category'))
70
    uuid = models.CharField(_('User identifier'), max_length=128, blank=True)
71
    identifier = models.CharField(_('identifier'), max_length=128, blank=True,
72
            help_text=_('ex.: mailto, homepage, ...'))
73
    class Meta:
74
        unique_together = ('category', 'identifier', 'uuid')
(6-6/11)