Продолжаем вытачивать
полуфабрикат продукта для Zope. На
предыдущем
шаге сделана форма (вкладка ZMI)
редактирования 'Edit'. Теперь
сделаем вкладку просмотра 'View'.
Вкладка 'View'
делается аналогично
вкладке редактирования и даже проще,
потому, что нет нужды делать парную
функцию — обработчик формы. Форма
просмотра будет только «на чтение».
Для разнообразия
сделаю ее на основе шаблона ZPT.
from Products.PageTemplates.PageTemplateFile import PageTemplateFile # ZPT files
from Globals import DTMLFile # dtml files
addForm = DTMLFile('www/vcuFileAdd', globals())
def addFunction(self, id, filename, REQUEST=None):
"""addForm processor function. Constructor.
Create a new VCUFile and add it to container.
"""
p = VCUFileProduct(id, filename)
self.Destination()._setObject(id, p)
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=0)
return id
#def addFunction(dispatcher, id, filename):
class VCUFileProduct(Implicit, Persistent, RoleManager, Item):
"""VCUFile product class, implements IVCUFile
"""
implements(IVCUFile)
#Item requerements
meta_type = 'VCUFile'
id = ''
title = ''
# ZMI views
manage_options = (
{'label':'Edit', 'action': 'editForm'}, # # editForm invoke editFunction
{'label':'View', 'action': ''}, # If your class has a default view method (index_html) you should also include a View view whose action is an empty string
) + RoleManager.manage_options + Item.manage_options # security, undo, ownership
security = ClassSecurityInfo()
security.declareProtected('View', 'index_html')
index_html = PageTemplateFile('www/vcuFileView', globals()) # ZPT file
security.declareProtected('View management screens', 'editForm')
editForm = DTMLFile('www/vcuFileEdit', globals()) # DTML file
|
В модуль с
классом продукта добавлены четыре
строки (выделены жирным). Один импорт,
один элемент кортежа 'manage_options'
и метод 'index_html'
с декларацией защиты.
Сама страничка просмотра
сделана добавлением файла
'vcufile\www\vcuFileView.zpt' такого
содержимого
<html>
<head>
<title tal:content="here/title_or_id">The title</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
<h2><span tal:replace="here/title_or_id">content title or id</span>
<span tal:condition="template/title"
tal:replace="template/title">optional template title</span>
</h2>
This is VCU File <em tal:content="here/id">file id</em>.
</body>
</html>
|
- самого
примитивного (как просто делать заготовки
:)
Осталось совсем
чуть-чуть. Вкладку 'Properties' —
и тема «заготовки Продукта Zope» будет
закрыта.
Комментариев нет:
Отправить комментарий