本文整理汇总了Python中models.Form.get_random_like_string方法的典型用法代码示例。如果您正苦于以下问题:Python Form.get_random_like_string方法的具体用法?Python Form.get_random_like_string怎么用?Python Form.get_random_like_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Form
的用法示例。
在下文中一共展示了Form.get_random_like_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forms
# 需要导入模块: from models import Form [as 别名]
# 或者: from models.Form import get_random_like_string [as 别名]
def forms():
if request.method == 'GET':
if request_wants_json():
return jsonerror(501, {'error': "This endpoint may return the list of forms for the logged user."})
else:
return redirect(url_for('dashboard'))
# Create a new form
if not current_user.upgraded:
return jsonerror(402, {'error': "Please upgrade your account."})
if request.get_json():
email = request.get_json().get('email')
else:
email = request.form.get('email')
if not IS_VALID_EMAIL(email):
if request_wants_json():
return jsonerror(400, {'error': "The email you sent is not a valid email."})
else:
flash('The email you sent is not a valid email.', 'error')
return redirect(url_for('dashboard'))
form = Form(email, owner=current_user)
DB.session.add(form)
DB.session.commit()
# A unique identifier for the form that maps to its id,
# but doesn't seem like a sequential integer
random_like_string = form.get_random_like_string()
if request_wants_json():
return jsonify({
'ok': True,
'random_like_string': random_like_string,
'submission_url': settings.API_ROOT + '/' + random_like_string
})
else:
return redirect(url_for('dashboard'))