Mercurial > agora-palash
comparison apps/snippet/views.py @ 202:499e5f47f278
Add necessary code to views and forms of snippet for Ratings
author | Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com> |
---|---|
date | Fri, 19 Jul 2013 22:09:29 +0500 |
parents | a4f88ac85837 |
children | d534881629ff |
comparison
equal
deleted
inserted
replaced
201:c2a1c8950db2 | 202:499e5f47f278 |
---|---|
105 if request.user.is_authenticated(): | 105 if request.user.is_authenticated(): |
106 default_pygments_style = request.user.get_profile().pygments_style | 106 default_pygments_style = request.user.get_profile().pygments_style |
107 else: | 107 else: |
108 default_pygments_style = PygmentsStyle.objects.get(pk=1) | 108 default_pygments_style = PygmentsStyle.objects.get(pk=1) |
109 | 109 |
110 | |
111 | |
112 score = (snippet.rating.score/snippet.rating.votes) | |
113 | |
114 | |
110 context = { | 115 context = { |
111 'snippet_form': snippet_form, | 116 'snippet_form': snippet_form, |
112 'snippet': snippet, | 117 'snippet': snippet, |
113 'lines': range(snippet.get_linecount()), | 118 'lines': range(snippet.get_linecount()), |
114 'tree': tree, | 119 'tree': tree, |
115 'language': dict(LEXER_LIST)[snippet.lexer], | 120 'language': dict(LEXER_LIST)[snippet.lexer], |
116 'pygments_styles': PygmentsStyle.objects.all(), | 121 'pygments_styles': PygmentsStyle.objects.all(), |
117 'default_style': default_pygments_style, | 122 'default_style': default_pygments_style, |
118 'no_descendants': len(tree) == 1, | 123 'no_descendants': len(tree) == 1, |
119 'show': show, | 124 'show': show, |
125 'score' : score, | |
120 } | 126 } |
121 | 127 |
122 response = render(request, template_name, context) | 128 response = render(request, template_name, context) |
123 | 129 |
124 if is_raw: | 130 if is_raw: |
226 | 232 |
227 def guess_lexer(request): | 233 def guess_lexer(request): |
228 code_string = request.GET.get('codestring', False) | 234 code_string = request.GET.get('codestring', False) |
229 response = simplejson.dumps({'lexer': guess_code_lexer(code_string)}) | 235 response = simplejson.dumps({'lexer': guess_code_lexer(code_string)}) |
230 return HttpResponse(response) | 236 return HttpResponse(response) |
237 | |
238 | |
239 | |
240 #Rating Processing | |
241 def processrating(request,snippet_id): | |
242 from djangoratings.views import AddRatingView | |
243 import django.db.models | |
244 from django.contrib.contenttypes.models import ContentType | |
245 | |
246 | |
247 content_type = ContentType.objects.get(model='snippet').id | |
248 if request.method == 'POST': | |
249 params = { | |
250 'content_type_id': content_type, | |
251 'object_id': get_object_or_404(Snippet,secret_id=snippet_id).id, | |
252 'field_name': 'rating', # Must be the same as the name declared in the model of snippet | |
253 'score': int( request.POST['Rate']) , # the score value sent | |
254 } | |
255 response = AddRatingView()(request, **params) | |
256 if response.status_code == 200: | |
257 return redirect( request.POST['next'] ) |