move former myslice/viewutils.py, to gether with the contents of former views/ subdir...
[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 def topmenu_items (current,request=None):
11     has_user=request.user.is_authenticated()
12     result=[]
13     if has_user:
14         result.append({'label':'Platforms', 'href': '/portal/platforms/'})
15         result.append({'label':'Dashboard', 'href': '/portal/dashboard/'})
16         # This should probably go in dashboard at some point
17         dropdown = []
18         dropdown.append({'label':'Request a slice', 'href': '/portal/slice_request/'})
19         dropdown.append({'label':'My Account', 'href': '/portal/account/'})
20         dropdown.append({'label':'Contact Support', 'href': '/portal/contact/'})
21         result.append({'label': 'More', 'href':"#", 'dropdown':True, 'contents':dropdown})
22     else:
23         result.append({'label':'Home', 'href': '/login'})
24         # looks like this is accessible to non-logged users
25         result.append({'label':'Platforms', 'href': '/portal/platforms/'})
26         result.append({'label':'Register', 'href': '/portal/register/'})
27         result.append({'label':'Contact Support', 'href': '/portal/contact/'})
28     # mark active
29     for d in result:
30         if 'dropdown' in d:
31             for dd in d['contents']:
32                 if dd['label'] == current: dd['is_active']=True
33         else:
34             if d['label'] == current: d['is_active']=True
35     return result
36
37 def the_user (request):
38     "retrieves logged in user's email, or empty string"
39     if not request.user.is_authenticated (): 
40         return ''
41     else: 
42         return request.user.email