work in progress: micro articles

This commit is contained in:
Helmut Merz 2011-11-02 13:38:50 +01:00
parent 73111402db
commit 6f8c9bda6a
9 changed files with 283 additions and 0 deletions

View file

@ -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
=============

View file

@ -0,0 +1,4 @@
"""
$Id$
"""

73
compound/microart/base.py Normal file
View file

@ -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)

52
compound/microart/browser.py Executable file
View file

@ -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)

View file

@ -0,0 +1,29 @@
<configure
xmlns:zope="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope">
<zope:adapter
factory="loops.compound.microart.base.MicroArt"
provides="loops.compound.microart.interfaces.IMicroArt"
trusted="True" />
<zope:class class="loops.compound.microart.base.MicroArt">
<require permission="zope.View"
interface="loops.compound.microart.interfaces.IMicroArt" />
<require permission="zope.View"
attributes="context" />
<require permission="zope.ManageContent"
set_schema="loops.compound.microart.interfaces.IMicroArt" />
</zope:class>
<!-- views -->
<zope:adapter
name="microart.html"
for="loops.interfaces.IConcept
zope.publisher.interfaces.browser.IBrowserRequest"
provides="zope.interface.Interface"
factory="loops.compound.microart.browser.MicroArtView"
permission="zope.View" />
</configure>

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1,17 @@
<!-- ZPT macros for loops.compound.microart views -->
<div metal:define-macro="microart"
tal:define="data item/data"
class="microart">
<metal:block use-macro="view/concept_macros/concepttitle_only" />
<div class="description"
tal:define="description description|item/renderedDescription"
tal:condition="description">
<span tal:content="structure description">Description</span>
</div>
<div class="text"
tal:content="structure item/render">Here comes the text...</div>
<metal:resources use-macro="view/concept_macros/conceptchildren" />
<metal:resources use-macro="view/concept_macros/conceptresources" />
<metal:block use-macro="view/comment_macros/comments" />
</div>

View file

@ -473,6 +473,7 @@
<include package=".browser" />
<include package=".classifier" />
<include package=".compound.blog" />
<include package=".compound.microart" />
<include package=".config" />
<include package=".constraint" />
<include package=".expert" />