262 # attributes/relations shared by all entities of the same type |
262 # attributes/relations shared by all entities of the same type |
263 self.etype_attrs = [] |
263 self.etype_attrs = [] |
264 self.etype_rels = [] |
264 self.etype_rels = [] |
265 # attributes/relations specific to each entity |
265 # attributes/relations specific to each entity |
266 self.entity_attrs = ['cwuri'] |
266 self.entity_attrs = ['cwuri'] |
267 #self.entity_rels = [] XXX not handled (YAGNI?) |
267 rschema = cnx.vreg.schema.rschema |
268 schema = cnx.vreg.schema |
|
269 rschema = schema.rschema |
|
270 for rtype in self.META_RELATIONS: |
268 for rtype in self.META_RELATIONS: |
271 # skip owned_by / created_by if user is the internal manager |
269 # skip owned_by / created_by if user is the internal manager |
272 if cnx.user.eid == -1 and rtype in ('owned_by', 'created_by'): |
270 if cnx.user.eid == -1 and rtype in ('owned_by', 'created_by'): |
273 continue |
271 continue |
274 if rschema(rtype).final: |
272 if rschema(rtype).final: |
293 rels[rel] = genfunc(entity) |
291 rels[rel] = genfunc(entity) |
294 return entity, rels |
292 return entity, rels |
295 |
293 |
296 def init_entity(self, entity): |
294 def init_entity(self, entity): |
297 entity.eid = self.create_eid(self._cnx) |
295 entity.eid = self.create_eid(self._cnx) |
|
296 # if cwuri is specified, this is an extid. It's not if it's generated in the above loop |
298 extid = entity.cw_edited.get('cwuri') |
297 extid = entity.cw_edited.get('cwuri') |
|
298 if isinstance(extid, text_type): |
|
299 extid = extid.encode('utf-8') |
299 for attr in self.entity_attrs: |
300 for attr in self.entity_attrs: |
300 if attr in entity.cw_edited: |
301 if attr in entity.cw_edited: |
301 # already set, skip this attribute |
302 # already set, skip this attribute |
302 continue |
303 continue |
303 genfunc = self.generate(attr) |
304 genfunc = self.generate(attr) |
304 if genfunc: |
305 if genfunc: |
305 entity.cw_edited.edited_attribute(attr, genfunc(entity)) |
306 entity.cw_edited.edited_attribute(attr, genfunc(entity)) |
306 if isinstance(extid, text_type): |
|
307 extid = extid.encode('utf-8') |
|
308 return self.source, extid |
307 return self.source, extid |
309 |
308 |
310 def generate(self, rtype): |
309 def generate(self, rtype): |
311 return getattr(self, 'gen_%s' % rtype, None) |
310 return getattr(self, 'gen_%s' % rtype, None) |
312 |
311 |