X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/700b6dec7e4d655fee91e26f9757442162047281..ee7cd8daedc243f04e5f619b94239371c87e0fcc:/forum/views/commands.py diff --git a/forum/views/commands.py b/forum/views/commands.py index 956463a..ea58406 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,23 +435,34 @@ def convert_to_comment(request, id): return RefreshPageCommand() @decorate.withfn(command) -def subscribe(request, id): +def subscribe(request, id, user=None): + if user: + 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 + question = get_object_or_404(Question, id=id) try: - subscription = QuestionSubscription.objects.get(question=question, user=request.user) + subscription = QuestionSubscription.objects.get(question=question, user=user) subscription.delete() subscribed = False except: - subscription = QuestionSubscription(question=question, user=request.user, auto_subscription=False) + subscription = QuestionSubscription(question=question, user=user, auto_subscription=False) subscription.save() subscribed = True return { - 'commands': { - 'set_subscription_button': [subscribed and _('unsubscribe me') or _('subscribe me')], - 'set_subscription_status': [''] - } + 'commands': { + 'set_subscription_button': [subscribed and _('unsubscribe me') or _('subscribe me')], + 'set_subscription_status': [''] + } } #internally grouped views - used by the tagging system @@ -483,10 +493,22 @@ def matching_tags(request): possible_tags = Tag.active.filter(name__istartswith = 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__istartswith = 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'])