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