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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
from base import *
from question import Question, QuestionManager
class QuestionView(models.Model):
question = models.ForeignKey(Question, related_name='viewed')
who = models.ForeignKey(User, related_name='question_views')
when = models.DateTimeField()
class Meta:
app_label = 'forum'
class FavoriteQuestion(models.Model):
"""A favorite Question of a User."""
question = models.ForeignKey(Question)
user = models.ForeignKey(User, related_name='user_favorite_questions')
added_at = models.DateTimeField(default=datetime.datetime.now)
class Meta:
app_label = 'forum'
db_table = u'favorite_question'
def __unicode__(self):
return '[%s] favorited at %s' %(self.user, self.added_at)
class QuestionRevision(ContentRevision):
"""A revision of a Question."""
question = models.ForeignKey(Question, related_name='revisions')
title = models.CharField(max_length=300)
tagnames = models.CharField(max_length=125)
class Meta(ContentRevision.Meta):
db_table = u'question_revision'
ordering = ('-revision',)
def get_question_title(self):
return self.question.title
def get_absolute_url(self):
#print 'in QuestionRevision.get_absolute_url()'
return reverse('question_revisions', args=[self.question.id])
def save(self, **kwargs):
"""Looks up the next available revision number."""
if not self.revision:
self.revision = QuestionRevision.objects.filter(
question=self.question).values_list('revision',
flat=True)[0] + 1
super(QuestionRevision, self).save(**kwargs)
def __unicode__(self):
return u'revision %s of %s' % (self.revision, self.title)
class AnonymousQuestion(AnonymousContent):
title = models.CharField(max_length=300)
tagnames = models.CharField(max_length=125)
def publish(self,user):
added_at = datetime.datetime.now()
QuestionManager.create_new(title=self.title, author=user, added_at=added_at,
wiki=self.wiki, tagnames=self.tagnames,
summary=self.summary, text=self.text)
self.delete()
from answer import Answer, AnswerManager
class AnswerRevision(ContentRevision):
"""A revision of an Answer."""
answer = models.ForeignKey('Answer', related_name='revisions')
def get_absolute_url(self):
return reverse('answer_revisions', kwargs={'id':self.answer.id})
def get_question_title(self):
return self.answer.question.title
class Meta(ContentRevision.Meta):
db_table = u'answer_revision'
ordering = ('-revision',)
def save(self, **kwargs):
"""Looks up the next available revision number if not set."""
if not self.revision:
self.revision = AnswerRevision.objects.filter(
answer=self.answer).values_list('revision',
flat=True)[0] + 1
super(AnswerRevision, self).save(**kwargs)
class AnonymousAnswer(AnonymousContent):
question = models.ForeignKey('Question', related_name='anonymous_answers')
def publish(self,user):
added_at = datetime.datetime.now()
#print user.id
AnswerManager.create_new(question=self.question,wiki=self.wiki,
added_at=added_at,text=self.text,
author=user)
self.delete()
|