Crud
====
This module gives you an abstract base class to make CRUD forms with.
These forms give you by default a tabular view of the objects, where
attributes of the object can be edited in-place. Please refer to the
``ICrudForm`` interface for more details.
>>> from megrok.z3cform.crud import crud
Form registration
=================
Models
------
We set up some models to serve as a form context::
>>> import grokcore.component as grok
>>> from zope import interface, schema
>>> class IPerson(interface.Interface):
... name = schema.TextLine(title=u"Name")
... age = schema.Int(title=u"Age")
>>> class Person(grok.Context):
... grok.implements(IPerson)
... name = schema.fieldproperty.FieldProperty(IPerson['name'])
... age = schema.fieldproperty.FieldProperty(IPerson['age'])
...
... def __init__(self, name, age):
... self.name = name
... self.age = age
>>> class IPersonContainer(interface.Interface):
... pass
>>> class PersonContainer(dict):
... grok.implements(IPersonContainer)
For this test, we take the the name of our persons as keys in our
storage:
>>> storage = PersonContainer()
>>> storage['Peter'] = Person(u'Peter', 16)
>>> storage['Martha'] = Person(u'Martha', 32)
We declare the Form with the help of megrok.z3cform.base. It's very similar to a grok.View::
>>> import megrok.z3cform.base as z3cform
>>> class TestForm(crud.CrudForm):
... grok.context(IPersonContainer)
...
... update_schema = IPerson
...
... def get_items(self):
... return sorted(storage.items(), key=lambda x: x[1].name)
...
... def add(self, data):
... person = Person(**data)
... storage[str(person.name)] = person
... return person
...
... def remove(self, (id, item)):
... del storage[id]
Grokking and querying
---------------------
We let Grok register the component::
>>> grok.testing.grok_component('form', TestForm)
True
Now, we can query it normally::
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> from zope.component import getMultiAdapter
>>> myform = getMultiAdapter((storage, request), name="testform")
>>> myform
<TestForm object at ...>
>>> print myform()
<form action="http://127.0.0.1" method="post"
enctype="multipart/form-data" class="form-testform">
...
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共22个文件
txt:9个
py:8个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:megrok.z3cform.crud-0.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
megrok.z3cform.crud-0.1.tar.gz (22个子文件)
megrok.z3cform.crud-0.1
MANIFEST.in 88B
PKG-INFO 3KB
README.txt 2KB
docs
INSTALL.txt 1KB
HISTORY.txt 48B
LICENSE.txt 752B
megrok.z3cform.crud.egg-info
PKG-INFO 3KB
requires.txt 90B
not-zip-safe 1B
SOURCES.txt 602B
top_level.txt 7B
namespace_packages.txt 22B
dependency_links.txt 1B
megrok
__init__.py 244B
z3cform
crud
widget.py 2KB
tests
test_all.py 606B
__init__.py 0B
crud.py 13KB
__init__.py 100B
__init__.py 244B
setup.cfg 59B
setup.py 1KB
共 22 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 12w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- ASP音像销售系统的设计与实现(源代码+论文).rar
- C1.cpp
- 网页设计-仿淘宝网站Web前端大作业报告书
- [论坛社区]MyForum v1.1_myforum11.rar
- 没东西蹭你非要蹭桌角.zip
- okx-android.apk
- myeclipse-ci-2018.12.0-online-installer-windows.rar
- 量程自动切换数字电压表proteus仿真+程序资料_51单片机(论文+开题报告+源代码+详解图).zip
- Q-learning for optimal tracking control
- 自然语言处理NLPPytorchLSTM-GCN图卷积火车票识别源码和视频1G
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功