52 """logout from the application""" |
52 """logout from the application""" |
53 return self.appli.session_handler.logout(self.req) |
53 return self.appli.session_handler.logout(self.req) |
54 |
54 |
55 |
55 |
56 class ViewController(Controller): |
56 class ViewController(Controller): |
|
57 """standard entry point : |
|
58 - build result set |
|
59 - select and call main template |
|
60 """ |
57 id = 'view' |
61 id = 'view' |
58 template = 'main' |
62 template = 'main-template' |
59 |
63 |
60 def publish(self, rset=None): |
64 def publish(self, rset=None): |
61 """publish a request, returning an encoded string""" |
65 """publish a request, returning an encoded string""" |
|
66 view, rset = self._select_view_and_rset(rset) |
|
67 self.add_to_breadcrumbs(view) |
|
68 self.validate_cache(view) |
62 template = self.req.property_value('ui.main-template') |
69 template = self.req.property_value('ui.main-template') |
63 if template not in self.vreg.registry('templates') : |
70 if template not in self.vreg.registry('views') : |
64 template = self.template |
71 template = self.template |
65 return self.vreg.main_template(self.req, template, rset=rset) |
72 return self.vreg.main_template(self.req, template, rset=rset, view=view) |
|
73 |
|
74 def _select_view_and_rset(self, rset): |
|
75 req = self.req |
|
76 if rset is None and not hasattr(req, '_rql_processed'): |
|
77 req._rql_processed = True |
|
78 rset = self.process_rql(req.form.get('rql')) |
|
79 if rset and rset.rowcount == 1 and '__method' in req.form: |
|
80 entity = rset.get_entity(0, 0) |
|
81 try: |
|
82 method = getattr(entity, req.form.pop('__method')) |
|
83 method() |
|
84 except Exception, ex: |
|
85 self.exception('while handling __method') |
|
86 req.set_message(req._("error while handling __method: %s") % req._(ex)) |
|
87 vid = req.form.get('vid') or vid_from_rset(req, rset, self.schema) |
|
88 try: |
|
89 view = self.vreg.select_view(vid, req, rset) |
|
90 except ObjectNotFound: |
|
91 self.warning("the view %s could not be found", vid) |
|
92 req.set_message(req._("The view %s could not be found") % vid) |
|
93 vid = vid_from_rset(req, rset, self.schema) |
|
94 view = self.vreg.select_view(vid, req, rset) |
|
95 except NoSelectableObject: |
|
96 if rset: |
|
97 req.set_message(req._("The view %s can not be applied to this query") % vid) |
|
98 else: |
|
99 req.set_message(req._("You have no access to this view or it's not applyable to current data")) |
|
100 self.warning("the view %s can not be applied to this query", vid) |
|
101 vid = vid_from_rset(req, rset, self.schema) |
|
102 view = self.vreg.select_view(vid, req, rset) |
|
103 return view, rset |
|
104 |
|
105 def process_rql(self, rql): |
|
106 """execute rql if specified""" |
|
107 if rql: |
|
108 self.ensure_ro_rql(rql) |
|
109 if not isinstance(rql, unicode): |
|
110 rql = unicode(rql, self.req.encoding) |
|
111 pp = self.vreg.select_component('magicsearch', self.req) |
|
112 self.rset = pp.process_query(rql, self.req) |
|
113 return self.rset |
|
114 return None |
|
115 |
|
116 def add_to_breadcrumbs(self, view): |
|
117 # update breadcrumps **before** validating cache, unless the view |
|
118 # specifies explicitly it should not be added to breadcrumb or the |
|
119 # view is a binary view |
|
120 if view.add_to_breadcrumbs and not view.binary: |
|
121 self.req.update_breadcrumbs() |
|
122 |
|
123 def validate_cache(self, view): |
|
124 view.set_http_cache_headers() |
|
125 self.req.validate_cache() |
66 |
126 |
67 def execute_linkto(self, eid=None): |
127 def execute_linkto(self, eid=None): |
68 """XXX __linkto parameter may cause security issue |
128 """XXX __linkto parameter may cause security issue |
69 |
129 |
70 defined here since custom application controller inheriting from this |
130 defined here since custom application controller inheriting from this |