Ejemplo n.º 1
0
def record_vote(request, issue_id):
    """
    Wrapper function for the voting.views.vote_on_object function
    It does 3 cases:
        -handle anonymous votes
        -handle and validate normal direction votes. 
        -handle ajax votes
    """
    if not request.user.is_authenticated() and request.REQUEST.has_key(
            'direction'):
        return handle_anonymous_vote(request, issue_id)

    if request.REQUEST.has_key('direction'):
        direction = int(request.REQUEST['direction'])
        if (not request.is_ajax()) and not possible_votes.has_key(direction):
            message = _("You did not pick a valid option")
            request.session["flash_msg"] = message
            next = request.REQUEST.get('next', '/')
            return HttpResponseRedirect(next)
        return vote_on_object(request,
                              Issue,
                              direction,
                              object_id=issue_id,
                              allow_xmlhttprequest=True)

    return HttpResponseRedirect('/')
Ejemplo n.º 2
0
def vote_on_assertion(request, object_id, direction):
    assertion = Assertion.objects.get(id=object_id)
    vote = dict(VOTE_DIRECTIONS)[direction]
    response = vote_on_object(request, object_id=object_id, direction=direction,
                              model=Assertion, template_object_name='assertion',
                              allow_xmlhttprequest=True)
    assertion.update_score()
    return response
Ejemplo n.º 3
0
def vote_on_statement(request, object_id, direction):
    raw = RawAssertion.objects.get(id=object_id)
    vote = dict(VOTE_DIRECTIONS)[direction]
    response = vote_on_object(request, object_id=object_id, direction=direction,
                              model=RawAssertion, template_object_name='statement',
                              allow_xmlhttprequest=True)
    if not Vote.objects.get_for_user(raw.assertion, request.user):
        Vote.objects.record_vote(raw.assertion, request.user, vote)
        raw.assertion.update_score()
    raw.update_score()
    return response
Ejemplo n.º 4
0
def vote_on_recipe(request, object_id, direction):
	print "val", direction
	returnval = vote_on_object(request, Recipe, direction, object_id=object_id, template_object_name='recipe', allow_xmlhttprequest=True)
#	try:
#		try:
#			usermeta = UserMeta.objects.get(user__id=request.user.id)#
#		except:
#			usermeta = UserMeta(request.user)
#		print usermeta.votearray
#	except Exception as e:
#		print type(e), e
	return returnval
Ejemplo n.º 5
0
def vote(request, model, object_id, direction):
    """Thin wrapper around ``django-voting`` to pass our custom params"""
    if not request.method == 'POST':
        raise Http404
    model_list = {
        'project': Project,
        'template': Template,
        }
    if model not in model_list:
        raise Http404
    model = model_list[model]
    return vote_on_object(request, model=model, allow_xmlhttprequest=True,
                          object_id=object_id, direction=direction)
Ejemplo n.º 6
0
def feedback_vote(request, feedback_id, direction):
    feedback = get_object_or_404(Feedback, id=feedback_id)

    # Auto (un)subscribe user if he/she's interested in this issue or not
    if direction == 'up':
        subscribe_user(request.user, feedback)
    elif direction in ('down', 'clear'):
        unsubscribe_user(request.user, feedback)

    return vote_on_object(request,
                          model=Feedback,
                          direction=direction,
                          object_id=feedback_id,
                          template_object_name='vote',
                          template_name='kb/link_confirm_vote.html',
                          allow_xmlhttprequest=True)
Ejemplo n.º 7
0
def record_vote_on_user(request, user_id):
    """
    Wrapper function for the voting.views.vote_on_object function.

    -Handle vote on user, check if direction == 1.
    -Handle ajax votes.
    """
    if request.REQUEST.has_key('direction'):
        direction = int(request.REQUEST['direction'])
        if (not request.is_ajax()) and not direction == 1: 
            message = _("You did not pick a valid option")
            request.session["flash_msg"] = message
            next = request.REQUEST.get('next', '/' )
            return HttpResponseRedirect(next) 
        return vote_on_object(request, User, direction, object_id=user_id, allow_xmlhttprequest=True ) 
    return HttpResponseRedirect('/')
