Merge branch 'jordan' of ssh://git.onelab.eu/git/myslice into jordan
[myslice.git] / myslice / viewutils.py
1 # a set of utilities to help make the global layout consistent across views
2
3 from copy import deepcopy
4
5 standard_topmenu_items = [ 
6 #    { 'label':'Tab', 'href': '/tab/'},
7 #    { 'label':'Scroll', 'href': '/scroll/'},
8 #    { 'label':'One Plugin', 'href': '/plugin/'},
9     { 'label':'Dashboard', 'href': '/portal/dashboard/'},
10     { 'label':'Slice', 'href': '/slice/'},
11     #{'label':'My Account', 'href': '/portal/account/'}
12     ]
13
14 #login_out_items = { False: { 'label':'Login', 'href':'/login/'},
15 #                    True:  { 'label':'Logout', 'href':'/logout/'}}
16
17 def topmenu_items (current,request=None):
18     has_user=request.user.is_authenticated()
19     if has_user:
20         result=deepcopy(standard_topmenu_items)
21         result.append({'label':'My Account', 'href': '/portal/account/'})
22         result.append({ 'label':'Request a slice', 'href': '/portal/slice_request/'})
23     else:
24         result = []
25         result.append({'label':'Home', 'href': '/login'})
26         result.append({ 'label':'Register', 'href': '/portal/register/'})
27     result.append({'label':'Platforms', 'href': '/portal/platforms/'})
28     result.append({'label':'Contact Support', 'href': '/portal/contact/'})
29     for d in result:
30         #if d['label'].lower()find(current)>=0: d['is_active']=True
31         if d['label'] == current: d['is_active']=True
32     if not request: return result
33 #    result.append (login_out_items [ has_user] )
34     return result
35
36 def the_user (request):
37     "This code below is broken"
38     if not request.user.is_authenticated (): 
39 #        print 'void user!'
40         return ''
41     else: 
42         return request.user.email
43
44 # temporary for sample views
45 lorem="""
46 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod <code>mazim placerat</code> facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
47 """
48
49 lorem_p = "<p>"+lorem+"</p>"
50
51 hard_wired_slice_names = []
52 for site in [ 'inria', 'upmc' , 'ibbt' ]:
53     for slice in [ 'foo', 'bar', 'tutu', 'test', 'omf', 'heartbeat' ]:
54         hard_wired_slice_names.append ("ple.%s.%s"%(site,slice))
55
56 # having html tags right here is not a real use case
57 hard_wired_list=[]
58 hard_wired_list.append("this hard-wired list")
59 hard_wired_list.append("is defined")
60 hard_wired_list.append("in plugins.simplelist.py")
61 hard_wired_list.append("which in turn relies on")
62 hard_wired_list.append("template widget-template.html")
63 hard_wired_list.append("while it should of course")
64 hard_wired_list.append("instead issue a query")
65 hard_wired_list.append("and fill the DOM in js from there")
66 hard_wired_list.append("it would however maybe make sense")
67 hard_wired_list.append("to offer the option to 'datatablify'")
68 hard_wired_list.append("the list from the python code")
69 hard_wired_list.append("just like a standard plugin can be set as visible or not")
70 hard_wired_list.append("")    
71 hard_wired_list.append("OTOH and IMHO, there should be two separate and explicit subclasses of SimpleList for slices or testbeds")
72
73 quickfilter_criterias = [
74     {'key': 'Slice', 'values': ['slice1','slice2']},
75     {'key': 'Type', 'values': ['type1','type2']},
76     {'key': 'Network', 'values': ['net1','net2']},
77     ]