45 for rstr in rdescr: |
45 for rstr in rdescr: |
46 subjs, rtype, objs = rstr.split(':') |
46 subjs, rtype, objs = rstr.split(':') |
47 for subj in subjs.split('_'): |
47 for subj in subjs.split('_'): |
48 for obj in objs.split('_'): |
48 for obj in objs.split('_'): |
49 yield typed_eid(subj), rtype, typed_eid(obj) |
49 yield typed_eid(subj), rtype, typed_eid(obj) |
50 |
50 |
51 def append_url_params(url, params): |
51 def append_url_params(url, params): |
52 """append raw parameters to the url. Given parameters, if any, are expected |
52 """append raw parameters to the url. Given parameters, if any, are expected |
53 to be already url-quoted. |
53 to be already url-quoted. |
54 """ |
54 """ |
55 if params: |
55 if params: |
73 def __init__(self, *args, **kwargs): |
73 def __init__(self, *args, **kwargs): |
74 super(Controller, self).__init__(*args, **kwargs) |
74 super(Controller, self).__init__(*args, **kwargs) |
75 # attributes use to control after edition redirection |
75 # attributes use to control after edition redirection |
76 self._after_deletion_path = None |
76 self._after_deletion_path = None |
77 self._edited_entity = None |
77 self._edited_entity = None |
78 |
78 |
79 def publish(self, rset=None): |
79 def publish(self, rset=None): |
80 """publish the current request, with an option input rql string |
80 """publish the current request, with an option input rql string |
81 (already processed if necessary) |
81 (already processed if necessary) |
82 """ |
82 """ |
83 raise NotImplementedError |
83 raise NotImplementedError |
92 rql = unicode(rql, self.req.encoding) |
92 rql = unicode(rql, self.req.encoding) |
93 pp = self.vreg.select_component('magicsearch', self.req) |
93 pp = self.vreg.select_component('magicsearch', self.req) |
94 self.rset = pp.process_query(rql, self.req) |
94 self.rset = pp.process_query(rql, self.req) |
95 return self.rset |
95 return self.rset |
96 return None |
96 return None |
97 |
97 |
98 def check_expected_params(self, params): |
98 def check_expected_params(self, params): |
99 """check that the given list of parameters are specified in the form |
99 """check that the given list of parameters are specified in the form |
100 dictionary |
100 dictionary |
101 """ |
101 """ |
102 missing = [] |
102 missing = [] |
104 if not self.req.form.get(param): |
104 if not self.req.form.get(param): |
105 missing.append(param) |
105 missing.append(param) |
106 if missing: |
106 if missing: |
107 raise RequestError('missing required parameter(s): %s' |
107 raise RequestError('missing required parameter(s): %s' |
108 % ','.join(missing)) |
108 % ','.join(missing)) |
109 |
109 |
110 def parse_datetime(self, value, etype='Datetime'): |
110 def parse_datetime(self, value, etype='Datetime'): |
111 """get a datetime or time from a string (according to etype) |
111 """get a datetime or time from a string (according to etype) |
112 Datetime formatted as Date are accepted |
112 Datetime formatted as Date are accepted |
113 """ |
113 """ |
114 assert etype in ('Datetime', 'Date', 'Time'), etype |
114 assert etype in ('Datetime', 'Date', 'Time'), etype |
139 # NOTE: we can't use entity.rest_path() at this point because |
139 # NOTE: we can't use entity.rest_path() at this point because |
140 # rest_path() could rely on schema constraints (such as a required |
140 # rest_path() could rely on schema constraints (such as a required |
141 # relation) that might not be satisfied yet (in case of creations) |
141 # relation) that might not be satisfied yet (in case of creations) |
142 if not self._edited_entity: |
142 if not self._edited_entity: |
143 self._edited_entity = entity |
143 self._edited_entity = entity |
144 |
144 |
145 def delete_entities(self, eidtypes): |
145 def delete_entities(self, eidtypes): |
146 """delete entities from the repository""" |
146 """delete entities from the repository""" |
147 redirect_info = set() |
147 redirect_info = set() |
148 eidtypes = tuple(eidtypes) |
148 eidtypes = tuple(eidtypes) |
149 for eid, etype in eidtypes: |
149 for eid, etype in eidtypes: |
158 self._after_deletion_path = iter(redirect_info).next() |
158 self._after_deletion_path = iter(redirect_info).next() |
159 if len(eidtypes) > 1: |
159 if len(eidtypes) > 1: |
160 self.req.set_message(self.req._('entities deleted')) |
160 self.req.set_message(self.req._('entities deleted')) |
161 else: |
161 else: |
162 self.req.set_message(self.req._('entity deleted')) |
162 self.req.set_message(self.req._('entity deleted')) |
163 |
163 |
164 def delete_relations(self, rdefs): |
164 def delete_relations(self, rdefs): |
165 """delete relations from the repository""" |
165 """delete relations from the repository""" |
166 # FIXME convert to using the syntax subject:relation:eids |
166 # FIXME convert to using the syntax subject:relation:eids |
167 execute = self.req.execute |
167 execute = self.req.execute |
168 for subj, rtype, obj in rdefs: |
168 for subj, rtype, obj in rdefs: |
169 rql = 'DELETE X %s Y where X eid %%(x)s, Y eid %%(y)s' % rtype |
169 rql = 'DELETE X %s Y where X eid %%(x)s, Y eid %%(y)s' % rtype |
170 execute(rql, {'x': subj, 'y': obj}, ('x', 'y')) |
170 execute(rql, {'x': subj, 'y': obj}, ('x', 'y')) |
171 self.req.set_message(self.req._('relations deleted')) |
171 self.req.set_message(self.req._('relations deleted')) |
172 |
172 |
173 def insert_relations(self, rdefs): |
173 def insert_relations(self, rdefs): |
174 """insert relations into the repository""" |
174 """insert relations into the repository""" |
175 execute = self.req.execute |
175 execute = self.req.execute |
176 for subj, rtype, obj in rdefs: |
176 for subj, rtype, obj in rdefs: |
177 rql = 'SET X %s Y where X eid %%(x)s, Y eid %%(y)s' % rtype |
177 rql = 'SET X %s Y where X eid %%(x)s, Y eid %%(y)s' % rtype |
178 execute(rql, {'x': subj, 'y': obj}, ('x', 'y')) |
178 execute(rql, {'x': subj, 'y': obj}, ('x', 'y')) |
179 |
179 |
180 |
180 |
181 def reset(self): |
181 def reset(self): |
182 """reset form parameters and redirect to a view determinated by given |
182 """reset form parameters and redirect to a view determinated by given |
183 parameters |
183 parameters |
184 """ |
184 """ |
185 newparams = {} |
185 newparams = {} |
219 else: |
219 else: |
220 path = 'view' |
220 path = 'view' |
221 url = self.build_url(path, **newparams) |
221 url = self.build_url(path, **newparams) |
222 url = append_url_params(url, self.req.form.get('__redirectparams')) |
222 url = append_url_params(url, self.req.form.get('__redirectparams')) |
223 raise Redirect(url) |
223 raise Redirect(url) |
224 |
224 |
225 |
225 |
226 def _return_to_edition_view(self, newparams): |
226 def _return_to_edition_view(self, newparams): |
227 """apply-button case""" |
227 """apply-button case""" |
228 form = self.req.form |
228 form = self.req.form |
229 if self._edited_entity: |
229 if self._edited_entity: |