def create_dummy_data(): default_user_type = ["Admin", "Staff", "Client"] for user_type in default_user_type: db.session.add(UserType(name=user_type)) db.session.commit() # Create product area default_product_area = ["Policies", "Billing", "Claims", "Reports"] for product_area in default_product_area: db.session.add(ProductArea(name=product_area)) db.session.commit() # Create dummy user admin = User(username="******", email="*****@*****.**", userTypeId=get_user_type("Admin"), fullname="Administrator") staff = User(username="******", email="*****@*****.**", userTypeId=get_user_type("Staff"), fullname="Staff 1") clienta = User(username="******", email="*****@*****.**", userTypeId=get_user_type("Client"), fullname="Client A") clientb = User(username="******", email="*****@*****.**", userTypeId=get_user_type("Client"), fullname="Client B") clientc = User(username="******", email="*****@*****.**", userTypeId=get_user_type("Client"), fullname="Client C") users = [admin, staff, clienta, clientb, clientc] for user in users: db.session.add(user) db.session.commit() for client_username in ["clienta", "clientb", "clientc"]: create_dummy_feature_request(client_username) db.session.commit()
def edit_userprofile(): if current_user is not None and current_user.is_privileged(UserType.registered): username = request.args.get("username") if not username: abort(404) elif current_user.username.lower() != username.lower(): abort(403) else: return render_template('edit_userprofile.html', username=current_user.username, user=current_user, genderName = GenderType.getName(current_user.gender), typeName=UserType.getName(current_user.type), birthStr = current_user.getBirthStr()) else: abort(403)
def user(): if current_user is not None and current_user.is_privileged(UserType.staff): page = request.args.get("page", 1) if page < 1: page = 1 paginate = Users.query.order_by(Users.uid).paginate(int(page), config.PAGE_ITEMS, False) users = [] for user in paginate.items: user.gender = GenderType.getName(user.gender) user.type = UserType.getName(user.type) users.append(user) return render_template("user.html", username=current_user.username, index=4, pagination=paginate) else: abort(403)
def setup_users(users): user_types = open('{}/initial/user_types.txt'.format(dir_path), 'r').read().splitlines() for user_type_name in user_types: # print 'checked {}'.format(user_type_name) # check user type try: user_type = session.query(UserType) \ .filter(UserType.name == user_type_name) \ .one() # make new entry if not found except NoResultFound as e: user_type = add(UserType(name=user_type_name)) for u in users: try: session.query(User) \ .filter(User.name == u['name']) \ .one() except NoResultFound as e: add( User(name=u['name'], email=u['email'], password=bcrypt.hashpw(u['password'], bcrypt.gensalt()), user_type_id=u['user_type_id'])) for k, v in answers.iteritems(): user = session.query(User) \ .filter(User.user_type_id == k) \ .one() for element_id, text in v.iteritems(): try: session.query(Answer) \ .filter(Answer.user_id == user.id) \ .filter(Answer.element_id == element_id) \ .one() except: add( Answer(name=text, element_id=element_id, user_id=user.id))
def search_user(): if current_user is not None and current_user.is_privileged(UserType.staff): # 由于使用站内搜索功能时结果集一般很少,为简单起见不再支持分页 name = request.args.get("username") if name == "": return render_template("error.html", message="请输入查询的用户名") try: pattern = "%" + name + "%" # 支持模糊查询 result = ( Users.query.filter( or_(Users.username.like(pattern), Users.phone.like(pattern), Users.email.like(pattern)) ) .order_by(Users.uid) .all() ) users = [] for user in result: user.gender = GenderType.getName(user.gender) user.type = UserType.getName(user.type) users.append(user) return render_template("search_user.html", username=current_user.username, users=result, index=4) except Exception, e: # app.logger.error(e) return render_template("error.html", message="查询失败")
def userType(): user_type=UserType.get_user_types() return user_type