web/views/editcontroller.py
branchstable
changeset 9178 b5762ac9a82e
parent 9177 5236d0e4c598
child 9179 570208f74a84
--- a/web/views/editcontroller.py	Mon Jul 22 11:38:48 2013 +0200
+++ b/web/views/editcontroller.py	Mon Jul 22 12:07:46 2013 +0200
@@ -101,6 +101,15 @@
         self.kwargs[var] = eid
         return rql
 
+    def set_attribute(self, attr, value):
+        self.kwargs[attr] = value
+        self.edited.append('X %s %%(%s)s' % (attr, attr))
+
+    def set_inlined(self, relation, value):
+        self.kwargs[relation] = value
+        self.edited.append('X %s %s' % (relation, relation.upper()))
+        self.restrictions.append('%s eid %%(%s)s' % (relation.upper(), relation))
+
 
 class EditController(basecontrollers.ViewController):
     __regid__ = 'edit'
@@ -238,8 +247,7 @@
                     continue
                 rschema = self._cw.vreg.schema.rschema(field.name)
                 if rschema.final:
-                    rqlquery.kwargs[field.name] = value
-                    rqlquery.edited.append('X %s %%(%s)s' % (rschema, rschema))
+                    rqlquery.set_attribute(field.name, value)
                 else:
                     if form.edited_entity.has_eid():
                         origvalues = set(entity.eid for entity in form.edited_entity.related(field.name, field.role, entities=True))
@@ -261,10 +269,7 @@
         """handle edition for the (rschema, x) relation of the given entity
         """
         if values:
-            attr = field.name
-            rqlquery.kwargs[attr] = iter(values).next()
-            rqlquery.edited.append('X %s %s' % (attr, attr.upper()))
-            rqlquery.restrictions.append('%s eid %%(%s)s' % (attr.upper(), attr))
+            rqlquery.set_inlined(field.name, iter(values).next())
         elif form.edited_entity.has_eid():
             self.handle_relation(form, field, values, origvalues)