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