From 6f8c9bda6ace5315a03e62d2f5bc367c69cf817a Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Wed, 2 Nov 2011 13:38:50 +0100 Subject: [PATCH] work in progress: micro articles --- compound/README.txt | 11 +++++ compound/microart/__init__.py | 4 ++ compound/microart/base.py | 73 ++++++++++++++++++++++++++++++++ compound/microart/browser.py | 52 +++++++++++++++++++++++ compound/microart/configure.zcml | 29 +++++++++++++ compound/microart/interfaces.py | 59 ++++++++++++++++++++++++++ compound/microart/schema.py | 37 ++++++++++++++++ compound/microart/view_macros.pt | 17 ++++++++ configure.zcml | 1 + 9 files changed, 283 insertions(+) create mode 100644 compound/microart/__init__.py create mode 100644 compound/microart/base.py create mode 100755 compound/microart/browser.py create mode 100644 compound/microart/configure.zcml create mode 100644 compound/microart/interfaces.py create mode 100644 compound/microart/schema.py create mode 100755 compound/microart/view_macros.pt diff --git a/compound/README.txt b/compound/README.txt index 4d0a049..06b6e2e 100644 --- a/compound/README.txt +++ b/compound/README.txt @@ -316,6 +316,17 @@ When we clear the `private` flag the post becomes visible again. True +Micro Articles +============== + + >>> from loops.compound.microart.base import MicroArt + >>> from loops.compound.microart.interfaces import IMicroArt + >>> component.provideAdapter(BlogPost, provides=IMicroArt) + + >>> tMicroArt = addAndConfigureObject(concepts, Concept, 'microart', + ... title=u'MicroArt', conceptType=tType) + + Fin de partie ============= diff --git a/compound/microart/__init__.py b/compound/microart/__init__.py new file mode 100644 index 0000000..4bc90fb --- /dev/null +++ b/compound/microart/__init__.py @@ -0,0 +1,4 @@ +""" +$Id$ +""" + diff --git a/compound/microart/base.py b/compound/microart/base.py new file mode 100644 index 0000000..3b568be --- /dev/null +++ b/compound/microart/base.py @@ -0,0 +1,73 @@ +# +# Copyright (c) 2011 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 +# + +""" +Micro articles (MicroArt). +""" + +from zope.cachedescriptors.property import Lazy +from zope.dublincore.interfaces import IZopeDublinCore +from zope.interface import implements +from zope.event import notify +from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent +from zope import schema +from zope.traversing.api import getName + +from loops.common import adapted +from loops.compound.base import Compound +from loops.compound.microart.interfaces import IMicroArt +from loops.resource import Resource +from loops.setup import addAndConfigureObject +from loops.type import TypeInterfaceSourceList + + +TypeInterfaceSourceList.typeInterfaces += (IMicroArt,) + + +class MicroArt(Compound): + + implements(IMicroArt) + + _adapterAttributes = Compound._adapterAttributes + ('text',) + _noexportAttributes = ('text',) + _textIndexAttributes = ('text',) + + defaultTextContentType = 'text/restructured' + textContentType = defaultTextContentType + + def getText(self): + res = self.getParts() + if len(res) > 0: + return adapted(res[0]).data + return u'' + def setText(self, value): + res = self.getParts() + if len(res) > 0: + res = adapted(res[0]) + else: + tTextDocument = self.conceptManager['textdocument'] + name = getName(self.context) + '_text' + res = addAndConfigureObject(self.resourceManager, Resource, name, + title=self.title, contentType=self.defaultTextContentType, + resourceType=tTextDocument) + #notify(ObjectCreatedEvent(res)) + self.add(res, position=0) + res = adapted(res) + res.data = value + notify(ObjectModifiedEvent(res.context)) + text = property(getText, setText) diff --git a/compound/microart/browser.py b/compound/microart/browser.py new file mode 100755 index 0000000..f35c83a --- /dev/null +++ b/compound/microart/browser.py @@ -0,0 +1,52 @@ +# +# Copyright (c) 2011 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 classes for micro articles (MicroArt). +""" + + +import itertools +from zope import component +from zope.app.pagetemplate import ViewPageTemplateFile +from zope.cachedescriptors.property import Lazy + +from loops.browser.concept import ConceptView, ConceptRelationView +from loops.common import adapted +from loops import util +from loops.util import _ + + +view_macros = ViewPageTemplateFile('view_macros.pt') + + +class MicroArtView(ConceptView): + + @Lazy + def macro(self): + return view_macros.macros['microart'] + + def render(self): + return self.renderText(self.data['text'], self.adapted.textContentType) + + def resources(self): + stdPred = self.loopsRoot.getConceptManager().getDefaultPredicate() + rels = self.context.getResourceRelations([stdPred]) + for r in rels: + yield self.childViewFactory(r, self.request, contextIsSecond=True) + diff --git a/compound/microart/configure.zcml b/compound/microart/configure.zcml new file mode 100644 index 0000000..36e46c9 --- /dev/null +++ b/compound/microart/configure.zcml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/compound/microart/interfaces.py b/compound/microart/interfaces.py new file mode 100644 index 0000000..9151803 --- /dev/null +++ b/compound/microart/interfaces.py @@ -0,0 +1,59 @@ +# +# Copyright (c) 2011 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 +# + +""" +Micro articles (MicroArt / MikroArtikel in German). +""" + +from zope.interface import Interface, Attribute +from zope import interface, component, schema + +from loops.compound.interfaces import ICompound +from loops.util import _ + + +class IMicroArt(ICompound): + """ A short article with a few elements, for collecting + relevant information in a knowledge management environment. + """ + + # title = Ueberschrift, Thema + + story = schema.Text( # Geschichte + title=_(u'Story'), + description=_(u'The story, i.e. the main text of your ' + u'micro article. Who did what? What happend?'), + required=True) + + insight = schema.Text( # Einsicht + title=_(u'Insight'), + description=_(u'What can we learn from the story? What ' + u'has gone wrong? What was good?'), + required=True) + + consequences = schema.Text( #(Schluss-) Folgerungen + title=_(u'Consequences'), + description=_(u'What we will do next time in a similar ' + u'situation?'), + required=True) + + followUps = schema.Text( #Anschlussfragen + title=_(u'Follow-up'), + description=_(u'Question for helping to solve or avoid ' + u'similar problems in the future.'), + required=False) diff --git a/compound/microart/schema.py b/compound/microart/schema.py new file mode 100644 index 0000000..b6d6dbf --- /dev/null +++ b/compound/microart/schema.py @@ -0,0 +1,37 @@ +# +# Copyright (c) 2011 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 +# + +""" +Specialized schema factories +""" + +from zope.component import adapts + +from cybertools.composer.schema.factory import SchemaFactory +from loops.compound.microart.interfaces import IMicroArt + + +class MicroArtSchemaFactory(SchemaFactory): + + adapts(IMicroArt) + + def __call__(self, interface, **kw): + schema = super(MicroArtSchemaFactory, self).__call__(interface, **kw) + schema.fields.text.height = 10 + return schema + diff --git a/compound/microart/view_macros.pt b/compound/microart/view_macros.pt new file mode 100755 index 0000000..ff15b1f --- /dev/null +++ b/compound/microart/view_macros.pt @@ -0,0 +1,17 @@ + + +
+ +
+ Description +
+
Here comes the text...
+ + + +
diff --git a/configure.zcml b/configure.zcml index 4400bed..a1522a5 100644 --- a/configure.zcml +++ b/configure.zcml @@ -473,6 +473,7 @@ +