X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=unfold%2Floginrequired.py;h=afe24f3f69cafc74ba6734e337aac17b11dcad9e;hb=deee82377a1f72626cede01fdfec5e9d7cc274ce;hp=ebe33d5132f41a7080eee0daba1618f564456872;hpb=fea9b7e286cc86f11844e371d67d184198afc287;p=myslice.git diff --git a/unfold/loginrequired.py b/unfold/loginrequired.py index ebe33d51..afe24f3f 100644 --- a/unfold/loginrequired.py +++ b/unfold/loginrequired.py @@ -4,7 +4,16 @@ from django.http import HttpResponseRedirect # for 'as_view' that we need to call in urls.py and the like from django.views.generic.base import TemplateView -from manifold.manifoldresult import ManifoldException +from manifoldapi.manifoldresult import ManifoldException + +from myslice.settings import logger + +### +# IMPORTANT NOTE +# the implementation of the classes in this file rely on redefining 'dispatch' +# for this reason if you inherit any of these, please do not redefine 'dispatch' yourself, +# but rather redefine 'get' and 'post' instead +### ########## the base class for views that require a login class LoginRequiredView (TemplateView): @@ -26,7 +35,6 @@ class LoginRequiredView (TemplateView): def logout_on_manifold_exception (fun_that_returns_httpresponse): def wrapped (request, *args, **kwds): - print 'wrapped by logout_on_manifold_exception' try: return fun_that_returns_httpresponse(request,*args, **kwds) except ManifoldException, manifold_result: @@ -38,9 +46,9 @@ def logout_on_manifold_exception (fun_that_returns_httpresponse): return HttpResponseRedirect ('/') except Exception, e: # xxx we need to sugarcoat this error message in some error template... - print "Unexpected exception",e + logger.error("Unexpected exception {}".format(e)) import traceback - traceback.print_exc() + logger.error(traceback.format_exc()) return HttpResponseRedirect ('/') return wrapped @@ -53,3 +61,11 @@ class LoginRequiredAutoLogoutView (TemplateView): @method_decorator(login_required) def dispatch (self, request, *args, **kwds): return super(LoginRequiredAutoLogoutView,self).dispatch(request,*args,**kwds) + +# we have more and more views that actually send manifold queries +# so for these we need to protect against manifold exceptions +# even though login is not required +class FreeAccessView (TemplateView): + + def dispatch (self, request, *args, **kwds): + return super(FreeAccessView,self).dispatch(request,*args,**kwds)