OpenLayers OpenLayers

Changeset 7895

Show
Ignore:
Timestamp:
08/29/08 10:51:02 (3 months ago)
Author:
crschmidt
Message:

add voting.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • project/gallery.openlayers.org/openlayers/faq/models.py

    r7891 r7895  
    22from django.template.defaultfilters import slugify 
    33from openlayers.faq.render import render_text 
     4from djangoratings import RatingField 
    45 
    56# Create your models here. 
     
    2930    modified = models.DateTimeField(auto_now=True)  
    3031 
     32RATING_CHOICES = ( 
     33    (1, 'Up'), 
     34    (0, 'Down'), 
     35) 
     36 
    3137class Question(models.Model): 
    3238    class Admin: pass 
     
    5561    created = models.DateTimeField(auto_now_add=True)  
    5662    modified = models.DateTimeField(auto_now=True)  
     63    rating = RatingField(choices=RATING_CHOICES, allow_anonymous=True, can_change_vote=True) 
    5764 
    5865class QLink(models.Model): 
  • project/gallery.openlayers.org/openlayers/faq/templates/question.html

    r7891 r7895  
    77{{ question.rendered_answer|safe }} 
    88 
     9<form action="/vote/question/" method="POST" target="form_out"> 
     10  <input type="hidden" name="question" value="{{question.id}}" /> 
     11  <input type="hidden" name="score" value="0" /> 
     12</form> 
     13<iframe name="form_out" style="display:none"></iframe>  
     14<p> 
     15  {{ question.rating.score }} out of {{ question.rating.votes }} people found the above answer helpful.  
     16  Did you find it helpful?  
     17  <a href="#" onclick='document.forms[0].score.value=1; document.forms[0].submit();return false'>Yes</a> or  
     18  <a href="#" onclick='document.forms[0].score.value=0;document.forms[0].submit();return false;'>No</a>  
     19</p>  
    920<hr /> 
    1021{% for link in question.qlink_set.all %} 
     
    1223  {{ link.description }} 
    1324  </p> 
    14 {% endfor %}  
     25{% endfor %}  
    1526<a href="#" onclick="document.forms[0].style.display='block'; this.style.display='none'">Add a link</a> 
    1627<form action="/add/qlink/" method="POST" style="display:none"> 
  • project/gallery.openlayers.org/openlayers/faq/urls.py

    r7891 r7895  
    55     (r'^$', 'list'), 
    66     (r'^(?P<all>all)/$', 'list'), 
     7     (r'^vote/question/', 'question_vote'), 
    78     (r'^add/qlink/', 'qlink_upload'), 
    89     (r'^add/(?P<type>category|question)/$', 'add_item'), 
  • project/gallery.openlayers.org/openlayers/faq/views.py

    r7891 r7895  
    33import openlayers.faq.models  
    44 
    5 from django.http import HttpResponseRedirect 
     5from django.http import HttpResponse, HttpResponseRedirect 
    66from django.shortcuts import render_to_response, get_object_or_404 
    77 
     
    6969    else: 
    7070        return render_to_response("form.html", {'form': form}) 
    71          
     71 
     72def question_vote(request): 
     73    q = get_object_or_404(Question, pk=request.POST['question']) 
     74    q.rating.add(score=int(request.POST['score']), user=request.user, ip_address=request.META['REMOTE_ADDR']) 
     75    return HttpResponse(q.rating.score) 
    7276 
    7377def question(request, cat, q):