Project

General

Profile

Download (2.15 KB) Statistics
| Branch: | Tag: | Revision:

root / corbo / models.py @ 36e2db0b

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

    
12
    def __unicode__(self):
13
        return self.name
14

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

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

    
31
    def is_expired(self):
32
        if self.expiration_time:
33
            return self.expiration_time < timezone.now()
34
        return False
35

    
36
    def is_published(self):
37
        if self.is_expired():
38
            return False
39
        if self.publication_time:
40
            return self.publication_time <= timezone.now()
41
        return False
42

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

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

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