X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/a64747b1fe3fb30bb05a8d9dcdfad625f7fade04..49d0961a6f7f585f707cd08817f3e0a9f1a19212:/forum/views/commands.py diff --git a/forum/views/commands.py b/forum/views/commands.py index e41c2e0..7b44322 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -10,7 +10,6 @@ from forum.models import * 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 @@ -436,12 +435,15 @@ def convert_to_comment(request, id): 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 not (user.is_a_super_user_or_staff() or user.is_authenticated()): - 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 @@ -488,13 +490,25 @@ def matching_tags(request): 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'])