119 |
119 |
120 def entity_cache(self, eid): |
120 def entity_cache(self, eid): |
121 raise KeyError |
121 raise KeyError |
122 def set_entity_cache(self, entity): |
122 def set_entity_cache(self, entity): |
123 pass |
123 pass |
|
124 |
|
125 def create_entity(self, etype, *args, **kwargs): |
|
126 """add a new entity of the given type""" |
|
127 rql = 'INSERT %s X' % etype |
|
128 relations = [] |
|
129 restrictions = [] |
|
130 cachekey = [] |
|
131 for rtype, rvar in args: |
|
132 relations.append('X %s %s' % (rtype, rvar)) |
|
133 restrictions.append('%s eid %%(%s)s' % (rvar, rvar)) |
|
134 cachekey.append(rvar) |
|
135 for attr in kwargs: |
|
136 if attr in cachekey: |
|
137 continue |
|
138 relations.append('X %s %%(%s)s' % (attr, attr)) |
|
139 if relations: |
|
140 rql = '%s: %s' % (rql, ', '.join(relations)) |
|
141 if restrictions: |
|
142 rql = '%s WHERE %s' % (rql, ', '.join(restrictions)) |
|
143 return self.execute(rql, kwargs, cachekey).get_entity(0, 0) |
|
144 |
124 # url generation methods ################################################## |
145 # url generation methods ################################################## |
125 |
146 |
126 def build_url(self, *args, **kwargs): |
147 def build_url(self, *args, **kwargs): |
127 """return an absolute URL using params dictionary key/values as URL |
148 """return an absolute URL using params dictionary key/values as URL |
128 parameters. Values are automatically URL quoted, and the |
149 parameters. Values are automatically URL quoted, and the |