remove debug print statement
[myslice.git] / ui / topmenu.py
1 # a set of utilities to help make the global layout consistent across views
2
3 # dropdowns are kind of ad hoc for now, and limited to one level
4 # [ 
5 # ### a regular first-level button
6 # {'label':...,'href':...}, 
7 # ### a dropdown
8 # { 'label': ..., 'href'=..., 'dropdown':True, 'contents': [ { 'label':.., 'href'} ] }
9 # , ..]
10
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()
14     result=[]
15     if has_user:
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/'})
19         dropdown = []
20         dropdown.append({'label':'My Account', 'href': '/portal/account/'})
21         dropdown.append({'label':'Contact Support', 'href': '/portal/contact/'})
22         result.append({'label': 'More', 'href':"#", 'dropdown':True, 'contents':dropdown})
23     else:
24         result.append({'label':'Home', 'href': '/login'})
25         # looks like this is accessible to non-logged users
26         result.append({'label':'Platforms', 'href': '/portal/platforms/'})
27         result.append({'label':'Register', 'href': '/portal/register/'})
28         result.append({'label':'Contact Support', 'href': '/portal/contact/'})
29     # mark active if the provided 'current', even if shorter, matches the beginning of d['label']
30     
31     if current is not None:
32         current=current.lower()
33         curlen=len(current)
34         def mark_active(d,up=None):
35             if d['label'][:curlen].lower() == current: 
36                 d['is_active']=True
37                 if up is not None: up['is_active']=True
38         for d in result:
39             mark_active(d)
40             if 'dropdown' in d:
41                 for dd in d['contents']: mark_active(dd,d)
42     return result
43
44 def the_user (request):
45     "retrieves logged in user's email, or empty string"
46     if not request.user.is_authenticated (): 
47         return ''
48     else: 
49         return request.user.email