當前位置: 首頁>>代碼示例>>Python>>正文


Python EventForm.errors['attachment']方法代碼示例

本文整理匯總了Python中forms.EventForm.errors['attachment']方法的典型用法代碼示例。如果您正苦於以下問題:Python EventForm.errors['attachment']方法的具體用法?Python EventForm.errors['attachment']怎麽用?Python EventForm.errors['attachment']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在forms.EventForm的用法示例。


在下文中一共展示了EventForm.errors['attachment']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_event

# 需要導入模塊: from forms import EventForm [as 別名]
# 或者: from forms.EventForm import errors['attachment'] [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


注:本文中的forms.EventForm.errors['attachment']方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。