propose another model for LoginRequiredView and the like
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 4 Sep 2013 12:42:28 +0000 (14:42 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 4 Sep 2013 12:42:28 +0000 (14:42 +0200)
this one would not fit for eg. DashBoard, that does not define its own get but relies on mixins for that

portal/sliceview.py
portal/templateviews.py

index d233c43..dc7aff8 100644 (file)
@@ -4,7 +4,7 @@ from django.template                 import RequestContext
 from django.shortcuts                import render_to_response
 from django.contrib.auth.decorators  import login_required
 
-from portal.templateviews            import LoginRequiredView,LogoutOnManifoldExceptionView
+from portal.templateviews            import LoginRequiredAutoLogoutView
 
 from unfold.page                     import Page
 from manifold.core.query             import Query, AnalyzedQuery
@@ -31,12 +31,12 @@ from plugins.messages.messages       import Messages
 tmp_default_slice='ple.upmc.myslicedemo'
 debug = True
 
-class SliceView (LoginRequiredView, LogoutOnManifoldExceptionView):
+class SliceView (LoginRequiredAutoLogoutView):
 
 #    def __init__ (self, slicename=None):
 #        self.slicename = slicename or tmp_default_slice
 
-    def get_or_logout (self,request, slicename=tmp_default_slice):
+    def get (self,request, slicename=tmp_default_slice):
     
         page = Page(request)
         page.expose_js_metadata()
index 0d76fcd..0f46ff7 100644 (file)
@@ -10,8 +10,8 @@ from manifold.manifoldresult            import ManifoldException
 class LoginRequiredView (TemplateView):
 
     @method_decorator(login_required)
-    def dispatch(self, *args, **kwargs):
-        return super(LoginRequiredView, self).dispatch(*args, **kwargs)
+    def dispatch(self, request, *args, **kwargs):
+        return super(LoginRequiredView, self).dispatch(request, *args, **kwargs)
 
 
 ########## the base class for views that need to protect against ManifoldException
@@ -24,10 +24,11 @@ class LoginRequiredView (TemplateView):
 # it is often a good idea for a view to monitor these exceptions
 # and to take this opportunity to logout people 
 
-def logout_on_manifold_exception (view_as_a_function):
+def logout_on_manifold_exception (fun_that_returns_httpresponse):
     def wrapped (request, *args, **kwds):
+        print 'wrapped by logout_on_manifold_exception'
         try:
-            return view_as_a_function(request,*args, **kwds)
+            return fun_that_returns_httpresponse(request,*args, **kwds)
         except ManifoldException, manifold_result:
             # xxx we need a means to display this message to user...
             from django.contrib.auth import logout
@@ -42,11 +43,11 @@ def logout_on_manifold_exception (view_as_a_function):
     return wrapped
 
 # at first sight this matters only for views that require login
-# however we prefer this to be explicit
-# i.e. a user class has to inherit both LoginRequiredView and LogoutOnManifoldExceptionView
-
-class LogoutOnManifoldExceptionView (TemplateView):
+# so for now we expose a single class that behaves like 
+# login_required + logout_on_manifold_exception
+class LoginRequiredAutoLogoutView (TemplateView):
 
     @logout_on_manifold_exception
-    def get (self, request, *args, **kwds):
-        return self.get_or_logout (request, *args, **kwds)
+    @method_decorator(login_required)
+    def dispatch (self, request, *args, **kwds):
+        return super(LoginRequiredAutoLogoutView,self).dispatch(request,*args,**kwds)