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