2 from pprint import pprint
3 from manifold.manifoldapi import execute_query
4 from manifold.core.query import Query
5 # a set of utilities to help make the global layout consistent across views
7 # dropdowns are kind of ad hoc for now, and limited to one level
9 # ### a regular first-level button
10 # {'label':...,'href':..., ['domid':.., 'disabled':...]},
12 # { 'label': ..., 'href'=..., 'dropdown':True, 'contents': [ { 'label':.., 'href'} ] }
15 # see also templates/widget-topmenu.html for how these items are put together
16 # and plugins/topmenuvalidation for how this hident button is turned on when necessary
18 # current: the beginning of the label in the menu that you want to outline
19 def topmenu_items (current,request=None):
20 has_user=request.user.is_authenticated()
24 result.append({'label':'Dashboard', 'href': '/portal/dashboard/'})
25 result.append({'label':'Request a slice', 'href': '/portal/slice_request/'})
26 # always create a disabled button for validation, and let the
27 # topmenuvalidation plugin handle that asynchroneously, based on this domid
28 result.append({'label':'Validation', 'href': '/portal/validate/', 'domid':'topmenu-validation', 'disabled':True})
30 dropdown.append({'label':'Platforms', 'href': '/portal/platforms/'})
31 dropdown.append({'label':'My Account', 'href': '/portal/account/'})
32 dropdown.append({'label':'Contact Support', 'href': '/portal/contact/'})
33 result.append({'label': 'More', 'href':"#", 'dropdown':True, 'contents':dropdown})
35 result.append({'label':'Home', 'href': '/login'})
36 # looks like this is accessible to non-logged users
37 result.append({'label':'Platforms', 'href': '/portal/platforms/'})
38 result.append({'label':'Register', 'href': '/portal/register/'})
39 result.append({'label':'Contact Support', 'href': '/portal/contact/'})
40 # mark active if the provided 'current', even if shorter, matches the beginning of d['label']
42 if current is not None:
43 current=current.lower()
45 def mark_active(d,up=None):
46 if d['label'][:curlen].lower() == current:
48 if up is not None: up['is_active']=True
52 for dd in d['contents']: mark_active(dd,d)
55 def the_user (request):
56 "retrieves logged in user's email, or empty string"
57 if not request.user.is_authenticated ():
60 return request.user.email