set up basic/generic view stuff in in 'view' package; move z2-independent stuff to 'view' package
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3790 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
17c35c9c61
commit
44fb2e3142
17 changed files with 363 additions and 74 deletions
13
view/browser/generic.pt
Normal file
13
view/browser/generic.pt
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<tal:show condition="view/update">
|
||||||
|
<html metal:use-macro="view/mainMacro">
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div metal:fill-slot="content">
|
||||||
|
<metal:content use-macro="view/contentMacro" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
</tal:show>
|
16
view/browser/liquid/__init__.py
Normal file
16
view/browser/liquid/__init__.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
"""
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
#from zope.publisher.interfaces.browser import IBrowserRequest
|
||||||
|
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
|
||||||
|
from zope.app.rotterdam import Rotterdam
|
||||||
|
|
||||||
|
|
||||||
|
#class liquid(IBrowserRequest):
|
||||||
|
# """The `liquid` layer."""
|
||||||
|
|
||||||
|
|
||||||
|
class Liquid(Rotterdam):
|
||||||
|
""" The Liquid skin """
|
||||||
|
|
32
view/browser/liquid/base.css
Normal file
32
view/browser/liquid/base.css
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
based on http://www.tjkdesign.com/articles/liquid/4.asp
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
body {
|
||||||
|
min-width:640px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif;
|
||||||
|
font-size: 13px;
|
||||||
|
background-color: white;
|
||||||
|
color: #000040;
|
||||||
|
}
|
||||||
|
|
||||||
|
#global,#menu,#sub-section,#footer {
|
||||||
|
overflow: hidden;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
#global,#footer {width:100%}
|
||||||
|
#menu,#content,#sub-section {float:left}
|
||||||
|
#menu {width:20%}
|
||||||
|
#content {width:62%}
|
||||||
|
#sub-section {width:17%}
|
||||||
|
#footer {clear:left; float:left}
|
57
view/browser/liquid/body.pt
Normal file
57
view/browser/liquid/body.pt
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<tal:block i18n:domain="loops">
|
||||||
|
<div class="body"
|
||||||
|
metal:define-macro="body"
|
||||||
|
tal:define="controller nocall:view/controller;
|
||||||
|
resourceBase controller/resourceBase;">
|
||||||
|
|
||||||
|
<div id="global" metal:define-macro="global">
|
||||||
|
<div class="top" metal:define-slot="top">
|
||||||
|
<a href="#" name="top" metal:define-slot="logo"
|
||||||
|
tal:attributes="href string:${request/URL/1}"><img class="logo"
|
||||||
|
src="logo.gif" border="0" alt="Home"
|
||||||
|
tal:attributes="src string:${resourceBase}logo.gif" /></a>
|
||||||
|
<div metal:define-slot="top-actions">
|
||||||
|
<tal:action repeat="macro controller/macros/top_actions">
|
||||||
|
<metal:action use-macro="macro" />
|
||||||
|
</tal:action>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="menu" metal:define-macro="menu">
|
||||||
|
<tal:portlet repeat="macro controller/macros/portlet_left">
|
||||||
|
<metal:portlet use-macro="macro" />
|
||||||
|
</tal:portlet>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="content" metal:define-macro="content">
|
||||||
|
<div metal:define-slot="actions"></div>
|
||||||
|
<div metal:define-slot="message"></div>
|
||||||
|
<metal:content define-slot="content">
|
||||||
|
<tal:content define="item nocall:view/item;
|
||||||
|
level level|python: 1;
|
||||||
|
macro item/macro;"
|
||||||
|
condition="macro">
|
||||||
|
<metal:block use-macro="macro" />
|
||||||
|
</tal:content>
|
||||||
|
</metal:content>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="sub-section"
|
||||||
|
xtal:condition="view/isAuthenticated">
|
||||||
|
<tal:portlet repeat="macro controller/macros/portlet_right">
|
||||||
|
<metal:portlet use-macro="macro" />
|
||||||
|
</tal:portlet>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="footer" class="footer" metal:define-macro="footer">
|
||||||
|
<metal:footer define-slot="footer">
|
||||||
|
Powered by <b><a href="http://www.python.org">Python</a></b> ·
|
||||||
|
<b><a href="http://wiki.zope.org/zope3">Zope 3</a></b> ·
|
||||||
|
<b><a href="http://loops.cy55.de">
|
||||||
|
loops</a></b>.
|
||||||
|
</metal:footer>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</tal:block>
|
9
view/browser/liquid/configure.zcml
Normal file
9
view/browser/liquid/configure.zcml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<!-- $Id$ -->
|
||||||
|
|
||||||
|
<configure
|
||||||
|
xmlns:zope="http://namespaces.zope.org/zope"
|
||||||
|
xmlns:browser="http://namespaces.zope.org/browser">
|
||||||
|
|
||||||
|
<browser:resource name="base.css" file="base.css" />
|
||||||
|
|
||||||
|
</configure>
|
7
view/browser/liquid/custom.css
Normal file
7
view/browser/liquid/custom.css
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
/*
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
Copy this to your custom skin directory and add custom settings.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
22
view/browser/liquid/presentation.css
Normal file
22
view/browser/liquid/presentation.css
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
.body {
|
||||||
|
margin: 4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top, #header, #menu, #sub-section, #footer, .object-actions, .button {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
width: 100%;
|
||||||
|
color: #000077;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2, h3, h4, h5 {
|
||||||
|
color: #005599;
|
||||||
|
}
|
||||||
|
|
17
view/browser/liquid/print.css
Normal file
17
view/browser/liquid/print.css
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top, #header, #menu, #sub-section, #footer, .object-actions, .button {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
width: 100%;
|
||||||
|
color: Black;
|
||||||
|
}
|
61
view/browser/liquid/view_macros.pt
Normal file
61
view/browser/liquid/view_macros.pt
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<metal:main define-macro="main"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title tal:content="view/head_title|context/title|default">
|
||||||
|
Powered by Zope 3
|
||||||
|
</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<link rel="stylesheet" type="text/css"
|
||||||
|
tal:attributes="href view/resources/base.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="body">
|
||||||
|
<div id="global">
|
||||||
|
<div class="top" metal:define-slot="top">
|
||||||
|
<a href="#" name="top" metal:define-slot="logo"
|
||||||
|
tal:attributes="href view/homeURL"><img class="logo"
|
||||||
|
src="logo.gif" border="0" alt="Home"
|
||||||
|
tal:attributes="src string:${view/resource_prefix}logo.gif" /></a>
|
||||||
|
<div metal:define-slot="top-actions">
|
||||||
|
<tal:action repeat="macro view/actions/top">
|
||||||
|
<metal:action use-macro="macro" />
|
||||||
|
</tal:action>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="menu">
|
||||||
|
<tal:portlet repeat="macro view/actions/portlet_left">
|
||||||
|
<metal:portlet use-macro="macro" />
|
||||||
|
</tal:portlet>
|
||||||
|
</div>
|
||||||
|
<div id="content">
|
||||||
|
<div metal:define-slot="actions"></div>
|
||||||
|
<div metal:define-slot="message"></div>
|
||||||
|
<div>
|
||||||
|
<metal:content define-slot="content">Content</metal:content>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="sub-section">
|
||||||
|
<tal:portlet repeat="macro view/actions/portlet_right">
|
||||||
|
<metal:portlet use-macro="macro" />
|
||||||
|
</tal:portlet>
|
||||||
|
</div>
|
||||||
|
<div id="footer" class="footer">
|
||||||
|
<metal:footer define-slot="footer">
|
||||||
|
Powered by <b><a href="http://www.python.org">Python</a></b> ·
|
||||||
|
<b><a href="http://wiki.zope.org/zope3">Zope</a></b>.
|
||||||
|
</metal:footer>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
</metal:main>
|
||||||
|
|
||||||
|
|
||||||
|
<metal:content define-macro="content">
|
||||||
|
Dummy Content
|
||||||
|
</metal:content>
|
||||||
|
|
91
view/browser/view.py
Normal file
91
view/browser/view.py
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Base classes for views.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||||
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
from zope import component
|
||||||
|
|
||||||
|
|
||||||
|
generic_page = ViewPageTemplateFile('generic.pt')
|
||||||
|
view_macros = ViewPageTemplateFile(os.path.join('liquid', 'view_macros.pt'))
|
||||||
|
|
||||||
|
|
||||||
|
class BaseView(object):
|
||||||
|
|
||||||
|
index = generic_page
|
||||||
|
default_template = view_macros # specify in subclass
|
||||||
|
resource_prefix = '/@@/'
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
return self.index(self)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def mainMacro(self):
|
||||||
|
return view_macros.macros['main']
|
||||||
|
|
||||||
|
#@rcache
|
||||||
|
def defaultMacros(self):
|
||||||
|
return self.default_template.macros
|
||||||
|
|
||||||
|
def contentMacro(self):
|
||||||
|
return self.defaultMacros()[getattr(self, 'content_renderer', 'content')]
|
||||||
|
|
||||||
|
#@rcache
|
||||||
|
def homeURL(self):
|
||||||
|
return '/'
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def resources(self):
|
||||||
|
return {'base.css': '%sbase.css' % self.resource_prefix}
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def actions(self):
|
||||||
|
return dict(top=[], portlet_left=[], portlet_right=[])
|
||||||
|
|
||||||
|
|
||||||
|
# generic views for use with generic persistent objects with type-based adapters
|
||||||
|
# (not used at the moment - obsolete?)
|
||||||
|
|
||||||
|
class GenericView(BaseView):
|
||||||
|
|
||||||
|
name = 'index_html'
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def object(self):
|
||||||
|
return self.context.typeInterface(self.context)
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def objectView(self):
|
||||||
|
return component.getMultiAdapter((self.object, self.request), name=self.name)
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
return self.objectView()
|
||||||
|
|
||||||
|
|
||||||
|
class GenericAddForm(GenericView):
|
||||||
|
|
||||||
|
name = 'create.html'
|
|
@ -59,4 +59,9 @@
|
||||||
</metal:content>
|
</metal:content>
|
||||||
|
|
||||||
|
|
||||||
|
<metal:portlet define-macro="navigation">
|
||||||
|
<p>Menu</p>
|
||||||
|
</metal:portlet>
|
||||||
|
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -34,6 +34,12 @@ class WikiBaseView(object):
|
||||||
|
|
||||||
default_template = ViewPageTemplateFile('default.pt')
|
default_template = ViewPageTemplateFile('default.pt')
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def actions(self):
|
||||||
|
return dict(top=[],
|
||||||
|
portlet_left=[self.default_template.macros['navigation']],
|
||||||
|
portlet_right=[])
|
||||||
|
|
||||||
|
|
||||||
class WikiManagerView(WikiBaseView):
|
class WikiManagerView(WikiBaseView):
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,13 @@ Supporting the Zope2 Environment for Zope3/ZTK-based Applications
|
||||||
>>> from zope.publisher.browser import TestRequest
|
>>> from zope.publisher.browser import TestRequest
|
||||||
|
|
||||||
|
|
||||||
|
Views
|
||||||
|
=====
|
||||||
|
|
||||||
|
>>> from zope.traversing.adapters import DefaultTraversable
|
||||||
|
>>> component.provideAdapter(DefaultTraversable, (object,))
|
||||||
|
|
||||||
|
>>> from cybertools.z2.browser.view import BaseView
|
||||||
|
>>> view = BaseView(object(), TestRequest())
|
||||||
|
|
||||||
|
>>> html = view()
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<tal:show condition="view/update">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"
|
|
||||||
metal:use-macro="view/getMainMacro">
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div metal:fill-slot="content">
|
|
||||||
<metal:content use-macro="view/getContentMacro" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
</tal:show>
|
|
|
@ -22,51 +22,23 @@ Base classes for views.
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
|
||||||
from zope.cachedescriptors.property import Lazy
|
|
||||||
from zope import component
|
|
||||||
from Products.Five import BrowserView
|
from Products.Five import BrowserView
|
||||||
#from Products.Five.browser.pagetemplatefile import PageTemplateFile
|
|
||||||
|
from cybertools.view.browser.view import BaseView, GenericView
|
||||||
|
|
||||||
|
|
||||||
generic_page = ViewPageTemplateFile('generic.pt')
|
class BaseView(BrowserView, BaseView):
|
||||||
view_macros = ViewPageTemplateFile('view_macros.pt')
|
|
||||||
|
|
||||||
|
resource_prefix = '/++resource++'
|
||||||
class BaseView(BrowserView):
|
|
||||||
|
|
||||||
index = generic_page
|
|
||||||
default_template = None # specify in subclass
|
|
||||||
|
|
||||||
def __call__(self):
|
|
||||||
return self.index(self)
|
|
||||||
|
|
||||||
def getMainMacro(self):
|
|
||||||
return view_macros.macros['main']
|
|
||||||
|
|
||||||
def getDefaultTemplate(self):
|
|
||||||
return self.default_template
|
|
||||||
|
|
||||||
def getContentMacro(self):
|
|
||||||
return self.getDefaultTemplate().macros[self.content_renderer]
|
|
||||||
|
|
||||||
|
|
||||||
# generic views for use with generic persistent objects with type-based adapters
|
# generic views for use with generic persistent objects with type-based adapters
|
||||||
|
# (not used at the moment - obsolete?)
|
||||||
|
|
||||||
class GenericView(BaseView):
|
class GenericView(BaseView, GenericView):
|
||||||
|
|
||||||
name = 'index_html'
|
|
||||||
|
|
||||||
@Lazy
|
|
||||||
def object(self):
|
|
||||||
return self.context.typeInterface(self.context)
|
|
||||||
|
|
||||||
@Lazy
|
|
||||||
def objectView(self):
|
|
||||||
return component.getMultiAdapter((self.object, self.request), name=self.name)
|
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
return self.objectView()
|
return GenericView.__call__(self)
|
||||||
|
|
||||||
|
|
||||||
class GenericAddForm(GenericView):
|
class GenericAddForm(GenericView):
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
<metal:main define-macro="main">
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<h1>Top Bar</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<metal:content define-slot="content">Content</metal:content>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<p>Footer</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
</metal:main>
|
|
11
z2/tests.py
11
z2/tests.py
|
@ -9,15 +9,24 @@ $Id$
|
||||||
import unittest, doctest
|
import unittest, doctest
|
||||||
from zope.testing.doctestunit import DocFileSuite
|
from zope.testing.doctestunit import DocFileSuite
|
||||||
|
|
||||||
|
try:
|
||||||
|
from Products.Five import BrowserView
|
||||||
|
ignore = False
|
||||||
|
except ImportError:
|
||||||
|
BrowserView = None
|
||||||
|
ignore = True
|
||||||
|
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
"Basic tests for the wiki package."
|
"Basic tests for the z2 package."
|
||||||
|
|
||||||
def testBasicStuff(self):
|
def testBasicStuff(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
|
if ignore:
|
||||||
|
return unittest.TestSuite(())
|
||||||
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||||
return unittest.TestSuite((
|
return unittest.TestSuite((
|
||||||
unittest.makeSuite(Test),
|
unittest.makeSuite(Test),
|
||||||
|
|
Loading…
Add table
Reference in a new issue