[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Only role='object' was correctly accounted for by 570208f74a84
--- a/web/test/unittest_views_basecontrollers.py Thu Jul 25 18:14:56 2013 +0200
+++ b/web/test/unittest_views_basecontrollers.py Fri Jul 26 13:47:52 2013 +0200
@@ -197,6 +197,30 @@
# created before.
self.assertGreater(salesterm.eid, salesterm.described_by_test[0].eid)
+ def test_create_mandatory_inlined2(self):
+ req = self.request()
+ req.form = {'eid': ['X', 'Y'], '__maineid' : 'X',
+
+ '__type:X': 'Salesterm',
+ '_cw_entity_fields:X': 'described_by_test-subject',
+ 'described_by_test-subject:X': 'Y',
+
+ '__type:Y': 'File',
+ '_cw_entity_fields:Y': 'data-subject',
+ 'data-subject:Y': (u'coucou.txt', Binary('coucou')),
+ }
+ path, params = self.expect_redirect_handle_request(req, 'edit')
+ self.assertTrue(path.startswith('salesterm/'), path)
+ eid = path.split('/')[1]
+ salesterm = req.entity_from_eid(eid)
+ # The NOT NULL constraint of mandatory relation implies that the File
+ # must be created before the Salesterm, otherwise Salesterm insertion
+ # will fail.
+ # NOTE: sqlite does have NOT NULL constraint, unlike Postgres so the
+ # insertion does not fail and we have to check dumbly that File is
+ # created before.
+ self.assertGreater(salesterm.eid, salesterm.described_by_test[0].eid)
+
def test_edit_multiple_linked(self):
req = self.request()
peid = u(self.create_user(req, 'adim').eid)
--- a/web/views/editcontroller.py Thu Jul 25 18:14:56 2013 +0200
+++ b/web/views/editcontroller.py Fri Jul 26 13:47:52 2013 +0200
@@ -166,7 +166,10 @@
if target_eid in values_by_eid:
# add dependency from the target entity to the
# current one
- graph.setdefault(target_eid, set()).add(eid)
+ if role == 'object':
+ graph.setdefault(target_eid, set()).add(eid)
+ else:
+ graph.setdefault(eid, set()).add(target_eid)
break
for eid in reversed(ordered_nodes(graph)):
yield values_by_eid[eid]