1 # a set of utilities to help make the global layout consistent across views
3 # dropdowns are kind of ad hoc for now, and limited to one level
5 # ### a regular first-level button
6 # {'label':...,'href':...},
8 # { 'label': ..., 'href'=..., 'dropdown':True, 'contents': [ { 'label':.., 'href'} ] }
11 # current: the beginning of the label in the menu that you want to outline
12 def topmenu_items (current,request=None):
13 has_user=request.user.is_authenticated()
16 result.append({'label':'Dashboard', 'href': '/portal/dashboard/'})
17 result.append({'label':'Request a slice', 'href': '/portal/slice_request/'})
18 result.append({'label':'Validation', 'href': '/portal/validate/'})
20 dropdown.append({'label':'Platforms', 'href': '/portal/platforms/'})
21 dropdown.append({'label':'My Account', 'href': '/portal/account/'})
22 dropdown.append({'label':'Contact Support', 'href': '/portal/contact/'})
23 result.append({'label': 'More', 'href':"#", 'dropdown':True, 'contents':dropdown})
25 result.append({'label':'Home', 'href': '/login'})
26 # looks like this is accessible to non-logged users
27 result.append({'label':'Platforms', 'href': '/portal/platforms/'})
28 result.append({'label':'Register', 'href': '/portal/register/'})
29 result.append({'label':'Contact Support', 'href': '/portal/contact/'})
30 # mark active if the provided 'current', even if shorter, matches the beginning of d['label']
32 if current is not None:
33 current=current.lower()
35 def mark_active(d,up=None):
36 if d['label'][:curlen].lower() == current:
38 if up is not None: up['is_active']=True
42 for dd in d['contents']: mark_active(dd,d)
45 def the_user (request):
46 "retrieves logged in user's email, or empty string"
47 if not request.user.is_authenticated ():
50 return request.user.email