本文整理汇总了Python中forms.EventForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python EventForm.validate方法的具体用法?Python EventForm.validate怎么用?Python EventForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.EventForm
的用法示例。
在下文中一共展示了EventForm.validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import validate [as 别名]
def add_event():
def _dup(l):
return [(i, i) for i in l]
session = create_session()
form = EventForm(request.forms.decode())
form.continent.choices = _dup(CONTINENTS)
# countries = session.query(Country) # XXX: why is countries never used?
# form.country.choices = [(c.id, c.name) for c in countries.all()]
# form.gender.choices = _dup(["male", "female", "all"])
if form.validate():
session = create_session()
new_task = Event.from_form(form)
try:
for attachment in scan_attachments(request.files):
print "saving attachment: ", attachment, attachment.filename
new_task.attachments.append(Attachment(
file_path=save_file(attachment),
file_name=attachment.filename,
file_type=attachment.content_type))
session.add(new_task)
session.commit()
return redirect("/")
except InvalidFileUpload as e:
form.errors['attachment'] = e.message
print dict(request.forms)
print form.errors
print type(form.errors)
return new(errors=form.errors)
示例2: post_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import validate [as 别名]
def post_event():
form = EventForm()
if 'email' not in session:
flash("You need to login to post Events")
return redirect(url_for('signin'))
user = User.query.filter_by(email = session['email']).first()
if user is None:
return redirect(url_for())
if request.method == 'POST':
if form.validate() == False:
flash("Fill all the fields")
return render_template('post_events.html',form=form)
else:
newevent = Event(form.name.data,
form.location.data,
form.date.data,
form.description.data)
db.session.add(newevent)
flash("Event successfully posted")
db.session.commit()
return redirect(url_for('index'))
elif request.method == 'GET':
return render_template('post_events.html',form=form)
示例3: newEvent
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import validate [as 别名]
def newEvent():
'''
Add an event, requires to be logged and makes the user the event owner.
Fills the choices select field with all the available categories.
Returns a redirect to show events after adding the event in case of POST
or the add event html page in case of GET.
'''
form = EventForm(request.form)
form.category_id.choices = ([
(c.id, c.name) for c in Category.query.order_by(Category.name)])
form.category_id.choices.insert(0, (0, 'select'))
if request.method == 'POST' and form.validate():
newEvent = Event(
category_id=form.category_id.data,
name=form.name.data,
location=form.location.data,
date=form.date.data,
username=session['username']
)
db.session.add(newEvent)
db.session.commit()
flash('New event created')
return redirect(url_for('showEvents'))
else:
return render_template('new_event.html', form=form)
示例4: edit_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import validate [as 别名]
def edit_event(id):
def _dup(l):
return [(i, i) for i in l]
session = create_session()
form = EventForm(request.forms)
form.continent.choices = _dup(CONTINENTS)
# countries = session.query(Country) # XXX: why is countries never used?
if form.validate():
session = create_session()
eventToEdit = session.query(Event).get(id)
eventToEdit.update(form)
session.commit()
redirect("/admin")
else:
print "gender=", form.gender
print dict(request.forms)
print form.errors
print type(form.errors)
return new(errors=form.errors)
示例5: editEvent
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import validate [as 别名]
def editEvent(event_id):
'''
Edit an event, requires to be logged and checks if the user is the event
owner in the html rendered file.
event_id is the id of the category to be edited.
Returns a redirect to show events after event edition in case of POST
or the edit event html page in case of GET
'''
event = Event.query.filter_by(id=event_id).one()
form = EventForm(request.form)
form.category_id.choices = ([
(c.id, c.name) for c in Category.query.order_by(Category.name)])
form.category_id.choices.insert(0, (0, 'select'))
if request.method == 'POST' and form.validate():
event.category_id = request.form['category_id']
event.name = request.form['name']
event.location = request.form['location']
event.date = datetime.datetime.strptime(
request.form['date'], '%d/%m/%Y').date()
db.session.commit()
flash("Event updated")
return redirect(url_for('showEvents'))
else:
return render_template('edit_event.html', event=event, form=form)