]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/commands.py
Several fixes in the OSQA exporter.
[osqa.git] / forum / views / commands.py
index 74bbe5ad043f841cabb5578e0bf37830cb46da42..7b44322edfa29ca979231e024476cb118778fd03 100644 (file)
@@ -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 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
 
@@ -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'])