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
6 from manifold.core.query import Query, AnalyzedQuery
8 from unfold.page import Page
10 from ui.topmenu import topmenu_items, the_user
12 from plugins.topmenuvalidation import TopmenuValidation
14 class TopmenuValidationView (TemplateView):
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'):
19 if username=='logged': username='$user_hrn'
23 query_pi_auths = Query.get('ple:user').filter_by('user_hrn', '==', username ).select('pi_authorities')
24 page.enqueue_query(query_pi_auths)
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 (
32 domid='topmenu-validation',
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)
41 # variables that will get passed to the view-unfold1.html template
44 # write something of our own instead
45 template_env ['unfold_main'] = '<h1>Some title </h1>'
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)
54 # don't forget to run the requests
55 page.expose_queries ()
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()
61 # print prelude_env.keys()
62 # for k in [ 'js_files' ] :
63 # print 'prelude_env',prelude_env,k,prelude_env[k]
65 template_env.update(prelude_env)
66 result=render_to_response ('view-unfold1.html',template_env,
67 context_instance=RequestContext(request))