def migrate_datas(): from autonomie_base.models.base import DBSESSION session = DBSESSION() from alembic.context import get_bind connection = get_bind() from autonomie.models.user.login import Login op.execute("update groups set editable=0;") op.execute("update groups set `primary`=0;") op.execute( "update groups set `primary`=1 where name IN ('admin', 'contractor', 'manager')" ) op.execute('update accounts set civilite="Monsieur"') for user in connection.execute(user_helper.select()): login = Login( user_id=user.id, login=user.login, ) login.pwd_hash = user.password, login.active = user.active == 'Y' session.add(login) session.flush() op.execute( 'UPDATE user_groups set login_id="%s" where user_id=%s' % ( login.id, user.id ) ) op.drop_column("accounts", "login") op.drop_column("accounts", "password") op.drop_column("accounts", "active") from autonomie.models.user.user import User for userdatas in connection.execute(userdatas_helper.select()): if userdatas.user_id is None: user = User( lastname=userdatas.coordonnees_lastname, firstname=userdatas.coordonnees_firstname, email=userdatas.coordonnees_email1, civilite=userdatas.coordonnees_civilite or 'Monsieur', ) session.add(user) session.flush() connection.execute( userdatas_helper.update().where( userdatas_helper.c.id == userdatas.id ).values(user_id=user.id) ) else: user = User.get(userdatas.user_id) user.civilite = userdatas.coordonnees_civilite or 'Monsieur' session.merge(user) session.flush() op.execute('update accounts set civilite="Monsieur" where civilite is NULL')
def company_remove_employee_view(context, request): """ Enlève un employé de l'entreprise courante """ uid = request.params.get('uid') if not uid: request.session.flash('Missing uid parameter', 'error') user = User.get(uid) if not user: request.session.flash('User not found', 'error') if user in context.employees: context.employees = [ employee for employee in context.employees if employee != user ] request.session.flash( u"L'utilisateur {0} ne fait plus partie de l'entreprise {1}". format(format_account(user), context.name)) url = request.referer if url is None: url = request.route_path('company', id=context.id) return HTTPFound(url)
def company_remove_employee_view(context, request): """ Enlève un employé de l'entreprise courante """ uid = request.params.get('uid') if not uid: request.session.flash('Missing uid parameter', 'error') user = User.get(uid) if not user: request.session.flash('User not found', 'error') if user in context.employees: context.employees = [ employee for employee in context.employees if employee != user ] request.session.flash( u"L'utilisateur {0} ne fait plus partie de l'entreprise {1}".format( format_account(user), context.name) ) url = request.referer if url is None: url = request.route_path('company', id=context.id) return HTTPFound(url)
def submit_success(self, appstruct): """ Edit the database entry and return redirect """ come_from = appstruct.pop('come_from', None) user_id = appstruct.get('user_id') company = Company() company.activities = fetch_activities_objects(appstruct) company = merge_session_with_post(company, appstruct) if user_id is not None: user_account = User.get(user_id) if user_account is not None: company.employees.append(user_account) self.dbsession.add(company) self.dbsession.flush() message = u"L'entreprise '{0}' a bien été ajoutée".format(company.name) self.session.flash(message) if come_from is not None: return HTTPFound(come_from) else: return HTTPFound(self.request.route_path("company", id=company.id))
def title(self): user = User.get(self.request.matchdict['uid']) return u'Ajouter une feuille de notes de dépenses ({})'.format( user.label, )
def validate_trainer(node, value): user = User.get(value) if 'trainer' not in user.login.groups: raise colander.invalid(node, msg)