import logging
from urllib import urlencode
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
import logging
from urllib import urlencode
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.utils.encoding import smart_unicode
from django.utils.translation import ungettext, ugettext as _
from django.utils.encoding import smart_unicode
from django.utils.translation import ungettext, ugettext as _
-from django.http import HttpResponse, HttpResponseRedirect, Http404
+from django.http import (HttpResponse, HttpResponseRedirect, Http404,
+ HttpResponseBadRequest)
from forum.models import *
from forum.utils.decorators import ajax_login_required
from forum.actions import *
from forum.models import *
from forum.utils.decorators import ajax_login_required
from forum.actions import *
from decorators import command, CommandException, RefreshPageCommand
class NotEnoughRepPointsException(CommandException):
from decorators import command, CommandException, RefreshPageCommand
class NotEnoughRepPointsException(CommandException):
- def __init__(self, action, user_reputation=None, reputation_required=None):
+ def __init__(self, action, user_reputation=None, reputation_required=None, node=None):
if reputation_required is not None and user_reputation is not None:
message = _(
"""Sorry, but you don't have enough reputation points to %(action)s.<br />
if reputation_required is not None and user_reputation is not None:
message = _(
"""Sorry, but you don't have enough reputation points to %(action)s.<br />
@decorate.withfn(command)
def vote_post(request, id, vote_type):
@decorate.withfn(command)
def vote_post(request, id, vote_type):
if not (vote_type == 'up' and user.can_vote_up() or user.can_vote_down()):
reputation_required = int(settings.REP_TO_VOTE_UP) if vote_type == 'up' else int(settings.REP_TO_VOTE_DOWN)
action_type = vote_type == 'up' and _('upvote') or _('downvote')
if not (vote_type == 'up' and user.can_vote_up() or user.can_vote_down()):
reputation_required = int(settings.REP_TO_VOTE_UP) if vote_type == 'up' else int(settings.REP_TO_VOTE_DOWN)
action_type = vote_type == 'up' and _('upvote') or _('downvote')
- raise NotEnoughRepPointsException(action_type, user_reputation=user.reputation, reputation_required=reputation_required)
+ raise NotEnoughRepPointsException(action_type, user_reputation=user.reputation, reputation_required=reputation_required, node=post)
user_vote_count_today = user.get_vote_count_today()
user_can_vote_count_today = user.can_vote_count_today()
user_vote_count_today = user.get_vote_count_today()
user_can_vote_count_today = user.can_vote_count_today()
@decorate.withfn(command)
def mark_favorite(request, id):
@decorate.withfn(command)
def mark_favorite(request, id):
if not request.user.is_authenticated():
raise AnonymousNotAllowedException(_('mark a question as favorite'))
try:
if not request.user.is_authenticated():
raise AnonymousNotAllowedException(_('mark a question as favorite'))
try:
raise AnonymousNotAllowedException(_('accept answers'))
node = get_object_or_404(Node, id=id)
raise AnonymousNotAllowedException(_('accept answers'))
node = get_object_or_404(Node, id=id)
# Redirect URL should include additional get parameters that might have been attached
redirect_url = answer.parent.get_absolute_url() + "?accepted_answer=true&%s" % smart_unicode(urlencode(request.GET))
# Redirect URL should include additional get parameters that might have been attached
redirect_url = answer.parent.get_absolute_url() + "?accepted_answer=true&%s" % smart_unicode(urlencode(request.GET))
tag_output = ''
for tag in possible_tags:
tag_output += "%s|%s|%s\n" % (tag.id, tag.name, tag.used_count)
tag_output = ''
for tag in possible_tags:
tag_output += "%s|%s|%s\n" % (tag.id, tag.name, tag.used_count)
for user in possible_users:
output += ("%s|%s|%s\n" % (user.id, user.decorated_name, user.reputation))
for user in possible_users:
output += ("%s|%s|%s\n" % (user.id, user.decorated_name, user.reputation))
def related_questions(request):
if request.POST and request.POST.get('title', None):
def related_questions(request):
if request.POST and request.POST.get('title', None):
if can_rank and isinstance(can_rank, basestring):
questions = questions.order_by(can_rank)
if can_rank and isinstance(can_rank, basestring):
questions = questions.order_by(can_rank)
[dict(title=q.title, url=q.get_absolute_url(), score=q.score, summary=q.summary)
[dict(title=q.title, url=q.get_absolute_url(), score=q.score, summary=q.summary)
- return render_to_response("node/award_points.html", { 'user' : user, 'awarded_user' : awarded_user, })
+ return render_to_response("node/award_points.html", {
+ 'user' : user,
+ 'awarded_user' : awarded_user,
+ 'reputation_to_comment' : str(settings.REP_TO_COMMENT)
+ })
AwardPointsAction(user=request.user, node=answer, extra=extra).save(data=dict(value=points, affected=awarded_user))
return { 'message' : _("You have awarded %(awarded_user)s with %(points)d points") % {'awarded_user' : awarded_user, 'points' : points} }
AwardPointsAction(user=request.user, node=answer, extra=extra).save(data=dict(value=points, affected=awarded_user))
return { 'message' : _("You have awarded %(awarded_user)s with %(points)d points") % {'awarded_user' : awarded_user, 'points' : points} }