def update(self, user_id): user = DBSession.query(User).get(user_id) self.can_modify(user) params = parse_request(self.request) print params.items() for key, value in params.items(): setattr(user, key, value) DBSession.add(user) DBSession.flush() self.ctx.success = True self.ctx.message = 'Updated user.'
def create(self): params = parse_request(self.request) tag_csv = ','.join(params['tags']) group = DBSession.query(Group).filter(Group.id.in_(params['groups'])).first() for user_dict in params['users']: new_user = User(**user_dict) if tag_csv: new_user.tags = tag_csv if group: new_user.group_id = group.id try: DBSession.begin_nested() DBSession.add(new_user) DBSession.flush() # print 'Adding user', user_dict['email'] except sqlalchemy.exc.IntegrityError, exc: DBSession.rollback() self.flash(str(exc), success=False) user = DBSession.query(User).filter(User.email==user_dict['email']).first() user.merge(new_user) DBSession.flush()