Plone的bdajax集成。
项目描述
集成包
这是针对 bdajax 的 Plone 集成包。
安装
将 egg 文件安装在您的实例中。
应用扩展配置文件。
将 Ajax 动作实现为浏览器视图
可以将 Ajax 动作实现为一个简单的浏览器视图。最简单的方法是仅渲染一个模板。创建模板 tile_a.pt
<div xmlns:ajax="http://namesspaces.bluedynamics.eu/ajax" tal:omit-tag="">
<!-- the tile -->
<div class="tile_a"
style="background-color:#ffc261;">
<h3>I am tile A</h3>
<!-- perform action directly. here we render tile_b, see below -->
<a href=""
ajax:bind="click"
ajax:action="bdajax_example_tile_b:.tile_a:replace"
ajax:target=""
tal:attributes="ajax:target context/absolute_url">alter me</a>
</div>
</div>
通过 ZCML 进行配置
<browser:page
for="*"
name="bdajax_example_tile_a"
template="tile_a.pt"
permission="zope2.View" />
将 Ajax 动作实现为内容提供者
创建一个包含标记的模板 tile_b.pt
<div xmlns:ajax="http://namesspaces.bluedynamics.eu/ajax" tal:omit-tag="">
<!-- bind custom event to tile, perform action if event triggered -->
<!-- when event gets triggered, tile_a gets rendered, see above -->
<div class="tile_b"
style="background-color:#61ff68;"
ajax:bind="altertile"
ajax:action="bdajax_example_tile_a:.tile_b:replace">
<h3>I am tile B</h3>
<!-- bind element to click event and trigger custom event -->
<a href=""
ajax:bind="click"
ajax:event="altertile:.tile_b"
ajax:target=""
tal:attributes="ajax:target context/absolute_url">alter me</a>
</div>
</div>
在 provider.py 中创建内容提供者
from Acquisition import Explicit
from zope.interface import (
Interface,
implementer,
)
from zope.component import adapter
from zope.publisher.interfaces.browser import (
IBrowserRequest,
IBrowserView,
)
from zope.contentprovider.interfaces import IContentProvider
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from bda.plone.ajax import ajax_message
@implementer(IContentProvider)
@adapter(Interface, IBrowserRequest, IBrowserView)
class Provider(Explicit):
template = ViewPageTemplateFile(u'tile_b.pt')
def __init__(self, context, request, view):
self.__parent__ = view
self.context = context
self.request = request
def update(self):
pass
def render(self):
# set here continuation message. See bda.plone.ajax.__init__ for
# details.
ajax_message(self.request, 'Demo continuation message', flavor='info')
return self.template(self)
通过 ZCML 进行提供者配置
<adapter
name="bdajax_example_tile_b"
provides="zope.contentprovider.interfaces.IContentProvider"
factory=".provider.Provider" />
实现包装视图
上述两个 Ajax 动作渲染片段每个只渲染一个瓷砖。现在我们需要将这些包装在 Plone 视图中。创建模板 ploneview.pt
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="here/main_template/macros/master">
<body>
<metal:main fill-slot="main">
<tal:main-macro metal:define-macro="main">
<tal:tile replace="structure context/@@bdajax_example_tile_a" />
</tal:main-macro>
</metal:main>
</body>
</html>
并通过 ZCML 进行注册
<browser:page
for="*"
name="bdajax_example_view"
template="ploneview.pt"
permission="zope2.View" />
现在启动实例并导航到 @@bdajax_example_view。您最初会看到 tile a 被渲染,点击后会切换到 tile b,反之亦然。此代码等同于示例文件夹中的代码。
实现 Ajax 表单
创建一个渲染表单的视图。
创建名为 ajaxform.pt 的模板。属性 ajax:form 告诉 bdajax 处理此表单
<form xmlns:ajax="http://namesspaces.bluedynamics.eu/ajax"
id="example_ajaxform"
method="post"
enctype="multipart/form-data"
ajax:form="True"
tal:define="error view/error"
tal:attributes="action view/form_action">
<label for="field">Field</label>
<div tal:condition="error"
tal:content="error"
style="font-weight:bold;color:red;">
Error Text
</div>
<input type="text"
name="field"
tal:attributes="value view/value" />
<input type="submit" name="submit" value="Submit" />
</form>
创建视图类
from Products.Five import BrowserView
from bda.plone.ajax import ajax_continue
from bda.plone.ajax import ajax_form_fiddle
from bda.plone.ajax import AjaxMessage
class AjaxForm(BrowserView):
@property
def form_action(self):
return 'ajaxform?form_name=bdajax_example_form'
@property
def submitted(self):
return 'field' in self.request.form
@property
def error(self):
if not self.submitted:
return
if not self.request.form['field']:
return u'Field must not be empty'
@property
def value(self):
return self.request.form.get('field')
def __call__(self):
if self.submitted and not self.error:
ajax_continue(self.request, AjaxMessage('Success!', 'info', None))
通过 ZCML 进行视图注册
<browser:page
for="*"
name="bdajax_example_form"
class=".AjaxForm"
template="ajaxform.pt"
permission="zope2.View" />
为表单创建包装视图 ajaxformview.pt
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="here/main_template/macros/master">
<body>
<metal:main fill-slot="main">
<tal:main-macro metal:define-macro="main">
<tal:tile replace="structure context/@@bdajax_example_form" />
</tal:main-macro>
</metal:main>
</body>
</html>
并通过 ZCML 进行注册
<browser:page
for="*"
name="bdajax_example_form_view"
template="ajaxformview.pt"
permission="zope2.View" />
现在启动实例并导航到 @@bdajax_example_form_view。
实现 Ajax 批处理
创建一个 Python 批处理实现,例如 examplebatch.py,计算批词汇
from Products.Five import BrowserView
from bda.plone.ajax.batch import Batch
RESULTLEN = 45
SLICESIZE = 10
class ExampleBatch(Batch):
batchname = 'examplebatch'
@property
def vocab(self):
ret = list()
# len result
count = RESULTLEN
# entries per page
slicesize = SLICESIZE
# number of batch pages
pages = count / slicesize
if count % slicesize != 0:
pages += 1
# current batch page
current = self.request.get('b_page', '0')
for i in range(pages):
# create query with page number
query = 'b_page=%s' % str(i)
# create batch target url
url = '%s?%s' % (self.context.absolute_url(), query)
# append batch page
ret.append({
'page': '%i' % (i + 1),
'current': current == str(i),
'visible': True,
'url': url,
})
return ret
创建批处理结果视图
class BatchedResult(BrowserView):
@property
def batch(self):
return ExampleBatch(self.context, self.request)()
@property
def slice(self):
result = range(RESULTLEN)
current = int(self.request.get('b_page', '0'))
start = current * SLICESIZE
end = start + SLICESIZE
return result[start:end]
创建批处理结果模板,例如 batchedresult.pt
<div xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="bda.plone.ajax"
class="examplebatchsensitiv"
ajax:bind="batchclicked"
tal:attributes="ajax:target context/absolute_url;
ajax:action string:bdajax_example_batched_result:.examplebatchsensitiv:replace">
<tal:listingbatch replace="structure view/batch" />
<ul>
<li tal:repeat="item view/slice" tal:content="item">x</li>
</ul>
<tal:listingbatch replace="structure view/batch" />
</div>
创建包装视图,例如 batchview.pt
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="here/main_template/macros/master"
i18n:domain="bda.plone.ajax">
<body>
<metal:main fill-slot="main">
<tal:main-macro metal:define-macro="main">
<tal:tile replace="structure context/@@bdajax_example_batched_result" />
</tal:main-macro>
</metal:main>
</body>
</html>
并通过 ZCML 进行视图注册
<browser:page
for="*"
name="bdajax_example_batch"
template="batchview.pt"
permission="zope2.View" />
<browser:page
for="*"
name="bdajax_example_batched_result"
class=".examplebatch.BatchedResult"
template="batchedresult.pt"
permission="zope2.View" />
现在启动实例并导航到 @@bdajax_example_batch。您会看到一个批处理示例结果被渲染。此代码等同于示例文件夹中的代码。
示例
该软件包附带示例,如上所述。要启用示例,请通过 ZCML 包括 bda.plone.ajax.examples。
源代码
如果您想帮助开发(改进、更新、错误修复等)bda.plone.ajax,这是一个很好的主意!
代码位于 github collective。
您可以通过克隆或 访问 github-collective 并直接在项目中工作来获取它。
维护者是 Robert Niederreiter 和 BlueDynamics Alliance 开发团队。我们非常感谢任何贡献,如果需要在 PyPI 上发布新版本,请与我们联系:[a href="mailto:dev%40bluedynamics.com" rel="nofollow">dev@bluedynamics dot com
贡献者
Robert Niederreiter(作者)
Jens W. Klein
变更
2.0.1 (2024-04-17)
在 batch.pt 中使用 Python 表达式而不是 TALES。[jensens]
更新 jQuery 遮罩资源条件并调整 bdajax 资源依赖。[petschki]
2.0 (2019-03-10)
停止支持 Plone 4(需要 5.1+)。[agitator]
添加 Python 3 支持。[agitator]
添加最小自定义 jQuerytools 和遮罩,不再依赖于 plone.app.jquerytools。[agitator]
1.8 (2019-02-08)
依赖 Products.CMFPlone 而不是 Plone,以避免获取不必要的依赖项。[thet]
在通过标签名称搜索元素之前检查子项是否为 null。[rnix]
适配到 bdajax 1.10。[rnix]
1.7 (2017-03-10)
在渲染ajax表单时添加隐藏字段 _authenticator,以确保CSRF保护正常工作。[rnix]
Plone 5更新,注册为遗留包。[agitator, rnix]
1.6 (2015-06-25)
为ajaxaction响应明确指定Content-Type: application/json。[jensens, 2015-06-25]
将以前捕获并隐藏的异常(严重性为错误)记录到错误日志中。[jensens, 2015-06-25]
禁用ajaxaction和ajaxform浏览器视图中的diazo主题。[rnix, 2014-12-10]
添加AjaxPath续传。从bdajax 1.6版本开始可以使用。[rnix, 2014-12-10]
1.5
添加ajaxform便捷浏览器页面。[rnix, 2014-02-04]
1.4
清理文档。[rnix, 2013-10-21]
默认不加载示例。[rnix, 2013-10-21]
添加构建ajax批次的抽象批处理。[rnix, 2013-10-20]
1.3
提供覆盖配置。[rnix, 2012-08-06]
提供表单续传。[rnix, 2012-08-06]
1.2.2
在IPortalTop中渲染视图小部件,使其居中弹出,而不是在网站末尾弹出。[jensens, 2011-12-02]
添加z3c.autoinclude入口点。[jensens, 2011-12-02]
1.2.1
如果ajaxaction抛出未捕获的异常,则显示bdajax.message和跟踪信息。[rnix]
1.2
添加ajax续传支持以及续传辅助对象和函数。[rnix]
1.1
添加示例。[rnix]
添加ajaxaction视图。[rnix]
1.0
使其正常工作。[rnix]
许可
版权所有(c)2010-2024,BlueDynamics Alliance,奥地利。保留所有权利。
在满足以下条件的情况下,允许重新分发和使用源代码和二进制形式,无论是否修改:
源代码重新分发必须保留上述版权声明、本许可清单和以下免责声明。
二进制形式的重新分发必须在文档和/或其他随重新分发提供的材料中重新生产上述版权声明、本许可清单和以下免责声明。
未经事先书面许可,不得使用BlueDynamics Alliance的名称或其贡献者的名称来认可或推广源自本软件的产品。[rnix]
本软件由BlueDynamics Alliance提供“按原样”使用,并明确或暗示地放弃了包括但不限于对适销性和针对特定目的的适用性的暗示保证。在任何情况下,BlueDynamics Alliance均不对因使用本软件而产生的任何直接、间接、偶然、特殊、示范性或后果性损害(包括但不限于替代商品或服务的采购;使用、数据或利润的损失;或业务中断)承担责任,即使已告知此类损害的可能性。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。
源代码分发
构建分发
bda.plone.ajax-2.0.1.tar.gz 的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | adc2410ab3cebe93c5116529b042c44da5b19b8055f838dace71946576a682e7 |
|
MD5 | 8a26d00a281283443c04e619146b822f |
|
BLAKE2b-256 | 9d9190a918425d2838d34d698670f59b21601a7ecfd140ca090dc28e1c86052d |
bda.plone.ajax-2.0.1-py3-none-any.whl 的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 026ff8479933004aea6f998b2e1ef8a319a8ba80bf87739aa7e5361de2c774e3 |
|
MD5 | 6ea0b7129f9d26e26c3ca81d368edfc7 |
|
BLAKE2b-256 | c21116d60a5ad47c623485a1779b2fa350aa0a3b0581bb91d99de183ad44ee35 |