from django.views.generic import View
from django.core.mail import send_mail
+from unfold.loginrequired import FreeAccessView
from ui.topmenu import topmenu_items, the_user
from portal.forms import ContactForm
# splitting the 2 functions done here
# GET is for displaying the empty form
# POST is to process it once filled - or show the form again if anything is missing
-class ContactView (View):
+class ContactView (FreeAccessView):
def post (self, request):
form = ContactForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
# this somehow is not used anymore - should it not be ?
-from django.views.generic import View
from django.core.context_processors import csrf
from django.http import HttpResponseRedirect
from django.contrib.auth import authenticate, login, logout
from django.template import RequestContext
from django.shortcuts import render_to_response
+from unfold.loginrequired import FreeAccessView
+
from manifold.manifoldresult import ManifoldResult
from ui.topmenu import topmenu_items, the_user
from myslice.config import Config
-class HomeView (View):
+class HomeView (FreeAccessView):
# expose this so we can mention the backend URL on the welcome page
def default_env (self):
-from django.views.generic.base import TemplateView
-
from manifold.core.query import Query
from unfold.page import Page
+from unfold.loginrequired import FreeAccessView
from ui.topmenu import topmenu_items, the_user
from plugins.hazelnut import Hazelnut
# View for platforms
-class PlatformsView(TemplateView):
+class PlatformsView(FreeAccessView):
template_name = "platforms.html"
def get_context_data(self, **kwargs):
-from django.views.generic.base import TemplateView
-
from manifold.core.query import Query
from unfold.page import Page
+from unfold.loginrequired import FreeAccessView
from ui.topmenu import topmenu_items, the_user
from plugins.hazelnut import Hazelnut
# View for 1 platform and its details
-class PlatformView(TemplateView):
+class PlatformView(FreeAccessView):
template_name = "platform.html"
def get_context_data(self, **kwargs):
from django.shortcuts import render
from unfold.page import Page
+from unfold.loginrequired import FreeAccessView
from ui.topmenu import topmenu_items
from manifold.manifoldapi import execute_admin_query
from portal.models import PendingUser
from portal.actions import authority_get_pi_emails
-# This is a rough porting from views.py
-# the former function-based view is now made a class
-# we redefine dispatch as it is simple
-# and coincidentally works since we do not need LoginRequiredAutoLogoutView
-# a second stab should redefine post and get instead
-# also this was not thoroughly tested either, might miss some imports
-# to be continued...
+# since we inherit from FreeAccessView we cannot redefine 'dispatch'
+# so let's override 'get' and 'post' instead
+#
+class RegistrationView (FreeAccessView):
-class RegistrationView (View):
+ def post (self, request):
+ return self.get_or_post (request, 'POST')
- def dispatch (self, request):
+ def get (self, request):
+ return self.get_or_post (request, 'GET')
+
+ def get_or_post (self, request, method):
errors = []
#authorities_query = Query.get('authority').\
page.add_js_files ( [ "js/jquery.validate.js", "js/my_account.register.js" ] )
page.add_css_files ( [ "css/onelab.css", "css/registration.css" ] )
- print 'registration view, method',request.method
+ print 'registration view, method',method
- if request.method == 'POST':
+ if method == 'POST':
# We shall use a form here
#get_email = PendingUser.objects.get(email)
-from django.views.generic.base import TemplateView
-
from manifold.core.query import Query
from unfold.page import Page
+from unfold.loginrequired import FreeAccessView
from ui.topmenu import topmenu_items, the_user
from plugins.googlemap import GoogleMap
from plugins.slicestat import SliceStat
# View for 1 platform and its details
-class ResourceView(TemplateView):
+class ResourceView(FreeAccessView):
template_name = "resource.html"
def get_context_data(self, **kwargs):
import json
from django.http import HttpResponseRedirect, HttpResponse
-from django.views.generic.base import TemplateView
from django.shortcuts import render
from django.template.loader import render_to_string
+from unfold.loginrequired import FreeAccessView
from ui.topmenu import topmenu_items, the_user
from portal.event import Event
# all the other ones have now migrated into separate classes/files for more convenience
# I'm leaving these ones here for now as I could not exactly figure what the purpose was
# (i.e. what the correct name should be, as presviewview was a bit cryptic)
-class PresViewView(TemplateView):
+class PresViewView(FreeAccessView):
template_name = "view-unfold1.html"
def get_context_data(self, **kwargs):
json_answer = json.dumps(cmd)
return HttpResponse (json_answer, mimetype="application/json")
-class ValidatePendingView(TemplateView):
+class ValidatePendingView(FreeAccessView):
template_name = "validate_pending.html"
def get_context_data(self, **kwargs):
from manifold.manifoldresult import ManifoldException
+###
+# 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):
def logout_on_manifold_exception (fun_that_returns_httpresponse):
def wrapped (request, *args, **kwds):
- print 'wrapped by logout_on_manifold_exception'
+# print 'wrapped by logout_on_manifold_exception'
try:
return fun_that_returns_httpresponse(request,*args, **kwds)
except ManifoldException, manifold_result:
@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)