diff --git a/browser/lobo/configure.zcml b/browser/lobo/configure.zcml index 5bf7ea0..f8a145c 100644 --- a/browser/lobo/configure.zcml +++ b/browser/lobo/configure.zcml @@ -17,7 +17,7 @@ >> from zope import component >>> from zope.traversing.api import getName @@ -349,6 +347,17 @@ Micro Articles u'Systemic KM talks about organizational knowledge.' +Books, Sections, and Pages +========================== + + >>> import os + >>> from loops.setup import importData + >>> importPath = os.path.join(os.path.dirname(__file__), 'book') + >>> importData(loopsRoot, importPath, 'loops_book_de.dmp') + + >>> from loops.compound.book.browser import PageLayout + + Fin de partie ============= diff --git a/compound/base.py b/compound/base.py index 47bd907..8aec311 100644 --- a/compound/base.py +++ b/compound/base.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2008 Helmut Merz helmutm@cy55.de +# 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 @@ -18,8 +18,6 @@ """ Compound objects like articles, blog posts, storyboard items, ... - -$Id$ """ from zope.cachedescriptors.property import Lazy @@ -27,35 +25,40 @@ from zope.interface import implements from zope.traversing.api import getName from loops.common import AdapterBase -from loops.compound.interfaces import ICompound, compoundPredicateName +from loops.compound.interfaces import ICompound, compoundPredicateNames class Compound(AdapterBase): implements(ICompound) + compoundPredicateNames = compoundPredicateNames + @Lazy - def compoundPredicate(self): - return self.context.getConceptManager()[compoundPredicateName] + def compoundPredicates(self): + return [self.context.getConceptManager()[n] + for n in self.compoundPredicateNames] def getParts(self): if self.context.__parent__ is None: return [] - return self.context.getResources([self.partOf]) + return self.context.getResources(self.compoundPredicates) def add(self, obj, position=None): if position is None: order = self.getMaxOrder() + 1 else: order = self.getOrderForPosition(position) - self.context.assignResource(obj, self.partOf, order=order) + self.context.assignResource(obj, self.partOf, + order=order) def remove(self, obj, position=None): if position is None: - self.context.deassignResource(obj, [self.partOf]) + self.context.deassignResource(obj, self.compoundPredicates) else: rel = self.getPartRelations()[position] - self.context.deassignResource(obj, [self.partOf], order=rel.order) + self.context.deassignResource(obj, self.compoundPredicates, + order=rel.order) def reorder(self, parts): existing = list(self.getPartRelations()) @@ -77,7 +80,7 @@ class Compound(AdapterBase): # helper methods and properties def getPartRelations(self): - return self.context.getResourceRelations([self.partOf]) + return self.context.getResourceRelations(self.compoundPredicates) def getMaxOrder(self): rels = self. getPartRelations() @@ -117,5 +120,5 @@ class Compound(AdapterBase): @Lazy def partOf(self): - return self.conceptManager[compoundPredicateName] + return self.compoundPredicates[0] diff --git a/compound/book/__init__.py b/compound/book/__init__.py new file mode 100644 index 0000000..8c1a40c --- /dev/null +++ b/compound/book/__init__.py @@ -0,0 +1,2 @@ +# __init__.py +# Package: loops.compound.book diff --git a/compound/book/base.py b/compound/book/base.py new file mode 100644 index 0000000..80579fe --- /dev/null +++ b/compound/book/base.py @@ -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 diff --git a/compound/book/browser.py b/compound/book/browser.py new file mode 100644 index 0000000..584e478 --- /dev/null +++ b/compound/book/browser.py @@ -0,0 +1,92 @@ +# +# 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', 'quote', 'maintext', + 'story', 'usecase'] + 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' + + +class KeyQuestions(PagePart, standard.BasePart): + + partName = 'keyquestions' + + +class Story(PagePart, standard.BasePart): + + partName = 'story' + + +class UseCase(PagePart, standard.BasePart): + + partName = 'usecase' + + +class Quote(PagePart, standard.BasePart): + + partName = 'quote' + gridPattern = ['span-2 last'] diff --git a/compound/book/configure.zcml b/compound/book/configure.zcml new file mode 100644 index 0000000..f1837cd --- /dev/null +++ b/compound/book/configure.zcml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/compound/book/interfaces.py b/compound/book/interfaces.py new file mode 100644 index 0000000..3dd1e43 --- /dev/null +++ b/compound/book/interfaces.py @@ -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 diff --git a/compound/book/loops_book_de.dmp b/compound/book/loops_book_de.dmp index db58c68..886aa88 100644 --- a/compound/book/loops_book_de.dmp +++ b/compound/book/loops_book_de.dmp @@ -1,16 +1,31 @@ +type(u'documenttype', u'Dokumentenart', options=u'qualifier:assign', + viewName=u'') + +# book types type(u'book', u'Buch', viewName=u'', typeInterface=u'', options=u'action.portlet:create_subtype,edit_concept') -type(u'page', u'Seite', viewName=u'', typeInterface=u'', +type(u'page', u'Seite', viewName=u'page_layout', + typeInterface=u'loops.compound.book.interfaces.IPage', options=u'action.portlet:edit_concept') type(u'section', u'Kapitel', viewName=u'', typeInterface=u'', options=u'action.portlet:create_subtype,edit_concept') -concept(u'ispartof', u'is Part of', u'predicate', options=u'', predicateInterface=u'') -concept(u'issubtype', u'is Subtype', u'predicate', options=u'', predicateInterface=u'') +concept(u'system', u'System', u'domain') + +# predicates +concept(u'ispartof', u'is Part of', u'predicate', options=u'', + predicateInterface=u'') +concept(u'issubtype', u'is Subtype', u'predicate', options=u'hide_children', + predicateInterface='loops.interfaces.IIsSubtype') + +# document types +concept(u'keyquestions', u'Leitfragen', u'documenttype') concept(u'maintext', u'Haupttext', u'documenttype') concept(u'quote', u'Zitat', u'documenttype') +concept(u'story', u'Geschichte', u'documenttype') +concept(u'usecase', u'Fallbeispiel', u'documenttype') -child(u'book', u'section', u'issubtype') -child(u'section', u'section', u'issubtype') -child(u'section', u'page', u'issubtype') -child(u'system', u'personal_info', u'standard') +# book structure +child(u'book', u'section', u'issubtype', usePredicate=u'ispartof') +child(u'section', u'section', u'issubtype', usePredicate=u'ispartof') +child(u'section', u'page', u'issubtype', usePredicate=u'ispartof') diff --git a/compound/book/view_macros.pt b/compound/book/view_macros.pt new file mode 100644 index 0000000..e330154 --- /dev/null +++ b/compound/book/view_macros.pt @@ -0,0 +1,21 @@ + + + + +
+ +
+
+ + + + +
+

+ +

+
+
+ + + diff --git a/compound/interfaces.py b/compound/interfaces.py index 4027d1e..0a3376b 100644 --- a/compound/interfaces.py +++ b/compound/interfaces.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2008 Helmut Merz helmutm@cy55.de +# 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 @@ -18,8 +18,6 @@ """ Compound objects like articles, blog posts, storyboard items, ... - -$Id$ """ #TODO: move generic stuff to cybertools.composer @@ -31,7 +29,7 @@ from loops.interfaces import IConceptSchema from loops.util import _ -compoundPredicateName = 'ispartof' +compoundPredicateNames = ['ispartof'] class ICompound(IConceptSchema): diff --git a/compound/tests.py b/compound/tests.py index 644d326..f0f28ba 100755 --- a/compound/tests.py +++ b/compound/tests.py @@ -1,4 +1,5 @@ -# $Id$ +# tests.py +# Package loops.compound import unittest, doctest from zope.testing.doctestunit import DocFileSuite diff --git a/configure.zcml b/configure.zcml index 1692294..013d4ce 100644 --- a/configure.zcml +++ b/configure.zcml @@ -480,6 +480,7 @@ + @@ -492,7 +493,6 @@ -