author | amit |
Thu, 30 Sep 2010 11:36:30 +0530 | |
changeset 0 | 54f784230511 |
child 2 | f5e18f8ed036 |
permissions | -rw-r--r-- |
0
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
1 |
from django.db import models |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
2 |
|
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
3 |
# Create your models here. |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
4 |
from django.db import models |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
5 |
import sha |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
6 |
|
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
7 |
mutable = True |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
8 |
|
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
9 |
class Chapter(models.Model): |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
10 |
id = models.CharField('ID attribute', max_length=64, editable=False, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
11 |
primary_key=True) |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
12 |
chapter = models.CharField('Chapter ID', max_length=100, editable=False, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
13 |
db_index=True) |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
14 |
|
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
15 |
|
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
16 |
def __unicode__(self): |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
17 |
return self.id |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
18 |
|
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
19 |
class Comment(models.Model): |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
20 |
element = models.ForeignKey(Element, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
21 |
help_text='ID of paragraph that was commented on') |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
22 |
comment = models.TextField(editable=mutable, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
23 |
help_text='Text of submitted comment (please do not modify)') |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
24 |
submitter_name = models.CharField('Submitter', max_length=64, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
25 |
help_text='Self-reported name of submitter (may be bogus)') |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
26 |
submitter_url = models.URLField('URL', blank=True, editable=mutable, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
27 |
help_text='Self-reported URL of submitter (may be empty or bogus)') |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
28 |
ip = models.IPAddressField('IP address', editable=mutable, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
29 |
help_text='IP address from which comment was submitted') |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
30 |
date = models.DateTimeField('date submitted', auto_now=True, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
31 |
auto_now_add=True) |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
32 |
reviewed = models.BooleanField(default=False, db_index=True, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
33 |
help_text='Has this comment been reviewed by an author?') |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
34 |
hidden = models.BooleanField(default=False, db_index=True, |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
35 |
help_text='Has this comment been hidden from public display?') |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
36 |
|
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
37 |
def __unicode__(self): |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
38 |
return self.comment[:32] |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
39 |
|
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
40 |
def get_absolute_url(self): |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
41 |
s = sha.new() |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
42 |
s.update(repr(self.comment)) |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
43 |
s.update(repr(self.submitter_name)) |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
44 |
s.update(str(self.date)) |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
45 |
return '/read/%s.html#%s?comment=%s&uuid=%s' % ( |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
46 |
self.element.chapter, self.element.id, self.id, s.hexdigest()[:20] |
54f784230511
Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff
changeset
|
47 |
) |