# HG changeset patch # User Ahsan Ali Shahid # Date 1374253769 -18000 # Node ID 499e5f47f27886c03b8d820d6a83e6800a42befa # Parent c2a1c8950db27c239fdd8313a58cb0ea91e02eca Add necessary code to views and forms of snippet for Ratings diff -r c2a1c8950db2 -r 499e5f47f278 apps/snippet/forms.py --- a/apps/snippet/forms.py Fri Jul 19 21:55:04 2013 +0500 +++ b/apps/snippet/forms.py Fri Jul 19 22:09:29 2013 +0500 @@ -34,6 +34,10 @@ label=_(u'Expires'), ) + + form_choices = ( (x,x) for x in range(1,6) ) + Rate = forms.ChoiceField(form_choices,widget=forms.RadioSelect(attrs={'onclick' :"document.getElementById('rate_form').submit();","class":"rate_radio"})) + def __init__(self, *args, **kwargs): request = kwargs.pop('request') super(SnippetForm, self).__init__(*args, **kwargs) diff -r c2a1c8950db2 -r 499e5f47f278 apps/snippet/views.py --- a/apps/snippet/views.py Fri Jul 19 21:55:04 2013 +0500 +++ b/apps/snippet/views.py Fri Jul 19 22:09:29 2013 +0500 @@ -107,6 +107,11 @@ else: default_pygments_style = PygmentsStyle.objects.get(pk=1) + + + score = (snippet.rating.score/snippet.rating.votes) + + context = { 'snippet_form': snippet_form, 'snippet': snippet, @@ -117,6 +122,7 @@ 'default_style': default_pygments_style, 'no_descendants': len(tree) == 1, 'show': show, + 'score' : score, } response = render(request, template_name, context) @@ -228,3 +234,24 @@ code_string = request.GET.get('codestring', False) response = simplejson.dumps({'lexer': guess_code_lexer(code_string)}) return HttpResponse(response) + + + +#Rating Processing +def processrating(request,snippet_id): + from djangoratings.views import AddRatingView + import django.db.models + from django.contrib.contenttypes.models import ContentType + + + content_type = ContentType.objects.get(model='snippet').id + if request.method == 'POST': + params = { + 'content_type_id': content_type, + 'object_id': get_object_or_404(Snippet,secret_id=snippet_id).id, + 'field_name': 'rating', # Must be the same as the name declared in the model of snippet + 'score': int( request.POST['Rate']) , # the score value sent + } + response = AddRatingView()(request, **params) + if response.status_code == 200: + return redirect( request.POST['next'] ) \ No newline at end of file diff -r c2a1c8950db2 -r 499e5f47f278 static/css/agora.less --- a/static/css/agora.less Fri Jul 19 21:55:04 2013 +0500 +++ b/static/css/agora.less Fri Jul 19 22:09:29 2013 +0500 @@ -488,4 +488,29 @@ .comment-body { padding-left: 15px; +} +#radio_votes +{ + margin:5px; +} +#radio_votes ul +{ + + list-style: none; + display:block; +} +#radio_votes ul li +{ + float:left; + font-weight: bold; + margin: 2px; +} +#rate_label +{ + float:left; + margin-right:3px; +} +.rate_radio +{ + margin:2px; } \ No newline at end of file