SEESenv/web/hgbook/comments/models.py
changeset 2 52d12eb31c30
parent 0 8083d21c0020
child 12 9c8d61545b60
equal deleted inserted replaced
1:672eaaab9204 2:52d12eb31c30
       
     1 from django.db import models
       
     2 import hashlib
       
     3 from django.conf import settings
       
     4 from django.contrib.flatpages.models import FlatPage
       
     5 import os
       
     6 from BeautifulSoup import BeautifulSoup
       
     7 import django
       
     8 from django.utils.html import strip_tags
       
     9 import djapian
       
    10 from djapian.indexer import CompositeIndexer ,Indexer
       
    11 mutable = True
       
    12 #standard_url='localhost/review/html/'
       
    13 
       
    14 
       
    15 
       
    16 class Element(models.Model):
       
    17     id = models.CharField('ID attribute', max_length=64, editable=False,
       
    18                           primary_key=True)
       
    19     	
       
    20     chapter = models.CharField('Chapter ID', max_length=100, editable=False,
       
    21                                db_index=True)
       
    22     title = models.CharField('Section title', max_length=256, editable=False)
       
    23 
       
    24     def __unicode__(self):
       
    25         return self.id
       
    26     
       
    27 class Comment(models.Model):
       
    28     element = models.ForeignKey(Element,
       
    29         help_text='ID of paragraph that was commented on')
       
    30     comment = models.TextField(editable=mutable,
       
    31         help_text='Text of submitted comment (please do not modify)')
       
    32     submitter_name = models.CharField('Submitter', max_length=64,
       
    33         help_text='Self-reported name of submitter (may be bogus)')
       
    34     submitter_url = models.URLField('URL', blank=True, editable=mutable,
       
    35         help_text='Self-reported URL of submitter (may be empty or bogus)')
       
    36     ip = models.IPAddressField('IP address', editable=mutable,
       
    37         help_text='IP address from which comment was submitted')
       
    38     date = models.DateTimeField('date submitted', auto_now=True,
       
    39                                 auto_now_add=True)
       
    40     reviewed = models.BooleanField(default=False, db_index=True,
       
    41         help_text='Has this comment been reviewed by an author?')
       
    42     hidden = models.BooleanField(default=False, db_index=True,
       
    43         help_text='Has this comment been hidden from public display?')
       
    44 
       
    45     def __unicode__(self):
       
    46         return self.comment[:32]
       
    47 
       
    48 #    def get_absolute_url(self):
       
    49 #        s = hashlib.new()
       
    50 #        s.update(repr(self.comment))
       
    51 #        s.update(repr(self.submitter_name))
       
    52 #        s.update(str(self.date))
       
    53 #	print '/read/%s.html#%s?comment=%s&uuid=%s' % (
       
    54 #            self.element.chapter, self.element.id, self.id, s.hexdigest()[:20]
       
    55 #            )        
       
    56 #	return '/read/%s.html#%s?comment=%s&uuid=%s' % (
       
    57 #            self.element.chapter, self.element.id, self.id, s.hexdigest()[:20]
       
    58 #            )
       
    59 
       
    60 
       
    61 """
       
    62 for directory,lists,files in os.walk('../html'):
       
    63 	if directory=='../html':
       
    64 		for file in files:
       
    65 			if file.endswith('.html'):
       
    66 				filename=os.path.join('../html/'+file)			
       
    67 				f=open(filename,'r')			
       
    68 				soup = BeautifulSoup(''.join(f.read()))
       
    69 				titletag=soup.html.head.title
       
    70 				body=strip_tags(soup.html.body)				
       
    71 				c=FlatPage(url=standard_url+file,title=titletag.string,content=body)
       
    72 				c.save()		
       
    73 	
       
    74 class FlatPageIndexer( djapian.Indexer ):
       
    75     fields = [ 'title', 'content' ]
       
    76     
       
    77 
       
    78 djapian.space.add_index(FlatPage, FlatPageIndexer, attach_as="indexer")
       
    79 FlatPage.indexer.update()
       
    80 result = FlatPage.indexer.search('lists')
       
    81 for row in result :
       
    82 	print row.instance.url
       
    83 print result.count()
       
    84 
       
    85 """	
       
    86