当前位置: 首页>>代码示例>>Python>>正文


Python UploadForm.validate方法代码示例

本文整理汇总了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)
开发者ID:nemobis,项目名称:BUB,代码行数:37,代码来源:routes.py

示例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"))
开发者ID:zhayden,项目名称:UCRinterest,代码行数:28,代码来源:__init__.py

示例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)
开发者ID:kkarra,项目名称:bddb_new,代码行数:33,代码来源:views.py

示例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)
开发者ID:sebastianiag,项目名称:Webdev,代码行数:10,代码来源:views.py

示例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) 
开发者ID:mattdeboard,项目名称:Python-WebOCR,代码行数:15,代码来源:views.py

示例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)
开发者ID:connienguyen,项目名称:knitting,代码行数:38,代码来源:app.py


注:本文中的forms.UploadForm.validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。