1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
from base import *
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
class Activity(models.Model):
"""
We keep some history data for user activities
"""
user = models.ForeignKey(User)
activity_type = models.SmallIntegerField(choices=TYPE_ACTIVITY)
active_at = models.DateTimeField(default=datetime.datetime.now)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
is_auditted = models.BooleanField(default=False)
def __unicode__(self):
return u'[%s] was active at %s' % (self.user.username, self.active_at)
class Meta:
app_label = 'forum'
db_table = u'activity'
class EmailFeedSetting(models.Model):
DELTA_TABLE = {
'w':datetime.timedelta(7),
'd':datetime.timedelta(1),
'n':datetime.timedelta(-1),
}
FEED_TYPES = (
('q_all',_('Entire forum')),
('q_ask',_('Questions that I asked')),
('q_ans',_('Questions that I answered')),
('q_sel',_('Individually selected questions')),
)
UPDATE_FREQUENCY = (
('w',_('Weekly')),
('d',_('Daily')),
('n',_('No email')),
)
subscriber = models.ForeignKey(User)
feed_type = models.CharField(max_length=16,choices=FEED_TYPES)
frequency = models.CharField(max_length=8,choices=UPDATE_FREQUENCY,default='n')
added_at = models.DateTimeField(auto_now_add=True)
reported_at = models.DateTimeField(null=True)
def save(self,*args,**kwargs):
type = self.feed_type
subscriber = self.subscriber
similar = self.__class__.objects.filter(feed_type=type,subscriber=subscriber).exclude(pk=self.id)
if len(similar) > 0:
raise IntegrityError('email feed setting already exists')
super(EmailFeedSetting,self).save(*args,**kwargs)
class Meta:
app_label = 'forum'
class AnonymousEmail(models.Model):
#validation key, if used
key = models.CharField(max_length=32)
email = models.EmailField(null=False,unique=True)
isvalid = models.BooleanField(default=False)
class Meta:
app_label = 'forum'
|