work in progress: page layout for 'book' compound objects
This commit is contained in:
parent
dbc720c54a
commit
6707ab59ff
6 changed files with 223 additions and 0 deletions
2
compound/book/__init__.py
Normal file
2
compound/book/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
# __init__.py
|
||||
# Package: loops.compound.book
|
52
compound/book/base.py
Normal file
52
compound/book/base.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# Copyright (c) 2012 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
|
||||
#
|
||||
|
||||
"""
|
||||
Implementation of book and book components
|
||||
"""
|
||||
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.interface import implements
|
||||
from zope.traversing.api import getName
|
||||
|
||||
from loops.compound.base import Compound
|
||||
from loops.compound.book.interfaces import IPage
|
||||
from loops.type import TypeInterfaceSourceList
|
||||
|
||||
|
||||
TypeInterfaceSourceList.typeInterfaces += (IPage,)
|
||||
|
||||
|
||||
class Page(Compound):
|
||||
|
||||
implements(IPage)
|
||||
|
||||
compoundPredicateNames = ['ispartof', 'standard']
|
||||
|
||||
@Lazy
|
||||
def documentType(self):
|
||||
return self.context.getConceptManager()['documenttype']
|
||||
|
||||
def getParts(self):
|
||||
result = {}
|
||||
for r in super(Page, self).getParts():
|
||||
for parent in r.getParents():
|
||||
if parent.conceptType == self.documentType:
|
||||
item = result.setdefault(getName(parent), [])
|
||||
item.append(r)
|
||||
return result
|
71
compound/book/browser.py
Normal file
71
compound/book/browser.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
#
|
||||
# Copyright (c) 2012 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
|
||||
#
|
||||
|
||||
"""
|
||||
View class(es) book/section/page structures.
|
||||
"""
|
||||
|
||||
from cgi import parse_qs
|
||||
from zope import interface, component
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
|
||||
from cybertools.typology.interfaces import IType
|
||||
from loops.browser.lobo import standard
|
||||
from loops.browser.concept import ConceptRelationView as BaseConceptRelationView
|
||||
from loops.browser.resource import ResourceView as BaseResourceView
|
||||
from loops.common import adapted, baseObject
|
||||
|
||||
|
||||
standard_template = standard.standard_template
|
||||
book_template = ViewPageTemplateFile('view_macros.pt')
|
||||
|
||||
|
||||
class PageLayout(standard.Layout):
|
||||
|
||||
def getParts(self):
|
||||
parts = ['headline', 'keyquestions', 'maintext',
|
||||
'story', 'usecase', 'quote']
|
||||
return self.getPartViews(parts)
|
||||
|
||||
|
||||
class PagePart(object):
|
||||
|
||||
template = book_template
|
||||
templateName = 'compound.book'
|
||||
macroName = 'text'
|
||||
partName = None # define in subclass
|
||||
gridPattern = ['span-4']
|
||||
|
||||
def getResources(self):
|
||||
result = []
|
||||
res = self.adapted.getParts().get(self.partName) or []
|
||||
for idx, r in enumerate(res):
|
||||
result.append(standard.ResourceView(
|
||||
r, self.request, parent=self, idx=idx))
|
||||
return result
|
||||
|
||||
|
||||
class Headline(PagePart, standard.Header2):
|
||||
|
||||
macroName = 'headline'
|
||||
|
||||
|
||||
class MainText(PagePart, standard.BasePart):
|
||||
|
||||
partName = 'maintext'
|
46
compound/book/configure.zcml
Normal file
46
compound/book/configure.zcml
Normal file
|
@ -0,0 +1,46 @@
|
|||
<configure
|
||||
xmlns:zope="http://namespaces.zope.org/zope"
|
||||
xmlns:browser="http://namespaces.zope.org/browser"
|
||||
i18n_domain="loops">
|
||||
|
||||
<!-- type adapters -->
|
||||
|
||||
<zope:adapter factory="loops.compound.book.base.Page"
|
||||
provides="loops.compound.book.interfaces.IPage"
|
||||
trusted="True" />
|
||||
<zope:class class="loops.compound.book.base.Page">
|
||||
<require permission="zope.View"
|
||||
interface="loops.compound.book.interfaces.IPage" />
|
||||
<require permission="zope.ManageContent"
|
||||
set_schema="loops.compound.book.interfaces.IPage" />
|
||||
</zope:class>
|
||||
|
||||
<!-- Views -->
|
||||
|
||||
<zope:adapter
|
||||
name="page_layout"
|
||||
for="loops.interfaces.IConcept
|
||||
loops.browser.skin.Lobo"
|
||||
provides="zope.interface.Interface"
|
||||
factory="loops.compound.book.browser.PageLayout"
|
||||
permission="zope.View" />
|
||||
|
||||
<!-- parts -->
|
||||
|
||||
<zope:adapter
|
||||
name="lobo_headline"
|
||||
for="loops.compound.book.interfaces.IPage
|
||||
loops.browser.skin.Lobo"
|
||||
provides="zope.interface.Interface"
|
||||
factory="loops.compound.book.browser.Headline"
|
||||
permission="zope.View" />
|
||||
|
||||
<zope:adapter
|
||||
name="lobo_maintext"
|
||||
for="loops.compound.book.interfaces.IPage
|
||||
loops.browser.skin.Lobo"
|
||||
provides="zope.interface.Interface"
|
||||
factory="loops.compound.book.browser.MainText"
|
||||
permission="zope.View" />
|
||||
|
||||
</configure>
|
32
compound/book/interfaces.py
Normal file
32
compound/book/interfaces.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
#
|
||||
# Copyright (c) 2012 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
|
||||
#
|
||||
|
||||
"""
|
||||
Books, sections, pages...
|
||||
"""
|
||||
|
||||
from zope.interface import Interface, Attribute
|
||||
from zope import interface, component, schema
|
||||
|
||||
from loops.compound.interfaces import ICompound
|
||||
from loops.util import _
|
||||
|
||||
|
||||
class IPage(ICompound):
|
||||
|
||||
pass
|
20
compound/book/view_macros.pt
Normal file
20
compound/book/view_macros.pt
Normal file
|
@ -0,0 +1,20 @@
|
|||
<html i18n:domain="loops">
|
||||
|
||||
|
||||
<metal:part define-macro="headline">
|
||||
<div tal:define="cell part/getView">
|
||||
<metal:headline use-macro="item/macros/headline" />
|
||||
</div>
|
||||
</metal:part>
|
||||
|
||||
|
||||
<metal:part define-macro="text">
|
||||
<tal:cell repeat="cell part/getResources">
|
||||
<div tal:attributes="class cell/cssClass">
|
||||
<span tal:content="structure cell/view/render" />
|
||||
</div>
|
||||
</tal:cell>
|
||||
</metal:part>
|
||||
|
||||
|
||||
</html>
|
Loading…
Add table
Reference in a new issue