Ejemplo n.º 8
0
def vote(request, model, object_id, direction):
    """Thin wrapper around ``django-voting`` to pass our custom params"""
    if not request.method == 'POST':
        raise Http404
    model_list = {
        'project': Project,
        'template': Template,
    }
    if model not in model_list:
        raise Http404
    model = model_list[model]
    return vote_on_object(request,
                          model=model,
                          allow_xmlhttprequest=True,
                          object_id=object_id,
                          direction=direction)
Ejemplo n.º 9
0
def vote_on_recipe(request, object_id, direction):
    print "val", direction
    returnval = vote_on_object(request,
                               Recipe,
                               direction,
                               object_id=object_id,
                               template_object_name='recipe',
                               allow_xmlhttprequest=True)
    #	try:
    #		try:
    #			usermeta = UserMeta.objects.get(user__id=request.user.id)#
    #		except:
    #			usermeta = UserMeta(request.user)
    #		print usermeta.votearray
    #	except Exception as e:
    #		print type(e), e
    return returnval
Ejemplo n.º 10
0
 def vote(self, request, object_id, tribe_slug, direction):
     from voting.views import vote_on_object
     from django_dms.apps.small_dms.models import Document
     
     tribe = get_object_or_404(Tribe, slug=tribe_slug)
     document = self.get_document(object_id, tribe_slug)
     model = Document
     
     return vote_on_object(request, model, direction, 
                             slug=document.uuid, slug_field='uuid',
                             template_object_name='bookmark',
                             template_name='small_dms/dms_detail.html',
                             allow_xmlhttprequest=True,
                             extra_context={'dms_site' : self,
                                            'tribe' : tribe,
                                            'document' : document,
                                           }
                                           
                          )
Ejemplo n.º 11
0
def record_vote_on_user(request, user_id):
    """
    Wrapper function for the voting.views.vote_on_object function.

    -Handle vote on user, check if direction == 1.
    -Handle ajax votes.
    """
    if request.REQUEST.has_key('direction'):
        direction = int(request.REQUEST['direction'])
        if (not request.is_ajax()) and not direction == 1:
            message = _("You did not pick a valid option")
            request.session["flash_msg"] = message
            next = request.REQUEST.get('next', '/')
            return HttpResponseRedirect(next)
        return vote_on_object(request,
                              User,
                              direction,
                              object_id=user_id,
                              allow_xmlhttprequest=True)
    return HttpResponseRedirect('/')
Ejemplo n.º 12
0
def record_vote(request, issue_id):
    """
    Wrapper function for the voting.views.vote_on_object function
    It does 3 cases:
        -handle anonymous votes
        -handle and validate normal direction votes. 
        -handle ajax votes
    """
    if not request.user.is_authenticated() and request.REQUEST.has_key('direction'):
        return handle_anonymous_vote(request, issue_id)
    
    if request.REQUEST.has_key('direction'):
        direction = int(request.REQUEST['direction'])
        if (not request.is_ajax()) and not possible_votes.has_key(direction):
            message = _("You did not pick a valid option")
            request.session["flash_msg"] = message
            next = request.REQUEST.get('next', '/' )
            return HttpResponseRedirect(next) 
        return vote_on_object(request, Issue, direction, object_id=issue_id, allow_xmlhttprequest=True ) 
        
    return HttpResponseRedirect('/')
Ejemplo n.º 13
0
def record_vote(request, issue_id ):
    """
    Wrapper function for the voting.views.vote_on_object function

    what if user is anonymous?

    """
    if not request.user.is_authenticated() and request.REQUEST.has_key('direction'):
        vote_history = request.session.get("vote_history", {})
        vote_history[int(issue_id)] = request.REQUEST['direction']
        request.session['vote_history'] = vote_history
        request.session.modified = True
        message = _("You voted succesfull, to save your votes please register")
        request.session["flash_msg"] = message
        next = request.REQUEST.get('next', '/' )
        return HttpResponseRedirect( next )

    if request.REQUEST.has_key('direction'):
        direction = request.REQUEST['direction']
        return vote_on_object(request, Issue, direction , object_id=issue_id ) 
    return HttpResponseRedirect('/')
Ejemplo n.º 14
0
def topic_vote(request, topic_id):
    if request.method != 'POST':
        return HttpResponseNotFound
    return vote_on_object(request, Topic, 'up',
                          object_id=topic_id, allow_xmlhttprequest=True)
Ejemplo n.º 15
0
def vote(request, *args, **kwargs):
    from voting.views import vote_on_object
    return vote_on_object(request, **kwargs)