# HG changeset patch # User Puneeth Chaganti # Date 1296370926 -19800 # Node ID e6e33366df0f2ba80ff34da8160e8c2c2f605f9f # Parent de4a2ed2f34b78c521904304b3fba5174461461f Clean up backup files and .pyc files. diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/__init__.pyc Binary file sphinx_django/__init__.pyc has changed diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/db_script.py~ --- a/sphinx_django/db_script.py~ Wed Oct 27 13:59:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -from sqlalchemy import * - -db = create_engine('sqlite:///test.db') - -db.echo = False # Try changing this to True and see what happens - -metadata = MetaData(db) - -chapter = Table('Chapter', metadata, - Column('id', Integer, primary_key=True), - Column('name', String(40)), -) -chapter.create() - -i = users.insert() -i.execute(name='basic_func') - diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/settings.pyc Binary file sphinx_django/settings.pyc has changed diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/settings.py~ --- a/sphinx_django/settings.py~ Wed Oct 27 13:59:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -# Django settings for sphinx_django project. -import os - -DEBUG = True -TEMPLATE_DEBUG = DEBUG - -ADMINS = ( - ('Amit Sethi', 'amit.pureenergy@gmail.com'), -) - -MANAGERS = ADMINS - -DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. -DATABASE_NAME = 'test.db' # Or path to database file if using sqlite3. -DATABASE_USER = '' # Not used with sqlite3. -DATABASE_PASSWORD = '' # Not used with sqlite3. -DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. -DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. - -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# If running in a Windows environment this must be set to the same as your -# system time zone. -TIME_ZONE = 'America/Chicago' - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'en-us' - -SITE_ID = 1 - -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. -USE_I18N = True - -# Absolute path to the directory that holds media. -# Example: "/home/media/media.lawrence.com/" -MEDIA_ROOT = '' - -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash if there is a path component (optional in other cases). -# Examples: "http://media.lawrence.com", "http://example.com/media/" -MEDIA_URL = '' - -# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a -# trailing slash. -# Examples: "http://foo.com/media/", "/media/". -ADMIN_MEDIA_PREFIX = '/media/' - -# Make this unique, and don't share it with anybody. -SECRET_KEY = '21^&3e-nh_hxqkruwj72gtwy^$i6t$#gbn&r36u0tj+ydk&&g8' - -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.load_template_source', - 'django.template.loaders.app_directories.load_template_source', -# 'django.template.loaders.eggs.load_template_source', -) - -MIDDLEWARE_CLASSES = ( - 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', -) - -ROOT_URLCONF = 'sphinx_django.urls' - - - - -TEMPLATE_DIRS = ( - "/home/amit/review/sphinx_django/templates/" - - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) -# Path of your sphinx static files -SPHINX_PROJECT = 'SPHINX STATIC FILES' -INSTALLED_APPS = ( - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'sphinx_django.sphinxcomment', -) diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/sphinxcomment/__init__.pyc Binary file sphinx_django/sphinxcomment/__init__.pyc has changed diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/sphinxcomment/admin.pyc Binary file sphinx_django/sphinxcomment/admin.pyc has changed diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/sphinxcomment/admin.py~ --- a/sphinx_django/sphinxcomment/admin.py~ Wed Oct 27 13:59:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -from django.contrib import admin -from sphinx_django.sphinxcomment.models import Comment, Element - -class CommentAdmin(admin.ModelAdmin): - list_display = ['element', 'submitter_name', 'comment', 'reviewed', - 'hidden', 'date'] - search_fields = ['comment'] - date_hierarchy = 'date' - list_filter = ['date', 'submitter_name'] - search_fields = ['title', 'submitter_name', 'submitter_url'] - fieldsets = ( - (None, {'fields': ('submitter_name', 'element', 'comment')}), - ('Review and presentation state', {'fields': ('reviewed', 'hidden')}), - ('Other info', {'fields': ('submitter_url', 'ip')}), - ) - # XXX: adding 'date' to the 'Other info' fieldset results in a - # ImproperlyConfigured error. :S - -class ElementAdmin(admin.ModelAdmin): - search_fields = ['id', 'chapter'] - list_filter = ['chapter', 'title'] - -admin.site.register(Comment, CommentAdmin) -admin.site.register(Element, ElementAdmin) diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/sphinxcomment/models.pyc Binary file sphinx_django/sphinxcomment/models.pyc has changed diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/sphinxcomment/models.py~ --- a/sphinx_django/sphinxcomment/models.py~ Wed Oct 27 13:59:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -from django.db import models - -# Create your models here. -from django.db import models - - -mutable = True - -class Element(models.Model): - paragraph_id = models.CharField('Paragraph Id', max_length=100, editable=False, primary_key=True) - chapter_name = models.CharField('Chapter name', max_length=100, editable=False,db_index=True) - - - def __unicode__(self): - return self.paragraph_id - -class Comment(models.Model): - element = models.ForeignKey(Element, - help_text='ID of paragraph that was commented on') - comment = models.TextField(editable=mutable, - help_text='Text of submitted comment (please do not modify)') - submitter_name = models.CharField('Submitter', max_length=64, - help_text='Self-reported name of submitter (may be bogus)') - submitter_url = models.URLField('URL', blank=True, editable=mutable, - help_text='Self-reported URL of submitter (may be empty or bogus)') - ip = models.IPAddressField('IP address', editable=mutable, - help_text='IP address from which comment was submitted') - date = models.DateTimeField('date submitted', auto_now=True, - auto_now_add=True) - - def __unicode__(self): - return self.comment[:32] - - diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/sphinxcomment/views.pyc Binary file sphinx_django/sphinxcomment/views.pyc has changed diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/sphinxcomment/views.py~ --- a/sphinx_django/sphinxcomment/views.py~ Wed Oct 27 13:59:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +0,0 @@ -# Create your views here. -from django.http import HttpResponse -from django.utils.simplejson import dumps -from django.contrib.csrf.middleware import csrf_exempt -import django.forms as forms -from django.db import connection -from django.http import HttpResponse,Http404 -from sphinxcomment.models import Comment, Element -from django.shortcuts import get_object_or_404, render_to_response -from django.template import Context -from django.template.loader import get_template -from django.utils.simplejson import dumps -from django.conf import settings -from os.path import join, splitext -from BeautifulSoup import BeautifulSoup as bss, Tag - -#placeholder_string = open('paragraph_id.py').read() -#exec placeholder_string - -def dump_queries(): - # requires settings.DEBUG to be set to True in order to work - if len(connection.queries) == 1: - print connection.queries - else: - qs = {} - for q in connection.queries: - qs[q['sql']] = qs.setdefault(q['sql'], 0) + 1 - for q in sorted(qs.items(), key=lambda x: x[1], reverse=True): - print q - print len(connection.queries) - -class CommentForm(forms.Form): - name = forms.CharField(max_length=64) - url = forms.URLField(max_length=128, required=False) - comment = forms.CharField(widget=forms.Textarea(attrs={ - 'rows': 8, 'cols': 60 - })) - remember = forms.BooleanField(initial=True, required=False) - -def comments_by_chapter(chapter): - objs = {} - - for c in Comment.objects.filter(element__chapter_name=chapter).order_by('date'): - objs.setdefault(c.element.paragraph_id, []).append(c) - - - - - return objs - - - - - - - -# def chapter(request): -# template = get_template('comment.html') -# resp = {} -# for elt, comments in comments_by_chapter(chapter).iteritems(): -# print elt ,comments -# form = CommentForm(initial={ -# 'paragraph_id': elt, -# 'name': name -# }) -# resp[elt] = template.render(Context({ -# 'paragraph_id': elt, -# 'form': form, -# 'length': len(comments), -# 'query': comments, -# })) -# return HttpResponse(dumps(resp), mimetype='application/json') - -def chapter_count(request,chapter_name): - print chapter_name - chapter_name=chapter_name.split('.')[0] - comment_objs = comments_by_chapter(chapter_name) - resp={} - temp_dict={} - for elt, comments in comment_objs.iteritems(): - temp_dict[elt]=len(comments) - - resp['count']=temp_dict - - - print resp - return HttpResponse(dumps(resp), mimetype='application/json') - -def single(request,paragraph_id, form=None, newid=None): - if paragraph_id[-1]=='/': - paragraph_id=paragraph_id[:-1] - queryset = Comment.objects.filter(element=paragraph_id) - print len(queryset) - if form is None: - form = CommentForm(initial={ - 'paragraph_id': paragraph_id, - 'name': request.session.get('name', ''), - }) - try: - error = form.errors[0] - except: - error = '' - print form.errors - return render_to_response('comment.html', { - 'paragraph_id': paragraph_id, - 'form': form, - 'length': len(queryset), - 'query': queryset, - 'newid': newid or True, - 'error': error, - }) - - - - -def submit(request, paragraph_id): - - try: - element = get_object_or_404(Element, paragraph_id=paragraph_id) - except Http404: - #creating chapter name from paragraph_id surely there is a better way using the context but i do not know as yet - chapter_id='_'.join(paragraph_id.split('_')[0:-1]) - chapter_name=chapter_id[-1::-1].replace('_','/',1)[-1::-1] - element=Element(chapter_name=chapter_name,paragraph_id=paragraph_id) - element.save() - print element.chapter_name - form = None - newid = None - - if request.method == 'POST': - form = CommentForm(request.POST) - print form.errors - if form.is_valid(): - print form.cleaned_data - data = form.cleaned_data - if data.get('remember'): - request.session['name'] = data['name'] - request.session['url'] = data['url'] - else: - request.session.pop('name', None) - request.session.pop('url', None) - c = Comment(element=element, - comment=data['comment'], - submitter_name=data['name'], - submitter_url=data['url'], - ip=request.META.get('REMOTE_ADDR')) - print c - c.save() - - form = None - return single(request, paragraph_id, form,) - -def test(request): - print request - string="

