renamed validatebutton into topmenuvalidation
[myslice.git] / sample / topmenuvalidationview.py
1 # just one instance of validator
2 from django.views.generic.base import TemplateView
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
5
6 from manifold.core.query import Query, AnalyzedQuery
7
8 from unfold.page import Page
9
10 from ui.topmenu import topmenu_items, the_user
11
12 from plugins.topmenuvalidation import TopmenuValidation
13
14 class TopmenuValidationView (TemplateView):
15
16     # mention a user name in the URL as .../trash/simpletopmenuvalidation/ple.inria.thierry_parmentelat
17     def get (self, request, username='ple.inria.thierry_parmentelat'):
18
19         if username=='logged': username='$user_hrn'
20
21         page=Page(request)
22
23         query_pi_auths = Query.get('ple:user').filter_by('user_hrn', '==', username ).select('pi_authorities')
24         page.enqueue_query(query_pi_auths)
25
26         # even though this plugin does not have any html materialization, the corresponding domid
27         # must exist because it is searched at init-time to create the JS plugin
28         # so we simply piggy-back the target button here
29         topmenuvalidation = TopmenuValidation (
30             page=page, 
31             # see above
32             domid='topmenu-validation',
33             query=query_pi_auths,
34             # this one is the target for enabling when the query comes back
35             button_domid="topmenu-validation")
36         # there is a need to call render() for exposing the query and creating the js plugin
37         # even though this returns an empty string
38         topmenuvalidation.render(request)
39
40
41         # variables that will get passed to the view-unfold1.html template
42         template_env = {}
43         
44         # write something of our own instead
45         template_env ['unfold_main'] = '<h1>Some title </h1>'
46         
47         # more general variables expected in the template
48         template_env [ 'title' ] = 'simple topmenuvalidation %(username)s'%locals()
49         # the menu items on the top
50         template_env [ 'topmenu_items' ] = topmenu_items('Slice', request) 
51         # so we can see who is logged
52         template_env [ 'username' ] = the_user (request) 
53     
54         # don't forget to run the requests
55         page.expose_queries ()
56
57         # the prelude object in page contains a summary of the requirements() for all plugins
58         # define {js,css}_{files,chunks}
59         prelude_env = page.prelude_env()
60
61 #        print prelude_env.keys()
62 #        for k in [ 'js_files' ] :
63 #            print 'prelude_env',prelude_env,k,prelude_env[k]
64
65         template_env.update(prelude_env)
66         result=render_to_response ('view-unfold1.html',template_env,
67                                    context_instance=RequestContext(request))
68         return result