SEESenv/web/hgbook/comments/views.py
author amit@shrike.aero.iitb.ac.in
Wed, 14 Apr 2010 14:38:29 +0530
changeset 54 ce987056033c
parent 6 1ce9b33fb6ff
permissions -rwxr-xr-x
Changed the list of chapter according to the actuall SEES course.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     1
import sys
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     2
import django.forms as forms
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     3
from django.db import connection
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     4
from django.http import HttpResponse
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     5
from hgbook.comments.models import Comment, Element
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     6
from django.shortcuts import get_object_or_404, render_to_response
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     7
from django.template import Context ,RequestContext
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     8
from django.template.loader import get_template
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     9
from django.utils.simplejson import dumps 
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    10
from p_list import *
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    11
from BeautifulSoup import BeautifulSoup
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    12
import glob
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 3
diff changeset
    13
import os
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 3
diff changeset
    14
home_dir=os.getenv("HOME")
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 3
diff changeset
    15
if home_dir=='/home/amit':    
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 3
diff changeset
    16
    html_folder='/home/amit/SEES-hacks/SEESenv/web/html/'
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 3
diff changeset
    17
else:
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 3
diff changeset
    18
    html_folder='/home/hg/repos/SEES-hacks/SEESenv/web/html/'
0
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
def dump_queries():
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    21
    # requires settings.DEBUG to be set to True in order to work
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    22
    if len(connection.queries) == 1:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    23
        print connection.queries
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    24
    else:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    25
        qs = {}
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    26
        for q in connection.queries:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    27
            qs[q['sql']] = qs.setdefault(q['sql'], 0) + 1
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    28
        for q in sorted(qs.items(), key=lambda x: x[1], reverse=True):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    29
            print q
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    30
        print len(connection.queries)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    31
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    32
class CommentForm(forms.Form):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    33
    id = forms.CharField(widget=forms.HiddenInput)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    34
    name = forms.CharField(max_length=64)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    35
    url = forms.URLField(max_length=128, required=False)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    36
    comment = forms.CharField(widget=forms.Textarea(attrs={
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    37
        'rows': 8, 'cols': 60
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    38
        }))
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    39
    remember = forms.BooleanField(initial=True, required=False)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    40
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    41
def search(request):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    42
	print request
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    43
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 index(request):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    46
	html_files = glob.glob(html_folder+'ch*.html')
3
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents: 2
diff changeset
    47
#	print >> sys.stderr ,html_files	
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents: 2
diff changeset
    48
#	print >> sys.stderr ,"just checking whether i got here"	
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents: 2
diff changeset
    49
#	print >> sys.stderr , html_files	
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    50
	html_files.sort()
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    51
	link_list=['/review/html/'+a.split('/')[-1] for a in html_files]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    52
#	print >> sys.stderr , html_files        
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    53
	title_list=[]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    54
	for html_file in html_files:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    55
		file_str=open(html_file,'r').read()			
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    56
		soup_obj=BeautifulSoup(''.join(file_str))
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    57
		title_str=soup_obj.html.head.title.string		
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    58
		title_str=unicode(title_str)		
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    59
		title_str.encode('ascii','ignore')              
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    60
		title_list.append(title_str)
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
	resp_dict=zip(link_list,title_list)
