11 |
11 |
12 from logilab.common.textutils import splitstrip |
12 from logilab.common.textutils import splitstrip |
13 |
13 |
14 from cubicweb import Binary, ValidationError, typed_eid |
14 from cubicweb import Binary, ValidationError, typed_eid |
15 from cubicweb.web import INTERNAL_FIELD_VALUE, RequestError, NothingToEdit, ProcessFormError |
15 from cubicweb.web import INTERNAL_FIELD_VALUE, RequestError, NothingToEdit, ProcessFormError |
16 from cubicweb.web.views.editviews import delete_relations, insert_relations |
16 from cubicweb.web.views import basecontrollers, autoform |
17 from cubicweb.web.views.basecontrollers import ViewController |
|
18 |
17 |
19 |
18 |
20 class RqlQuery(object): |
19 class RqlQuery(object): |
21 def __init__(self): |
20 def __init__(self): |
22 self.edited = [] |
21 self.edited = [] |
42 rql += ', %s' % ','.join(self.restrictions) |
41 rql += ', %s' % ','.join(self.restrictions) |
43 self.kwargs[var] = eid |
42 self.kwargs[var] = eid |
44 return rql |
43 return rql |
45 |
44 |
46 |
45 |
47 class EditController(ViewController): |
46 class EditController(basecontrollers.ViewController): |
48 __regid__ = 'edit' |
47 __regid__ = 'edit' |
49 |
48 |
50 def publish(self, rset=None): |
49 def publish(self, rset=None): |
51 """edit / create / copy / delete entity / relations""" |
50 """edit / create / copy / delete entity / relations""" |
52 for key in self._cw.form: |
51 for key in self._cw.form: |
97 self._cw.execute(*querydef) |
96 self._cw.execute(*querydef) |
98 # XXX this processes *all* pending operations of *all* entities |
97 # XXX this processes *all* pending operations of *all* entities |
99 if req.form.has_key('__delete'): |
98 if req.form.has_key('__delete'): |
100 todelete = req.list_form_param('__delete', req.form, pop=True) |
99 todelete = req.list_form_param('__delete', req.form, pop=True) |
101 if todelete: |
100 if todelete: |
102 delete_relations(self._cw, todelete) |
101 autoform.delete_relations(self._cw, todelete) |
103 if req.form.has_key('__insert'): |
102 if req.form.has_key('__insert'): |
104 warn('[3.6] stop using __insert, support will be removed', |
103 warn('[3.6] stop using __insert, support will be removed', |
105 DeprecationWarning) |
104 DeprecationWarning) |
106 toinsert = req.list_form_param('__insert', req.form, pop=True) |
105 toinsert = req.list_form_param('__insert', req.form, pop=True) |
107 if toinsert: |
106 if toinsert: |
108 insert_relations(self._cw, toinsert) |
107 autoform.insert_relations(self._cw, toinsert) |
109 self._cw.remove_pending_operations() |
108 self._cw.remove_pending_operations() |
110 if self.errors: |
109 if self.errors: |
111 errors = dict((f.name, unicode(ex)) for f, ex in self.errors) |
110 errors = dict((f.name, unicode(ex)) for f, ex in self.errors) |
112 raise ValidationError(form.get('__maineid'), errors) |
111 raise ValidationError(form.get('__maineid'), errors) |
113 |
112 |
172 if is_main_entity: |
171 if is_main_entity: |
173 self.notify_edited(entity) |
172 self.notify_edited(entity) |
174 if formparams.has_key('__delete'): |
173 if formparams.has_key('__delete'): |
175 # XXX deprecate? |
174 # XXX deprecate? |
176 todelete = self._cw.list_form_param('__delete', formparams, pop=True) |
175 todelete = self._cw.list_form_param('__delete', formparams, pop=True) |
177 delete_relations(self._cw, todelete) |
176 autoform.delete_relations(self._cw, todelete) |
178 if formparams.has_key('__cloned_eid'): |
177 if formparams.has_key('__cloned_eid'): |
179 entity.copy_relations(typed_eid(formparams['__cloned_eid'])) |
178 entity.copy_relations(typed_eid(formparams['__cloned_eid'])) |
180 if is_main_entity: # only execute linkto for the main entity |
179 if is_main_entity: # only execute linkto for the main entity |
181 self.execute_linkto(entity.eid) |
180 self.execute_linkto(entity.eid) |
182 return eid |
181 return eid |