Commit 067d70ba authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[editcontrollers] Account for role in the ordering of entities (Complements #3031719)

Only role='object' was correctly accounted for by 570208f74a84

--HG--
branch : stable
parent e9fb9377229e
......@@ -197,6 +197,30 @@ class EditControllerTC(CubicWebTC):
# 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)
......
......@@ -166,7 +166,10 @@ class EditController(basecontrollers.ViewController):
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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment