]> git.openstreetmap.org Git - osqa.git/commitdiff
Handle redirects and other responses in parameter decorators.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 31 Aug 2010 23:59:16 +0000 (23:59 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 31 Aug 2010 23:59:16 +0000 (23:59 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@582 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/modules/__init__.py
forum/modules/decorators.py
forum/views/users.py

index 07cbc6edde5ea74dc6e6139f4a245822c80e0292..a8a56652b9b0b386ce5e1a52be0ff910f6f2c185 100644 (file)
@@ -108,4 +108,4 @@ def module_templates_loader(name, dirs=None):
 
 module_templates_loader.is_usable = True
 
-from decorators import decorate
+from decorators import decorate, ReturnImediatelyException
index 13bddac89357785c8df24e9402483de3b5724e02..3c53412dc0505c4c92bbe183a6709ca007dc5a34 100644 (file)
@@ -47,7 +47,10 @@ class DecoratableObject(object):
     def __call__(self, *args, **kwargs):\r
         if self._params_decoration:\r
             for dec in self._params_decoration:\r
-                args, kwargs = dec(*args, **kwargs)\r
+                try:\r
+                    args, kwargs = dec(*args, **kwargs)\r
+                except ReturnImediatelyException, e:\r
+                    return e.ret\r
 \r
         res = self._callable(*args, **kwargs)\r
 \r
@@ -60,6 +63,11 @@ class DecoratableObject(object):
 \r
         return res\r
 \r
+class ReturnImediatelyException(Exception):\r
+    def __init__(self, ret):\r
+        super(Exception, self).__init__()\r
+        self.ret = ret\r
+\r
 def _check_decoratable(origin, install=True):\r
     if not isinstance(origin, DecoratableObject):\r
         if inspect.ismethod(origin) and not hasattr(origin, '_decoratable_obj'):\r
index 2e665989c407bcfadf3dd89825c3b2923058fda3..60e4b38cc991ab2fc4435d36f903b122a7676efb 100644 (file)
@@ -15,7 +15,7 @@ from django.utils import simplejson
 from django.core.urlresolvers import reverse, NoReverseMatch\r
 from forum.forms import *\r
 from forum.utils.html import sanitize_html\r
-from forum.modules import decorate\r
+from forum.modules import decorate, ReturnImediatelyException\r
 from datetime import datetime, date\r
 from forum.actions import EditProfileAction, FavoriteAction, BonusRepAction, SuspendAction\r
 from forum.modules import ui\r
@@ -259,10 +259,10 @@ def user_view(template, tab_name, tab_title, tab_description, private=False, tab
         def params(request, id, slug=None):\r
             user = get_object_or_404(User, id=id)\r
             if private and not (user == request.user or request.user.is_superuser):\r
-                return HttpResponseUnauthorized(request)\r
+                raise ReturnImediatelyException(HttpResponseUnauthorized(request))\r
 \r
             if render_to and (not render_to(user)):\r
-                return HttpResponseRedirect(user.get_profile_url())\r
+                raise ReturnImediatelyException(HttpResponseRedirect(user.get_profile_url()))\r
 \r
             return [request, user], {}\r
 \r