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


Python Form.errors["global_error"]方法代码示例

本文整理汇总了Python中pyramid_simpleform.Form.errors["global_error"]方法的典型用法代码示例。如果您正苦于以下问题:Python Form.errors["global_error"]方法的具体用法?Python Form.errors["global_error"]怎么用?Python Form.errors["global_error"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid_simpleform.Form的用法示例。


在下文中一共展示了Form.errors["global_error"]方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: book_edit

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors["global_error"] [as 别名]
def book_edit(request):
    book_id = 0
    try:
        book_id = int(request.matchdict['id'])
    except Exception:
        pass

    if not book_id:
        return HTTPForbidden()

    form = Form(request, schema=BookSchema)
    if form.validate():
        try:
            DBSession.query(Book).filter(Book.id==book_id).update({Book.name:form.data.get("name"),
                                                                   Book.author:form.data.get("author"),
                                                                   Book.desc:form.data.get("desc"),
                                                                   Book.ISBN:form.data.get("ISBN"),
                                                                   Book.price:form.data.get("price")})
            return HTTPFound(location=route_path("book_list", request))
        except IntegrityError:
            transaction.abort()
            form.errors["global_error"] = 'database update error, maybe book name conflict.'
        except Exception:
            transaction.abort()
            form.errors["global_error"] = 'database error.'
            log.error("database error!")
    else:
        book = None
        try:
            book = DBSession.query(Book).filter(Book.id==book_id).first()
        except Exception:
            pass

        if not book:
            return HTTPForbidden()

        form = Form(request, schema=BookSchema, obj = book)

    return dict(renderer=FormRenderer(form))
开发者ID:eryxlee,项目名称:pyramid_koans,代码行数:41,代码来源:views.py

示例2: crime_edit

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors["global_error"] [as 别名]
def crime_edit(request):
    crime_id = 0
    try:
        crime_id = int(request.matchdict['id'])
    except Exception:
        pass

    if not crime_id:
        return HTTPForbidden()

    form = Form(request, schema=CrimeSchema)
    if form.validate():
        try:
            DBSession.query(Crime).filter(Crime.id==crime_id).update({Crime.state:form.data.get("state"),
                                                                   Crime.ctype:form.data.get("ctype"),
                                                                   Crime.crime:form.data.get("crime"),
                                                                   Crime.year:form.data.get("year"),
                                                                   Crime.count:form.data.get("count")})
            return HTTPFound(location=route_path("crimes", request))
        except IntegrityError:
            transaction.abort()
            form.errors["global_error"] = 'database update error.'
        except Exception:
            transaction.abort()
            form.errors["global_error"] = 'database error.'
            log.error("database error!")
    else:
        crime = None
        try:
            crime = DBSession.query(Crime).filter(Crime.id==crime_id).first()
        except Exception:
            pass

        if not crime:
            return HTTPForbidden()

        form = Form(request, schema=CrimeSchema, obj = crime)

    return dict(renderer=FormRenderer(form))
开发者ID:sicarul,项目名称:pyramid_simplecrud,代码行数:41,代码来源:views.py

示例3: book_add

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors["global_error"] [as 别名]
def book_add(request):
    form = Form(request, schema=BookSchema)
    if form.validate():

        book = Book(form.data.get("name"),
                    form.data.get("author"),
                    form.data.get("desc"),
                    form.data.get("ISBN"),
                    form.data.get("price"))

        try:
            DBSession.add(book)
            DBSession.flush()
            transaction.commit()

            return HTTPFound(location=route_path("book_list", request))
        except IntegrityError:
            transaction.abort()
            form.errors["global_error"] = 'database insert error, maybe book name conflict.'
        except Exception, e:
            transaction.abort()
            form.errors["global_error"] = 'database error.' + str(e)
            log.error("database error!")
开发者ID:eryxlee,项目名称:pyramid_koans,代码行数:25,代码来源:views.py

示例4: crime_add

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors["global_error"] [as 别名]
def crime_add(request):
    form = Form(request, schema=CrimeSchema)
    if form.validate():

        crime = Crime(form.data.get("state"),
                    form.data.get("ctype"),
                    form.data.get("crime"),
                    form.data.get("year"),
                    form.data.get("count"))

        try:
            DBSession.add(crime)
            DBSession.flush()
            transaction.commit()

            return HTTPFound(location=route_path("crimes", request))
        except IntegrityError:
            transaction.abort()
            form.errors["global_error"] = 'database insert error.'
        except Exception, e:
            transaction.abort()
            form.errors["global_error"] = 'database error.' + str(e)
            log.error("database error!")
开发者ID:sicarul,项目名称:pyramid_simplecrud,代码行数:25,代码来源:views.py


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