本文整理汇总了Python中forms.UploadForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python UploadForm.validate_on_submit方法的具体用法?Python UploadForm.validate_on_submit怎么用?Python UploadForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UploadForm
的用法示例。
在下文中一共展示了UploadForm.validate_on_submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload():
form = UploadForm()
if form.validate_on_submit():
try:
name = form.name.data
filename = images.save(form.image.data, folder=unicode(g.user.id))
#Checks if Image is new or exists before commit changes
image = Image.query.filter_by(name = form.name.data).first()
if image is None:
image = Image(name = name, filename = filename, uid=g.user.id)
message = "%r image uploaded." % name
else:
old_file = image.filename
image.filename = filename
message = "%r image changed." % name
db.session.add(image)
db.session.commit()
flash(message)
return redirect(url_for('index'))
except UploadNotAllowed:
flash("Not allowed to upload image")
else:
filename = None
return render_template('upload.html',
form = form,
filename = filename)
示例2: editCustomerCodes
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def editCustomerCodes(customer_id=None):
form = UploadForm()
if form.validate_on_submit() and form.filename.data:
file = form.filename.data
filename = 'cust_' + str(customer_id) + '.csv'
file.save(os.path.join(CUSTOMER_CODES_PATH, filename))
try:
parse_csv(os.path.join(CUSTOMER_CODES_PATH, filename))
flash(gettext('CSV uploaded and processed sucessfully.'))
except:
flash(gettext('Upload unsuccessful! File could not be parsed!'))
redirect('/settings/editcustomercodes')
def_file_path = getCustomerCodesDefinitionFiles(customer_id)
if def_file_path:
try:
def_file_data = parse_csv(def_file_path[0])
except:
def_file_data = []
else:
def_file_data = []
customer = Customer.query.get(customer_id)
return render_template('/settings/editcustomercodes.html',
title=gettext("Edit Customer Codes"),
customer=customer,
def_file_data=def_file_data,
form=form)
示例3: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload():
if g.user.files.count() >=100:
flash("You can't upload more than 100 files")
return redirect(url_for('index'))
form=UploadForm()
if form.validate_on_submit():
file=form.file.data
filename = secure_filename(file.filename)
#create sha1 of file
url=sha1(file.read()).hexdigest()
f=File.query.filter_by(url=url).first()
if f is None:
file.seek(0)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], url))
else:
if f.own==g.user:
flash('File already exist in your storage(%s)'%f.name)
else:
flash("File already exist(%s in %s's storage)"%(f.name,f.own.nickname))
newfile=File(url=url,timestamp=datetime.datetime.utcnow(),name=filename,own=g.user)
db.session.add(newfile)
db.session.commit()
return redirect(url_for('index'))
return render_template('upload.html',form=form)
示例4: index
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def index():
form = UploadForm()
if request.method == 'POST' and form.validate_on_submit():
bucket_name = app.config['BUCKET_NAME']
key = uuid.uuid4()
filename = str(key) + '.ics'
fullpath = '/' + bucket_name + '/' + filename
upfile = request.files['csv_file']
try:
ics_file = converter.convert(upfile)
except (ContentError, HeadersError, DatetimeFormatError) as error:
flash(error, 'danger')
return render_template('index.html', form=form, links=base_links,
links_title=links_title)
else:
mtype = 'text/calendar'
with gcs.open(fullpath, 'w', content_type=mtype) as w:
w.write(ics_file)
session['key'] = key
return redirect(url_for('success'))
for field, errors in form.errors.items():
for error in errors:
msg = "Whups! {}".format(error)
flash(msg)
return render_template('index.html', form=form, links=base_links,
links_title=links_title)
示例5: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload():
if not current_user.is_admin():
return 'Not Authorized', 500
form = UploadForm(request.form)
if form.validate_on_submit():
#save and process it
pass
return render_template('upload.html', form=form)
示例6: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload():
"""Render the website's about page."""
form = UploadForm()
if request.method == 'POST' and form.validate_on_submit():
data_file = request.files['file']
file_name = secure_filename(data_file.filename)
data_file.save(os.path.join(UPLOAD_FOLDER, file_name))
save_form_data(request.form, file_name)
return redirect(url_for('thanks'))
return render_template('upload.html', form=form)
示例7: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload():
form = UploadForm()
if form.validate_on_submit():
f = form.photo.data
filename = random_filename(f.filename)
f.save(os.path.join(app.config['UPLOAD_PATH'], filename))
flash('Upload success.')
session['filenames'] = [filename]
return redirect(url_for('show_images'))
return render_template('upload.html', form=form)
示例8: dataImport
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def dataImport():
form = UploadForm()
colnames = get_colnames(Product)
form.colnames = colnames
if form.validate_on_submit() and form.filename.data:
filename = secure_filename(form.filename.data.filename)
file = request.files[form.filename.name].read()
open(os.path.join(CSV_PATH, filename), 'w').write(file)
result = process_csv(os.path.join(CSV_PATH, filename), Product, colnames)
flash(result)
redirect('/settings/dataimport')
return render_template('/settings/dataimport.html',
title=gettext("Data Import"),
form=form)
示例9: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload():
form = UploadForm()
if form.validate_on_submit():
flash('TXT registered')
db = Db()
filename = secure_filename(form.upload.data.filename)
form.upload.data.save(os.path.join(app.config['UPLOADED_TEXT_DEST'], filename))
SQL = 'INSERT INTO text (author_name, file_location, description, title, text_type, pub_date) VALUES (%s, %s, %s, %s, %s, %s);'
data = (form.author.data, "uploads/" + form.upload.data.filename, form.description.data, form.title.data, form.textType.data, form.pub_date.data)
db.execute(SQL, data)
return redirect(url_for('pick'))
else:
filename = None
return render_template('upload.html', form=form, filename=filename)
示例10: upload_file_form
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload_file_form(game_slug, release_id):
# release_id = request.args.get('release', None)
# file_id = request.args.get('file', None)
# if file_id: # edit/re-upload
# file = db.session.query(File).filter(File.id==file_id).one()
# form = UploadForm()
# form.edit.data = "True"
# else:
form = UploadForm()
form.edit.data = ""
if form.validate_on_submit():
uploaded_file = form.uploaded_file.data
save_file(uploaded_file, release_id)
flash('File uploaded!')
return render_template('upload_files.html', form=form, upload_url=game_slug + '/filesupload/'+release_id, site_data=site_data(), navigation=return_navigation())
示例11: upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload():
user = g.user
form = UploadForm()
if form.validate_on_submit():
video = Video(link = form.link.data,
comment = form.comment.data,
timestamp = datetime.datetime.utcnow(),
author = user)
db.session.add(video)
db.session.commit()
flash("Upload successful!")
return redirect(url_for('index'))
return render_template('upload.html',
title = 'Upload',
form = form,
user = user)
示例12: upload_file_old
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def upload_file_old(game_slug):
release_id = request.args.get('release', None)
file_id = request.args.get('file', None)
if file_id:
file = db.session.query(File).filter(File.id==file_id).one()
form = UploadForm()
form.edit.data = "True"
else:
form = UploadForm()
form.edit.data = ""
if form.validate_on_submit():
uploaded_file = form.uploaded_file.data
if uploaded_file: # and allowed_file(uploaded_file.filename):
filename = secure_filename(uploaded_file.filename)
if os.path.isfile(os.path.join(app.config['UPLOAD_FOLDER'], filename)):
fileName, fileExtension = os.path.splitext(filename)
filename = fileName + '-' + time.strftime("%Y%m%d-%H%M%S") + fileExtension
uploaded_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
if form.edit.data:
if uploaded_file:
file.filename=filename
file.description=form.description.data
else:
if uploaded_file:
# release = Release.query.filter(Release.id==release_id).one()
file = File(release_id=release_id, filename=filename, description=form.description.data)
db.session.add(file)
if uploaded_file or form.edit.data:
file.approved = False;
db.session.commit()
if not form.edit.data:
form.description.data=None
if form.edit.data:
flash('File changed!')
else:
if uploaded_file:
flash('File uploaded!')
else:
if form.edit.data:
form.description.data=file.description
return render_template('add_file.html', form=form, site_data=site_data(), navigation=return_navigation())
示例13: ui_upload
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def ui_upload():
form = UploadForm()
message = ""
error = ""
if form.validate_on_submit():
artist = None
if form.artist.data != "":
artist = form.artist.data
album = None
if form.album.data != "":
album = form.album.data
track = None
if form.track.data != "":
track = form.track.data
current_user.radio.add_download("youtube-dl", form.url.data, artist, album, track)
message = "Dodano link do kolejki pobierania"
return render_template('upload.html', form=form, message=message, error=error)
示例14: uploads
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
def uploads():
form = UploadForm()
if form.validate_on_submit():
description = form.description.data
photoData = form.photo.data
filename = secure_filename(photodata.filename)
try:
potoData.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
return jsonify(message="201", filename=filename, description=description)
except Exception as e:
print e:
return jsonify(errors=["internal Error"])
示例15: UploadFormProcessor
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import validate_on_submit [as 别名]
class UploadFormProcessor(FormProcessor):
def __init__(self, *args, **kwargs):
super(UploadFormProcessor, self).__init__(*args, **kwargs)
self.select_form()
def select_form(self):
if self.page.form:
self.form = self.page.form
self.form = self.process_form()
else:
self.get_form()
if request.is_xhr:
self.rendered_form = self.form
else:
self.form_template = self.get_form_template()
self.rendered_form = self.render_form()
def get_form(self):
if 'key' in request.args:
if request.endpoint == "photos":
self.page.assets['new_photo'] = request.args['key']
self.form = PostForm()
self.form.photo.data = self.page.assets['new_photo']
self.template = "post_form.html"
else:
self.page.assets['new_photo'] = request.args['key']
self.form = EditForm()
self.form.photo.data = self.page.assets['new_photo']
self.form.about_me.data = g.user.about_me
self.form.nickname.data = g.user.nickname
self.template = "update_photo.html"
else:
if request.is_xhr:
if request.endpoint == "photos":
self.form = UploadForm(prefix="").s3_upload_form()
else:
if request.endpoint == "photos":
key = "user-images/" + str(g.user.id) + "/" + str(uuid4()) + ".jpeg"
message = "Select New Photo"
redirect_url = request.base_url
else:
key = "user-images/" + str(g.user.id) + "/profile_image/" + str(uuid4()) + ".jpeg"
message = "Change Profile Picture"
redirect_url = request.base_url
self.form = UploadForm(key=key, message=message, redirect_url=redirect_url).s3_upload_form()
def process_form(self):
if self.form.validate_on_submit():
photo_name = self.form.photo.data
post = Post(body=self.form.body.data, timestamp=datetime.utcnow(), category=self.form.category.data,
author=g.user, photo=photo_name, writing_type="entry")
db.session.add(post)
db.session.commit()
exif_stats = ExifStats()
exif_stats.post_id = post.id
exif_data = json.loads(json.dumps(request.json['exifTags']))
for key, value in exif_data.iteritems():
if key == "DateTime" or key == "DateTimeOriginal":
datetimeobject = datetime.strptime(value, '%Y:%m:%d %H:%M:%S')
setattr(exif_stats, key, datetimeobject)
else:
setattr(exif_stats, key, value)
db.session.add(exif_stats)
db.session.commit()
if request.is_xhr:
response = post.json_view()
response['savedsuccess'] = True
self.rendered_form = response
else:
self.form = None
self.rendered_form = None
else:
if request.is_xhr:
self.form.errors['iserror'] = True
return json.dumps(self.form.errors)
else:
self.template = "post_form.html"
self.form_template = self.get_form_template()
self.rendered_form = self.render_form()