1 # a set of utilities to help make the global layout consistent across views
3 from django.http import HttpResponseRedirect
5 from manifold.manifoldresult import ManifoldException
7 def topmenu_items (current,request=None):
8 has_user=request.user.is_authenticated()
11 result.append({'label':'Platforms', 'href': '/portal/platforms/'})
12 result.append({ 'label':'Dashboard', 'href': '/portal/dashboard/'})
13 # This should probably go in dashboard at some point
14 result.append({ 'label':'Request a slice', 'href': '/portal/slice_request/'})
15 result.append({'label':'My Account', 'href': '/portal/account/'})
17 result.append({'label':'Home', 'href': '/login'})
18 # looks like this is accessible to non-logged users
19 result.append({'label':'Platforms', 'href': '/portal/platforms/'})
20 result.append({ 'label':'Register', 'href': '/portal/register/'})
21 result.append({'label':'Contact Support', 'href': '/portal/contact/'})
23 #if d['label'].lower()find(current)>=0: d['is_active']=True
24 if d['label'] == current: d['is_active']=True
25 if not request: return result
26 # result.append (login_out_items [ has_user] )
29 def the_user (request):
30 "This code below is broken"
31 if not request.user.is_authenticated ():
35 return request.user.email
38 # a decorator for view classes to catch manifold exceptions
39 # by design views should not directly exercise a manifold query
40 # given that these are asynchroneous, you would expect a view to just
41 # return a mundane skeleton
42 # however of course this is not always true, and if only for metadata
43 # that for some reason we deal with some other way, it is often a good idea
44 # for a view to monitor these exceptions - and to take this opportunity to
45 # logout people if it's a matter of expired session for example
46 def logout_on_manifold_exception (view_as_a_function):
47 def wrapped (request, *args, **kwds):
49 return view_as_a_function(request,*args, **kwds)
50 except ManifoldException, manifold_result:
51 # xxx we need a means to display this message to user...
52 from django.contrib.auth import logout
54 return HttpResponseRedirect ('/')
56 # xxx we need to sugarcoat this error message in some error template...
57 print "Unexpected exception",e
60 return HttpResponseRedirect ('/')