def get_or_create_organization(name, type_name, parent=None): org_type = _get_organization_type(type_name) organization = OrganizationData.get_by(label=name, type=org_type, parent=parent) if not organization: organization = OrganizationData(label=name, type=org_type, parent=parent) return organization
def update_user(self): # checks the other fields and updates data if super(UserLineEditor, self).commit( (), ('corporation_id', 'direction_id', 'site_id', 'service_id', 'fi_uid', 'enabled')): # FIXME: use the OrganizationRepository get_orga = lambda id: OrganizationData.get(id ) if id != -1 else None u = self.user_repository.get_by_uid(self.uid) u.corporation = get_orga(self.corporation_id()) u.direction = get_orga(self.direction_id()) u.service = get_orga(self.service_id()) u.site = get_orga(self.site_id()) u.subsite = get_orga(self.subsite_id()) u.enabled = self.enabled() u.fi_uid = self.fi_uid() session.flush() self.orig_corp_id = u.corporation_id or -1L self.orig_dir_id = u.direction_id or -1L self.orig_service_id = u.service_id or -1L self.orig_site_id = u.site_id or -1L self.orig_subsite_id = u.subsite_id or -1L self.orig_enabled = u.enabled self.orig_fi_uid = u.fi_uid flashmessage.set_flash(_(u'User modified')) return True
def update_user(self): # checks the other fields and updates data if super(UserLineEditor, self).commit((), ('corporation_id', 'direction_id', 'site_id', 'service_id', 'fi_uid', 'enabled')): # FIXME: use the OrganizationRepository get_orga = lambda id: OrganizationData.get( id) if id != -1 else None u = self.user_repository.get_by_uid(self.uid) u.corporation = get_orga(self.corporation_id()) u.direction = get_orga(self.direction_id()) u.service = get_orga(self.service_id()) u.site = get_orga(self.site_id()) u.subsite = get_orga(self.subsite_id()) u.enabled = self.enabled() u.fi_uid = self.fi_uid() session.flush() self.orig_corp_id = u.corporation_id or -1L self.orig_dir_id = u.direction_id or -1L self.orig_service_id = u.service_id or -1L self.orig_site_id = u.site_id or -1L self.orig_subsite_id = u.subsite_id or -1L self.orig_enabled = u.enabled self.orig_fi_uid = u.fi_uid flashmessage.set_flash(_(u'User modified')) return True
def create_user(self): user = create_user( uid=u'jcdusse', firstname=u'Jean-Claude', lastname=u'Dusse', email=u'jean-claude.dusse@localhost', work_phone=u'0212345678', mobile_phone=u'0612345678', position=u'Bronzé', corporation=OrganizationData(label=u'PagesJaunes', type=OrganizationType(u'Corporation')), direction=OrganizationData(label=u'Dir. Communication', type=OrganizationType(u'Direction')), service=OrganizationData(label=u'Direction de la Communication', type=OrganizationType(u'Service')), site=OrganizationData(label=u'Sèvres', type=OrganizationType(u'Site')), ) user.photo = self.create_photo() session.flush() return user
def get_or_create_organization(name, type_name, parent=None): org_type = _get_organization_type(type_name) organization = OrganizationData.get_by( label=name, type=org_type, parent=parent ) if not organization: organization = OrganizationData( label=name, type=org_type, parent=parent ) return organization
def commit(self): if not super(UserEditor, self).commit( (), ('login', 'email', 'roles', 'fi_uid', 'work_phone', 'mobile_phone', 'firstname', 'lastname', 'position', 'corporation_id', 'direction_id', 'site_id', 'service_id')): return False # FIXME: use the OrganizationRepository get_organization = lambda id: OrganizationData.get( id) if id != -1 else None corporation = get_organization(self.corporation_id.value) direction = get_organization(self.direction_id.value) service = get_organization(self.service_id.value) site = get_organization(self.site_id.value) subsite = get_organization(self.subsite_id.value) facilitator = self.user_repository.get_by_uid(self.fi_uid.value) # create or update the user updates = dict( email=self.email.value, firstname=self.firstname.value, lastname=self.lastname.value, enabled=self.enabled.value, position=self.position.value, corporation=corporation, direction=direction, service=service, site=site, incorporated=self.incorporated.value, work_phone=self.work_phone.value, mobile_phone=self.mobile_phone.value, fi=facilitator, subsite=subsite, ) if self.user: u = self.user u.set(**updates) else: u = self.user_repository.create(uid=self.login.value, **updates) password = u.reset_password() u.send_welcome_email(password) # roles for role in self.assignable_roles: if role in self.roles(): u.add_role(role) else: u.remove_role(role) return True
def get_directions(self): return OrganizationData.get_directions(parent_id=self.corporation_id())
def get_corporations(self): return OrganizationData.get_corporations()
def get_subsites(self): return ([(_(u'All subsites'), -1)] + OrganizationData.get_subsites(parent_id=self.site_id()))
def choices(self): return OrganizationData.get_directions()
def test_fix_path(self): path = u"#PAGES JAUNES#Direction Informatique#Equipe Développement Mobile#Montpellier" expected = u"#PagesJaunes#Dir. Informatique#Equipe Dév. Mobile#Montpellier" self.assertEqual(expected, OrganizationData.fix_path(path))
def _get_organization_label(self, org_id): if org_id == -1: return None # FIXME: use the OrganizationRepository instead return OrganizationData.get(org_id).label
def get_subsites(self): return OrganizationData.get_subsites(parent_id=self.site_id())
def get_services(self): return OrganizationData.get_services(parent_id=self.direction_id())
def get_directions(self): return ( [(_(u'All directions'), -1)] + OrganizationData.get_directions(parent_id=self.corporation_id()))
def get_corporations(self): return ([(_(u'All corporations'), -1)] + OrganizationData.get_corporations())
def get_directions(self): return ([(_(u'All directions'), -1)] + OrganizationData.get_directions(parent_id=self.corporation_id()))
def get_services(self): return ([(_(u'All services'), -1)] + OrganizationData.get_services(parent_id=self.direction_id()))