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


Python EventForm.validate方法代码示例

本文整理汇总了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)
开发者ID:steinnes,项目名称:judo-events,代码行数:33,代码来源:index.py

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

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

示例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)
开发者ID:steinnes,项目名称:judo-events,代码行数:23,代码来源:index.py

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


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