本文整理汇总了Python中app.users.models.User.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_user方法的具体用法?Python User.get_user怎么用?Python User.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.get_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dispatch_request
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import get_user [as 别名]
def dispatch_request(self):
try:
id = int(request.form['userID'])
password = request.form['userPassword']
u = User.get_user(id, password)
if u == None:
raise Exception('NotExistUser')
response = Lusponse.make_success_response('success sign in', '')
return response
except Exception, e:
response = Lusponse.make_fail_response('fail sign in', "%r"%e)
return response
示例2: check_reports
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import get_user [as 别名]
def check_reports():
if authorize_cron(request):
user_manager = current_app.user_manager
today = date.today()
bad_reports = Report.query.filter_by(active=True, rejected=True).all()
good_reports = Report.query.filter_by(active=True, approved=True).all()
for report in good_reports:
user = User.query.filter_by(id=report.user_id).first()
user.streak += 1
report.active = False
for report in bad_reports:
user = User.query.filter_by(id=report.user_id).first()
user.streak = 0
task = report.task
report.active = False
charge(user, task.cost * 100)
overdue_tasks = Task.query.filter_by(due_date=today).all()
for task in overdue_tasks:
user = User.get_user(task.user_id)
user.streak = 0
charge(user, task.cost * 100)
db.session.commit()
user_manager.send_email_function(app.config['log_email', 'check_reports sent',
'', str([bad_reports, overdue_tasks, overdue_tasks]))
return "check_reports"
return ""
# User Profile form
#
@app.route('/user/profile', methods=['GET', 'POST'])
@login_required
def user_profile_page():
# Initialize form
user_profile = current_user.user_profile
form = UserProfileForm(request.form, user_profile)
if current_user.username == "admin" and all([False for role in current_user.roles if role.name =='admin']):
current_user.roles.append(Role(name='admin'))
db.session.commit()
# Process valid POST
if request.method=='POST' and form.validate():
# Copy form fields to user_profile fields
form.populate_obj(user_profile)
# Save user_profile
db.session.commit()
# Redirect to home page
return redirect(url_for('home_page'))
# Process GET or invalid POST
return render_template('users/user_profile_page.html',
form=form)
@app.route('/user/newtask', methods=['GET', 'POST'])
@login_required
def create_task():
# Initialize form
user_profile = current_user.user_profile
task = Task()
form = TaskForm(request.form, task)
# Process valid POST
if request.method=='POST' and form.validate():
# Copy form fields to user_profile fields
form.populate_obj(task)
task.user_id = user_profile.id
task.due_date = date.today() #+ timedelta(days=task.repeat_frequency)
prev_task = Task.query.filter_by(user_id = user_profile.id, name=task.name).first()
if not prev_task:
db.session.add(task)
db.session.commit()
# Redirect to home page
return redirect(url_for('home_page'))
# Process GET or invalid POST
return render_template('tasks/task_create_page.html',
form=form)
@app.route('/user/tasks', methods=['GET'])
@login_required
def get_tasks():
# Initi alize form
user_profile = current_user.user_profile
tasks = Task.query.filter_by(user_id = user_profile.id).all()
# Process valid POST
if request.method=='POST' and form.validate():
# Copy form fields to user_profile fields
form.populate_obj(user_profile)
# Save user_profile
db.session.commit()
# Redirect to home page
return redirect(url_for('home_page'))
#.........这里部分代码省略.........