]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/commands.py
Fixing OSQA 258, Original templates can be directly accessed by public viewers.
[osqa.git] / forum / views / commands.py
index 6220bc229344e288eb3ef88180401ef4f8b3e414..e09924b064a38409874e253a66495263454d4fc9 100644 (file)
@@ -2,7 +2,7 @@ import datetime
 from forum import settings
 from django.core.exceptions import ObjectDoesNotExist
 from django.utils import simplejson
 from forum import settings
 from django.core.exceptions import ObjectDoesNotExist
 from django.utils import simplejson
-from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
+from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404
 from django.shortcuts import get_object_or_404, render_to_response
 from django.utils.translation import ungettext, ugettext as _
 from django.template import RequestContext
 from django.shortcuts import get_object_or_404, render_to_response
 from django.utils.translation import ungettext, ugettext as _
 from django.template import RequestContext
@@ -19,31 +19,31 @@ import logging
 class NotEnoughRepPointsException(CommandException):
     def __init__(self, action):
         super(NotEnoughRepPointsException, self).__init__(
 class NotEnoughRepPointsException(CommandException):
     def __init__(self, action):
         super(NotEnoughRepPointsException, self).__init__(
-            _("""Sorry, but you don't have enough reputation points to %(action)s.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
+            _("""Sorry, but you don't have enough reputation points to %(action)s.<br />Please check the <a href='%(faq_url)s'>faq</a>""") % {'action': action, 'faq_url': reverse('faq')}
         )
 
 class CannotDoOnOwnException(CommandException):
     def __init__(self, action):
         super(CannotDoOnOwnException, self).__init__(
         )
 
 class CannotDoOnOwnException(CommandException):
     def __init__(self, action):
         super(CannotDoOnOwnException, self).__init__(
-            _("""Sorry but you cannot %(action)s your own post.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
+            _("""Sorry but you cannot %(action)s your own post.<br />Please check the <a href='%(faq_url)s'>faq</a>""") % {'action': action, 'faq_url': reverse('faq')}
         )
 
 class AnonymousNotAllowedException(CommandException):
     def __init__(self, action):
         super(AnonymousNotAllowedException, self).__init__(
         )
 
 class AnonymousNotAllowedException(CommandException):
     def __init__(self, action):
         super(AnonymousNotAllowedException, self).__init__(
-            _("""Sorry but anonymous users cannot %(action)s.<br />Please login or create an account <a href='%(signin_url)s'>here</a>.""" % {'action': action, 'signin_url': reverse('auth_signin')})
+            _("""Sorry but anonymous users cannot %(action)s.<br />Please login or create an account <a href='%(signin_url)s'>here</a>.""") % {'action': action, 'signin_url': reverse('auth_signin')}
         )
 
 class NotEnoughLeftException(CommandException):
     def __init__(self, action, limit):
         super(NotEnoughLeftException, self).__init__(
         )
 
 class NotEnoughLeftException(CommandException):
     def __init__(self, action, limit):
         super(NotEnoughLeftException, self).__init__(
-            _("""Sorry, but you don't have enough %(action)s left for today..<br />The limit is %(limit)s per day..<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'limit': limit, 'faq_url': reverse('faq')})
+            _("""Sorry, but you don't have enough %(action)s left for today..<br />The limit is %(limit)s per day..<br />Please check the <a href='%(faq_url)s'>faq</a>""") % {'action': action, 'limit': limit, 'faq_url': reverse('faq')}
         )
 
 class CannotDoubleActionException(CommandException):
     def __init__(self, action):
         super(CannotDoubleActionException, self).__init__(
         )
 
 class CannotDoubleActionException(CommandException):
     def __init__(self, action):
         super(CannotDoubleActionException, self).__init__(
-            _("""Sorry, but you cannot %(action)s twice the same post.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
+            _("""Sorry, but you cannot %(action)s twice the same post.<br />Please check the <a href='%(faq_url)s'>faq</a>""") % {'action': action, 'faq_url': reverse('faq')}
         )
 
 
         )
 
 
@@ -410,6 +410,14 @@ def matching_tags(request):
         
     return HttpResponse(tag_output, mimetype="text/plain")
 
         
     return HttpResponse(tag_output, mimetype="text/plain")
 
+def related_questions(request):
+    if request.POST and request.POST.get('title', None):
+        return HttpResponse(simplejson.dumps(
+                [dict(title=q.title, url=q.get_absolute_url(), score=q.score, summary=q.summary)
+                 for q in Question.objects.search(request.POST['title'])[0:10]]), mimetype="application/json")
+    else:
+        raise Http404()
+