test comment

" - return HttpResponse(string,mimetype="text/plain") - -def page(req, path): - if splitext(path)[1] == '.html': - soup = bss(open(join(settings.SPHINX_PROJECT, path)).read()) - head = soup.find('head') - first_script = Tag(soup, 'script') - first_script['src'] = "_static/simplecomment.js" - first_script['type'] = "text/javascript" - second_script = Tag(soup, 'script') - second_script['src'] = "_static/jquery.form.js" - second_script['type'] = "text/javascript" - head.insert(-1, first_script) - head.insert(-1, second_script) - counter = 0 - page_identity = path.split('.')[0].replace('/', '_') - for p in soup.findAll('p'): - p['id'] = '%s_%s' %(page_identity, counter) - counter += 1 - return HttpResponse(str(soup)) - else: - return HttpResponse(open(join(settings.SPHINX_PROJECT, path)).read()) - -#return HttpResponse(dumps(string),mimetype="text/plain") -#test= csrf_exempt(test) - diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/templates/comment.html~ --- a/sphinx_django/templates/comment.html~ Wed Oct 27 13:59:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -{% ifequal length 1 %} - One comment -{% else %} - {% if length %} - {{ length }} comments - {% else %} - No comments - - {% endif %} -{% endifequal %} -{% for c in query %} - -{% endfor %} -
- {{ form.id }} - - - - - - - - - -
Comment
{{ form.comment }}
Your name{{ form.name }} - Required so we can give you credit
Your URL{{ form.url }} - Optional link to blog, home page, - etc.
Remember you?{{ form.remember }}
{{ error }}
-
diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/test.db Binary file sphinx_django/test.db has changed diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/urls.pyc Binary file sphinx_django/urls.pyc has changed diff -r de4a2ed2f34b -r e6e33366df0f sphinx_django/urls.py~ --- a/sphinx_django/urls.py~ Wed Oct 27 13:59:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -from django.conf.urls.defaults import * -from django.contrib import admin -# Uncomment the next two lines to enable the admin: -# from django.contrib import admin -admin.autodiscover() - -urlpatterns = patterns('', - # Example: - # (r'^sphinx_django/', include('sphinx_django.foo.urls')), - - (r'^test/','sphinxcomment.views.test' ), - (r'chapter/', 'sphinxcomment.views.chapter'), - (r'count/(?P.+)?$', 'sphinxcomment.views.chapter_count'), - (r'single/(?P[^/]+)/$', 'sphinxcomment.views.single'), - (r'submit/(?P[^/]+)/$', 'sphinxcomment.views.submit'), - (r'^static/(?P.*)$', 'django.views.static.serve', - {'document_root': '/home/amit/review/st-scripts/_build/commenthtml'}), - - # Uncomment the admin/doc line below and add 'django.contrib.admindocs' - # to INSTALLED_APPS to enable admin documentation: - # (r'^admin/doc/', include('django.contrib.admindocs.urls')), - - # Uncomment the next line to enable the admin: - (r'^admin/', include(admin.site.urls)), - (r'^pages/_static/(?P.*)$', 'django.views.static.serve', - {'document_root': '/home/amit/review/st-scripts/_build/commenthtml/_static'}), - - (r'^pages/(?P.*)$', 'sphinxcomment.views.page'), -)