def user_seeder(): db.session.add( User(user_name='admin', user_password=bcrypt.generate_password_hash('admin'), firstname=u'ผู้ดูแลระบบ', lastname='', branch_id=1, user_type='admin')) db.session.add( User(user_name='cashier', user_password=bcrypt.generate_password_hash('cashier'), firstname=u'แคชเชียร์', lastname='', branch_id=1, user_type='cashier')) db.session.add( User(user_name='staff', user_password=bcrypt.generate_password_hash('staff'), firstname=u'สตาฟ', lastname='', branch_id=1, user_type='staff')) db.session.commit()
def user_save(): result = 0 f = request.get_json() if f is None: f = request.form forms = { 'user_name': f.get('user_name') or '', 'user_password': bcrypt.generate_password_hash(f.get('user_password') or ''), 'firstname': f.get('firstname') or '', 'lastname': f.get('lastname') or '', 'branch_id': f.get('branch_id') or None, 'user_type': f.get('user_type') or '', } id = f.get('id') or None if id: user = User.query.get(id) for k, v in forms.iteritems(): setattr(user, k, v) db.session.merge(user) else: user = User() for k, v in forms.iteritems(): setattr(user, k, v) db.session.add(user) db.session.commit() if user: result = user.id return jsonify({'result': result})