provide view base classes + template
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3782 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
642d30ffc3
commit
1b8d510d88
2 changed files with 159 additions and 0 deletions
62
wiki/browser/default.pt
Normal file
62
wiki/browser/default.pt
Normal file
|
@ -0,0 +1,62 @@
|
|||
<html>
|
||||
|
||||
|
||||
<metal:content define-macro="manager">
|
||||
<h1>Wiki Manager</h1>
|
||||
<h2>Wikis</h2>
|
||||
<table>
|
||||
<tr tal:repeat="wiki view/listWikis">
|
||||
<td>
|
||||
<a tal:attributes="href wiki/absolute_url"
|
||||
tal:content="wiki/context/title" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</metal:content>
|
||||
|
||||
|
||||
<metal:content define-macro="wiki">
|
||||
<h1>Wiki</h1>
|
||||
<div tal:repeat="page view/listPages">
|
||||
<a tal:attributes="href page/absolute_url"
|
||||
tal:content="page/title" />
|
||||
</div>
|
||||
</metal:content>
|
||||
|
||||
|
||||
<metal:content define-macro="wikipage">
|
||||
<div metal:define-macro="edit">
|
||||
<tal:edit condition="python: request.get('mode') == 'edit'">
|
||||
<h1>Edit <span tal:content="context/title">Wiki Page</span></h1>
|
||||
<form method="post">
|
||||
<input type="hidden" name="form_action" value="edit" />
|
||||
<div>
|
||||
<div>Title</div>
|
||||
<div>
|
||||
<input name="title" size="40"
|
||||
tal:attributes="value context/title"/></div>
|
||||
</div>
|
||||
<div>
|
||||
<div>Text</div>
|
||||
<div>
|
||||
<textarea name="text" rows="15" cols="60"
|
||||
tal:content="context/text" /></div>
|
||||
</div>
|
||||
<div>
|
||||
<div><input type="submit" value="Save" /></div><br />
|
||||
</div>
|
||||
</form>
|
||||
</tal:edit>
|
||||
</div>
|
||||
<div metal:define-macro="show">
|
||||
<h1 tal:content="context/title">Wiki Page</h1>
|
||||
<div tal:content="structure view/render" />
|
||||
<tal:show condition="python: request.get('mode') != 'edit'">
|
||||
<div> </div>
|
||||
<div><a href="?mode=edit">Edit</a></div>
|
||||
</tal:show>
|
||||
</div>
|
||||
</metal:content>
|
||||
|
||||
|
||||
</html>
|
97
wiki/browser/view.py
Normal file
97
wiki/browser/view.py
Normal file
|
@ -0,0 +1,97 @@
|
|||
#
|
||||
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Classes for wiki-specific views.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope import component
|
||||
from zope.traversing.browser import absoluteURL
|
||||
|
||||
|
||||
class WikiBaseView(object):
|
||||
|
||||
default_template = ViewPageTemplateFile('default.pt')
|
||||
|
||||
|
||||
class WikiManagerView(WikiBaseView):
|
||||
|
||||
content_renderer = 'manager'
|
||||
|
||||
def update(self):
|
||||
form = self.request.form
|
||||
return True
|
||||
|
||||
def listWikis(self):
|
||||
return self.context.listWikis()
|
||||
|
||||
|
||||
class WikiView(WikiBaseView):
|
||||
|
||||
content_renderer = 'wiki'
|
||||
|
||||
def update(self):
|
||||
return True
|
||||
|
||||
def listPages(self):
|
||||
return self.context.listPages()
|
||||
|
||||
|
||||
class CreatePage(object):
|
||||
|
||||
def update(self):
|
||||
form = self.request.form
|
||||
name = form.get('name')
|
||||
title = name
|
||||
page = self.context.createPage(name, title)
|
||||
# record in LinkManager
|
||||
manager = self.context.getManager()
|
||||
lmName = self.context.getConfig('linkManager')
|
||||
lm = manager.getPlugin(ILinkManager, lmName)
|
||||
for link in lm.query(name=name):
|
||||
if link.target is None:
|
||||
link.update(target=page)
|
||||
self.request.response.redirect('%s?mode=edit' %
|
||||
absoluteURL(page, self.request))
|
||||
return False
|
||||
|
||||
|
||||
class WikiPageView(WikiBaseView):
|
||||
|
||||
content_renderer = 'wikipage'
|
||||
|
||||
def update(self):
|
||||
form = self.request.form
|
||||
if form.get('form_action') == 'edit':
|
||||
title = form.get('title')
|
||||
if title and title != self.context.title:
|
||||
self.context.title = title
|
||||
text = form.get('text')
|
||||
if text and text != self.context.text:
|
||||
self.context.text = text
|
||||
# TODO: notify(ObjectModifiedEvent())
|
||||
#self.request.response.redirect(absoluteURL(self.context, self.request))
|
||||
#return False
|
||||
return True
|
||||
|
||||
def render(self):
|
||||
return self.context.render(self.request)
|
Loading…
Add table
Reference in a new issue