from forum.models.node import NodeMetaClass
from forum.actions import *
from django.core.urlresolvers import reverse
-from django.contrib.auth.decorators import login_required
from forum.utils.decorators import ajax_method, ajax_login_required
from decorators import command, CommandException, RefreshPageCommand
from forum.modules import decorate
return RefreshPageCommand()
@decorate.withfn(command)
-def subscribe(request, id, user=0):
+def subscribe(request, id, user=None):
if user:
- user = User.objects.filter(id=user)[0]
- if user.is_a_super_user_or_staff():
- raise CommandException(_("You do not have the correct credentials to preform this action."))
+ try:
+ user = User.objects.get(id=user)
+ except User.DoesNotExist:
+ raise Http404()
+ if not (request.user.is_a_super_user_or_staff() or user.is_authenticated()):
+ raise CommandException(_("You do not have the correct credentials to preform this action."))
else:
user = request.user
if len(request.GET['q']) == 0:
raise CommandException(_("Invalid request"))
- possible_tags = Tag.active.filter(name__istartswith = request.GET['q'])
+ possible_tags = Tag.active.filter(name__icontains = request.GET['q'])
tag_output = ''
for tag in possible_tags:
- tag_output += (tag.name + "|" + tag.name + "." + tag.used_count.__str__() + "\n")
+ tag_output += "%s|%s|%s\n" % (tag.id, tag.name, tag.used_count)
return HttpResponse(tag_output, mimetype="text/plain")
+def matching_users(request):
+ if len(request.GET['q']) == 0:
+ raise CommandException(_("Invalid request"))
+
+ possible_users = User.objects.filter(username__icontains = request.GET['q'])
+ output = ''
+
+ for user in possible_users:
+ output += ("%s|%s|%s\n" % (user.id, user.decorated_name, user.reputation))
+
+ return HttpResponse(output, mimetype="text/plain")
+
def related_questions(request):
if request.POST and request.POST.get('title', None):
can_rank, questions = Question.objects.search(request.POST['title'])