Projet

Général

Profil

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

root / corbo / models.py @ a3743177

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
class Category(models.Model):
7
    name = models.CharField(max_length=64, blank=False, null=False)
8
    ctime = models.DateTimeField(auto_now_add=True)
9

    
10
    def __unicode__(self):
11
        return self.name
12

    
13
class Announce(models.Model):
14
    title = models.CharField(_('title'), max_length=256,
15
                             help_text=_('maximum 256 characters'))
16
    text = models.TextField(_('text'))
17
    publication_time = models.DateTimeField(_('publication time'), blank=True,
18
                                            null=True, default=timezone.now)
19
    expiration_time = models.DateTimeField(_('expiration time'), blank=True,
20
                                           null=True)
21
    ctime = models.DateTimeField(_('creation time'), auto_now_add=True)
22
    mtime = models.DateTimeField(_('modification time'), auto_now=True)
23
    category  = models.ForeignKey('Category', verbose_name=_('category'))
24

    
25
    def __unicode__(self):
26
        return u'{title} ({id}) at {mtime}'.format(title=self.title,
27
                                    id=self.id, mtime=self.mtime)
28

    
29
    def is_published(self):
30
        if self.publication_time:
31
            if self.expiration_time:
32
                return self.publication_time <= timezone.now() < self.expiration_time
33
            return self.publication_time <= timezone.now()
34

    
35
    def is_expired(self):
36
        if self.expiration_time:
37
            return self.expiration_time > timezone.now()
38

    
39
    def is_not_published(self):
40
        return not self.publication_time
41

    
42
    class Meta:
43
        verbose_name = _('announce')
44
        ordering = ('-mtime',)
45

    
46
class SubscriptionType(models.Model):
47
    subscription = models.ForeignKey('Subscription')
48
    identifier = models.CharField(_('identifier'), max_length=128, blank=True,
49
            help_text=_('ex.: email, mobile phone number, jabber id'))
50

    
51
class Subscription(models.Model):
52
    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user'),
53
                             blank=True, null=True)
54
    category = models.ForeignKey('Category', verbose_name=_('category'))
55
    class Meta:
56
        unique_together = ('user', 'category')
(3-3/9)