Commit 7910c6ef authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

new create_entity method, temporarily on base request (later on cw entity...

new create_entity method, temporarily on base request (later on cw entity manager or as factory method)

--HG--
branch : 3.5
parent 452b4c9ee61d
......@@ -121,6 +121,27 @@ class RequestSessionMixIn(object):
raise KeyError
def set_entity_cache(self, entity):
pass
def create_entity(self, etype, *args, **kwargs):
"""add a new entity of the given type"""
rql = 'INSERT %s X' % etype
relations = []
restrictions = []
cachekey = []
for rtype, rvar in args:
relations.append('X %s %s' % (rtype, rvar))
restrictions.append('%s eid %%(%s)s' % (rvar, rvar))
cachekey.append(rvar)
for attr in kwargs:
if attr in cachekey:
continue
relations.append('X %s %%(%s)s' % (attr, attr))
if relations:
rql = '%s: %s' % (rql, ', '.join(relations))
if restrictions:
rql = '%s WHERE %s' % (rql, ', '.join(restrictions))
return self.execute(rql, kwargs, cachekey).get_entity(0, 0)
# url generation methods ##################################################
def build_url(self, *args, **kwargs):
......
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