502 or session.execute('CWUser X WHERE X use_email C, C address %(login)s', |
502 or session.execute('CWUser X WHERE X use_email C, C address %(login)s', |
503 {'login': login})): |
503 {'login': login})): |
504 qname = role_name('login', 'subject') |
504 qname = role_name('login', 'subject') |
505 raise ValidationError(None, {qname: errmsg % login}) |
505 raise ValidationError(None, {qname: errmsg % login}) |
506 # we have to create the user |
506 # we have to create the user |
507 user = self.vreg['etypes'].etype_class('CWUser')(session, None) |
507 user = self.vreg['etypes'].etype_class('CWUser')(session) |
508 if isinstance(password, unicode): |
508 if isinstance(password, unicode): |
509 # password should *always* be utf8 encoded |
509 # password should *always* be utf8 encoded |
510 password = password.encode('UTF8') |
510 password = password.encode('UTF8') |
511 kwargs['login'] = login |
511 kwargs['login'] = login |
512 kwargs['upassword'] = password |
512 kwargs['upassword'] = password |
932 if rtype in schema.VIRTUAL_RTYPES or rtype in pendingrtypes: |
932 if rtype in schema.VIRTUAL_RTYPES or rtype in pendingrtypes: |
933 continue |
933 continue |
934 if role == 'subject': |
934 if role == 'subject': |
935 # don't skip inlined relation so they are regularly |
935 # don't skip inlined relation so they are regularly |
936 # deleted and so hooks are correctly called |
936 # deleted and so hooks are correctly called |
937 selection = 'X %s Y' % rtype |
937 rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype |
938 else: |
938 else: |
939 selection = 'Y %s X' % rtype |
939 rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype |
940 rql = 'DELETE %s WHERE X eid %%(x)s' % selection |
|
941 session.execute(rql, {'x': eid}, 'x', build_descr=False) |
940 session.execute(rql, {'x': eid}, 'x', build_descr=False) |
942 self.system_source.delete_info(session, entity, sourceuri, extid) |
941 self.system_source.delete_info(session, entity, sourceuri, extid) |
943 |
942 |
944 def locate_relation_source(self, session, subject, rtype, object): |
943 def locate_relation_source(self, session, subject, rtype, object): |
945 subjsource = self.source_from_eid(subject, session) |
944 subjsource = self.source_from_eid(subject, session) |
995 # XXX kill that transmutation feature ! |
994 # XXX kill that transmutation feature ! |
996 if not entity_ is entity: |
995 if not entity_ is entity: |
997 entity.__class__ = entity_.__class__ |
996 entity.__class__ = entity_.__class__ |
998 entity.__dict__.update(entity_.__dict__) |
997 entity.__dict__.update(entity_.__dict__) |
999 eschema = entity.e_schema |
998 eschema = entity.e_schema |
1000 etype = str(eschema) |
999 source = self.locate_etype_source(entity.__regid__) |
1001 source = self.locate_etype_source(etype) |
1000 # allocate an eid to the entity before calling hooks |
1002 # attribute an eid to the entity before calling hooks |
|
1003 entity.set_eid(self.system_source.create_eid(session)) |
1001 entity.set_eid(self.system_source.create_eid(session)) |
1004 # set caches asap |
1002 # set caches asap |
1005 extid = self.init_entity_caches(session, entity, source) |
1003 extid = self.init_entity_caches(session, entity, source) |
1006 if server.DEBUG & server.DBG_REPO: |
1004 if server.DEBUG & server.DBG_REPO: |
1007 print 'ADD entity', etype, entity.eid, dict(entity) |
1005 print 'ADD entity', entity.__regid__, entity.eid, dict(entity) |
1008 relations = [] |
1006 relations = [] |
1009 if source.should_call_hooks: |
1007 if source.should_call_hooks: |
1010 self.hm.call_hooks('before_add_entity', session, entity=entity) |
1008 self.hm.call_hooks('before_add_entity', session, entity=entity) |
1011 # XXX use entity.keys here since edited_attributes is not updated for |
1009 # XXX use entity.keys here since edited_attributes is not updated for |
1012 # inline relations |
1010 # inline relations XXX not true, right? (see edited_attributes |
|
1011 # affectation above) |
1013 for attr in entity.iterkeys(): |
1012 for attr in entity.iterkeys(): |
1014 rschema = eschema.subjrels[attr] |
1013 rschema = eschema.subjrels[attr] |
1015 if not rschema.final: # inlined relation |
1014 if not rschema.final: # inlined relation |
1016 relations.append((attr, entity[attr])) |
1015 relations.append((attr, entity[attr])) |
1017 entity.set_defaults() |
1016 entity.set_defaults() |
1050 |
1049 |
1051 def glob_update_entity(self, session, entity, edited_attributes): |
1050 def glob_update_entity(self, session, entity, edited_attributes): |
1052 """replace an entity in the repository |
1051 """replace an entity in the repository |
1053 the type and the eid of an entity must not be changed |
1052 the type and the eid of an entity must not be changed |
1054 """ |
1053 """ |
1055 etype = str(entity.e_schema) |
|
1056 if server.DEBUG & server.DBG_REPO: |
1054 if server.DEBUG & server.DBG_REPO: |
1057 print 'UPDATE entity', etype, entity.eid, \ |
1055 print 'UPDATE entity', entity.__regid__, entity.eid, \ |
1058 dict(entity), edited_attributes |
1056 dict(entity), edited_attributes |
1059 entity.edited_attributes = edited_attributes |
1057 entity.edited_attributes = edited_attributes |
1060 if session.is_hook_category_activated('integrity'): |
1058 if session.is_hook_category_activated('integrity'): |
1061 entity.check() |
1059 entity.check() |
1062 eschema = entity.e_schema |
1060 eschema = entity.e_schema |