1
672eaaab9204 Added some new html files that failed earlier during change from rst
amit@thunder
parents: 0
diff changeset
    63
	print >>sys.stderr ,resp_dict
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    64
	return render_to_response('index.html', {'resp_dict': resp_dict })
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    65
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    66
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    67
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    68
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    69
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    70
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    71
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    72
def comments_by_chapter(id):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    73
    objs = {}
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    74
    for c in Comment.objects.filter(element=id, hidden=False).order_by('date'):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    75
        objs.setdefault(c.element_id, []).append(c)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    76
    return objs
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
def chapter(request, id):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    79
    template = get_template('comment.html')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    80
    resp = {}
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    81
    for elt, comments in comments_by_chapter(id).iteritems():
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    82
            
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    83
        form = CommentForm(initial={
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    84
            'id': elt,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    85
            'name': request.session.get('name', ''),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    86
            })
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    87
            
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    88
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    89
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    90
    resp[elt] = template.render(RequestContext({
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    91
            'id': elt,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    92
            'form': form,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    93
            'length': len(comments),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    94
            'query': comments,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    95
            }))
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    96
    return HttpResponse(dumps(resp), mimetype='application/json')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    97
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    98
#    queryset = Comment.objects.filter(element=id, hidden=False).order_by('date')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    99
#    if form is None:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   100
#        form = CommentForm(initial={
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   101
#            'id': id,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   102
#            'name': request.session.get('name', ''),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   103
#            })
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   104
#    try:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   105
#        error = form.errors[0]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   106
#    except:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   107
#        error = ''
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   108
#    return render_to_response('comment.html', {
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   109
#        'id': id,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   110
#        'form': form,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   111
#        'length': len(queryset),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   112
#        'query': queryset,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   113
#        'newid': newid or True,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   114
#        'error': error,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   115
#        })
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   116
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   117
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   118
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   119
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   120
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   121
def single_com(request,id):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   122
     
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   123
#    template = get_template('comment.html')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   124
    resp = {}
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   125
    print >> sys.stderr ,id   
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   126
    for i in p_list[id]:	
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   127
#        form=None
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   128
        queryset = Comment.objects.filter(element=i, hidden=False).order_by('date')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   129
                
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   130
#        if form is None:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   131
#		form = CommentForm(initial={
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   132
#		    'id': id,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   133
#		    'name': request.session.get('name', ''),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   134
#        })
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   135
        if len(queryset)==0:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   136
            resp[i] = "No"
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   137
        elif len(queryset)==1:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   138
            resp[i]="One"
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   139
        else:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   140
            resp[i] = len(queryset)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   141
#            'id': i,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   142
#           'form': form,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   143
#            'length': len(queryset),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   144
#            'query': queryset,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   145
            
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   146
    return HttpResponse(dumps(resp), mimetype='application/json')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   147
#    template = get_template('comment.html')    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   148
#    for i in p_list[id]:	
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   149
#        form=None
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   150
#        queryset = Comment.objects.filter(element=i, hidden=False).order_by('date')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   151
#        print queryset        
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   152
#        if form is None:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   153
#		form = CommentForm(initial={
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   154
#		    'id': id,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   155
#		    'name': request.session.get('name', ''),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   156
#		    })
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   157
#       try:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   158
#		    error = form.errors[0]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   159
#        except:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   160
#            error = ''
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   161
	    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   162
#    return HttpResponse(response_list)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   163
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   164
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   165
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   166
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   167
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   168
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   169
def chapter_count(request, id):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   170
      
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   171
    resp = comments_by_chapter(id)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   172
    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   173
    for elt, comments in resp.iteritems():
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   174
              
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   175
        resp[elt] = len(comments)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   176
     
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   177
    return HttpResponse(dumps(resp), mimetype='application/json')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   178
    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   179
def single(request, id, form=None, newid=None ):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   180
    queryset = Comment.objects.filter(element=id, hidden=False).order_by('date')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   181
    if form is None:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   182
        form = CommentForm(initial={
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   183
            'id': id,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   184
            'name': request.session.get('name', ''),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   185
            })
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   186
    try:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   187
        error = form.errors[0]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   188
    except:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   189
        error = ''
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   190
    return render_to_response('comment.html', {
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   191
        'id': id,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   192
        'form': form,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   193
        'length': len(queryset),
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   194
        'query': queryset,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   195
        'newid': newid or True,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   196
        'error': error,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   197
        })
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   198
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   199
def submit(request, id):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   200
#    print request
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   201
#    print id    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   202
    try :    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   203
        element=Element.objects.get(id=id,chapter='chap_intro')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   204
    except Element.DoesNotExist:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   205
        element=Element(id=id)    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   206
	element.save()    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   207
    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   208
   
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   209
    if request.method == 'POST':
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   210
       
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   211
	form = CommentForm(request.POST)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   212
	   
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   213
	if form.is_valid():
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   214
            data = form.cleaned_data
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   215
            
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   216
	    if data.get('remember'):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   217
		               
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   218
		request.session['name'] = data['name']
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   219
                request.session['url'] = data['url']
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   220
            else:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   221
                request.session.pop('name', None)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   222
                request.session.pop('url', None)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   223
            c = Comment(element=element,
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   224
                        comment=data['comment'],
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   225
                        submitter_name=data['name'],
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   226
                        submitter_url=data['url'],
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   227
                        ip=request.META.get('REMOTE_ADDR'))
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   228
          
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   229
			
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   230
	c.save()
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   231
        newid=c.id        
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   232
        form = None
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   233
    return single(request, id, form, newid)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   234