本文整理汇总了Python中forms.UploadForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python UploadForm.validate方法的具体用法?Python UploadForm.validate怎么用?Python UploadForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UploadForm
的用法示例。
在下文中一共展示了UploadForm.validate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate [as 别名]
def index():
subtitle = "Transfer books to Internet Archive"
form = UploadForm(request.form)
if request.method == "POST":
if form.validate():
book_id = html_escape(form.book_id.data)
email = html_escape(form.email.data) if form.email.data not in (None, "") else ""
book = bridge.fields(form.library_id.data, book_id, email)
book_id = book.Id if book.Id not in (None, "") else book_id
redis = redis_py.Redis()
redis_key3 = keys.redis_key3
book_key = "%s:%s:%s" % (redis_key3, form.library_id.data, book_id)
library_url_key = book_key + ":library_url"
redis_py.set(library_url_key, form.book_id.data, True)
redis.expire(library_url_key, 60 * 15)
verification_status_no = book.verify_fields()
if verification_status_no != 0:
flash(error_msg(verification_status_no, book))
return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form)
else:
if redundant_request(book) == True:
flash(error_msg(50))
return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form)
book_info = bridge.book_info(form.library_id.data, book_id)
if isinstance(book_info, (int, long, float, complex)):
flash(error_msg(book_info))
return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form)
confirm_resp = make_response(minify(render_template("confirm.html", book_info=book_info, form=form)))
uuid = urandom(32).encode("hex")
confirm_resp.set_cookie("bub_session", uuid)
store_request(book, uuid)
return confirm_resp
return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form)
else:
return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form)
示例2: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate [as 别名]
def upload():
form = UploadForm()
if form.validate():
if form.title.data == "":
flash("Must include title")
return redirect(request.referrer + "#add_form")
filename = secure_filename(form.photo.data.filename)
pos = filename.rfind('.')
#flash(str(filename[pos + 1: ] in ALLOWED_EXTENSIONS))
if pos < 0 or (pos >= 0 and (not filename[pos + 1 : ] in ALLOWED_EXTENSIONS)):
flash("Error: Invalid extension, pleases use jpg or png")
return redirect(request.referrer + '#add_form')
form.photo.file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
pin = Pin(title=form.title.data,
img=filename,
dscrp=form.dscrp.data,
orig=True,
date=datetime.now(),
pinner=current_user.to_dbref(),
repins=0,
like_count=0)
pin.save()
flash("Image has been uploaded.")
else:
flash("Image upload error.")
return redirect(request.referrer + "#add_form" or url_for("index"))
示例3: upload_file
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate [as 别名]
def upload_file():
form = UploadForm()
if request.method == "POST":
if form.validate() == False:
flash("All fields are required.")
return render_template("upload.html", form=form)
else:
file = request.files["filename"]
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
msg = Message(form.subject.data, sender="[email protected]", recipients=["[email protected]"])
msg.body = """
From: %s <%s>
Subject: %s
PeakCaller: %s
SupplementalInfo: %s
File Name: %s
""" % (
form.name.data,
form.email.data,
form.subject.data,
form.peakcaller.data,
form.supplementalinfo.data,
filename,
)
mail.send(msg)
return redirect(url_for("uploaded_file", filename=filename))
elif request.method == "GET":
return render_template("upload.html", form=form)
示例4: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate [as 别名]
def upload():
form = UploadForm()
if request.method == 'POST' and form.validate():
g.user.avatar = form.uri.data
db_session.add(g.user.avatar)
db_session.commit()
return redirect(url_for("home", username=g.user.username))
return render_template("upload.html", form=form, user=g.user)
示例5: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate [as 别名]
def upload():
form = UploadForm()
if request.method == "POST":
form = UploadForm(request.form)
if form.validate():
filename = secure_filename(form.img.file.filename)
filename.save(os.path.join(UPLOAD_FOLDER, filename))
flash(ocr(filename))
else:
flash("Invalid filename. Please choose another.")
return render_template("base.html", form=form)
示例6: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate [as 别名]
def upload():
form = UploadForm(request.form)
if request.method == 'POST' and form.validate() and current_user.is_authenticated():
image = request.files['image']
if image:
filename = secure_filename(image.filename)
filename, ext = filename.split('.', 1)
if ext not in IMG_EXTS:
return redirect(url_for('upload'))
timestamp = cleanTime(str(datetime.utcnow()))
filename = filename + timestamp + '.' + ext
image_data = request.files[image.name].read()
open(os.path.join(app.config['UPLOAD_FOLDER'], filename), 'w').write(image_data)
flash('You have uploaded a file')
if form.maxColors.data:
patternfile, across, tall = processImage(filename, form.stitches.data, form.maxColors.data)
colors = form.maxColors.data
else:
patternfile, across, tall = processImage(filename, form.stitches.data)
colors = 256
os.remove(UPLOAD_FOLDER + filename)
patternsave = url_for('static', filename=patternfile)
project = Project(session.get('user_id'), patternsave, form.title.data, form.public.data, across, tall, colors)
db_session.add(project)
db_session.commit()
tags = form.tags.data
if tags:
tags = tags.split(',')
for tag in tags:
if tag != '':
tag = Tag(tag.strip(), project.id)
db_session.add(tag)
db_session.commit()
return redirect(url_for('project', pid=project.id))
return redirect(url_for('index.html'))
return render_template('upload.html', form = form)