Skip to content

Commit

Permalink
allow POSTing direction, content_type_id and object_id parameters ins…
Browse files Browse the repository at this point in the history
…tead of supplying from within the request URL
  • Loading branch information
onurmatik committed May 14, 2010
1 parent 964fd54 commit 44d68ab
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions voting/views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
from django.contrib.auth.views import redirect_to_login from django.contrib.auth.views import redirect_to_login
from django.template import loader, RequestContext from django.template import loader, RequestContext
from django.utils import simplejson from django.utils import simplejson

from voting.models import Vote from voting.models import Vote


VOTE_DIRECTIONS = (('up', 1), ('down', -1), ('clear', 0)) VOTE_DIRECTIONS = (('up', 1), ('down', -1), ('clear', 0))




def vote_on_object(request, direction, model=None, content_type_id=None, def vote_on_object(request, direction=None, model=None, content_type_id=None,
post_vote_redirect=None, object_id=None, slug=None, post_vote_redirect=None, object_id=None, slug=None,
slug_field=None, template_name=None, template_loader=loader, slug_field=None, template_name=None, template_loader=loader,
extra_context=None, context_processors=None, extra_context=None, context_processors=None,
template_object_name='object', allow_xmlhttprequest=True): template_object_name='object', allow_xmlhttprequest=True):
""" """
A wrapper around the original vote_on_object to allow fetching model A wrapper around the original vote_on_object to allow fetching model
from content_type_id if model is not given from content_type_id if model is not given
Also allows POSTing direction, content_type_id and object_id parameters
instead of supplying from within the request URL.
""" """
if not direction:
direction = request.POST.get('direction')
if not object_id:
object_id = request.POST.get('object_id')
if not model: if not model:
if not content_type_id:
content_type_id = request.POST.get('content_type_id')
model = ContentType.objects.get_for_id(content_type_id).model_class() model = ContentType.objects.get_for_id(content_type_id).model_class()
return _vote_on_object(request, model, direction, post_vote_redirect=post_vote_redirect, return _vote_on_object(request, model, direction, post_vote_redirect=post_vote_redirect,
object_id=object_id, slug=slug, slug_field=slug_field, template_name=template_name, object_id=object_id, slug=slug, slug_field=slug_field, template_name=template_name,
Expand Down

0 comments on commit 44d68ab

Please sign in to comment.