diff --git a/browser/common.py b/browser/common.py index ae47666..88b1ade 100644 --- a/browser/common.py +++ b/browser/common.py @@ -240,6 +240,18 @@ class BaseView(GenericView): # versioning + @Lazy + def versionId(self): + context = self.context + versionable = IVersionable(context, None) + return versionable and versionable.versionId or '' + + @Lazy + def currentVersionId(self): + context = self.context + versionable = IVersionable(context, None) + return versionable and versionable.currentVersion.versionId or '' + @Lazy def versionInfo(self): context = self.context diff --git a/browser/concept.py b/browser/concept.py index b3e114f..982bce6 100644 --- a/browser/concept.py +++ b/browser/concept.py @@ -47,6 +47,7 @@ from loops.interfaces import IConcept from loops.concept import Concept, ConceptTypeSourceList, PredicateSourceList from loops.browser.common import EditForm, BaseView, LoopsTerms from loops import util +from loops.versioning.util import getVersion class ConceptEditForm(EditForm): @@ -276,6 +277,7 @@ class ConceptRelationView(BaseView): else: self.context = relation.first self.other = relation.second + self.context = getVersion(self.context, request) self.predicate = relation.predicate self.request = request diff --git a/browser/concept_macros.pt b/browser/concept_macros.pt index b238c4c..dfbf97b 100644 --- a/browser/concept_macros.pt +++ b/browser/concept_macros.pt @@ -87,6 +87,7 @@ Title Type + V Size Modification Date @@ -102,6 +103,9 @@ Type + + 1.1 + Type diff --git a/browser/node.py b/browser/node.py index 4dff1f5..5bd64ad 100644 --- a/browser/node.py +++ b/browser/node.py @@ -37,7 +37,6 @@ from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent from zope.lifecycleevent import Attributes from zope.formlib.form import Form, FormFields from zope.formlib.namedtemplate import NamedTemplate -from zope.app.pagetemplate import ViewPageTemplateFile from zope.proxy import removeAllProxies from zope.security import canAccess, canWrite from zope.security.proxy import removeSecurityProxy @@ -99,11 +98,12 @@ class NodeView(BaseView): @Lazy def item(self): + viewName = self.request.get('loops.viewName') or '' + # was there a .target... element in the URL? #target = self.virtualTargetObject # ignores page even for direktly assignd target target = self.request.annotations.get('loops.view', {}).get('target') - # was there a .target... element in the URL? if target is not None: - basicView = zapi.getMultiAdapter((target, self.request)) + basicView = zapi.getMultiAdapter((target, self.request), name=viewName) # xxx: obsolete when self.targetObject is virtual target: return basicView.view return self.page diff --git a/versioning/browser.py b/versioning/browser.py new file mode 100644 index 0000000..8d0bb3a --- /dev/null +++ b/versioning/browser.py @@ -0,0 +1,57 @@ +# +# Copyright (c) 2007 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 versioning. + +$Id$ +""" + +from zope import interface, component +from zope.app.pagetemplate import ViewPageTemplateFile +from zope.app.security.interfaces import IUnauthenticatedPrincipal +from zope.cachedescriptors.property import Lazy + +from loops.browser.common import BaseView +from loops.versioning.interfaces import IVersionable +from loops.versioning.util import getVersion + + +class ListVersions(BaseView): + + template = ViewPageTemplateFile('version_macros.pt') + + @Lazy + def macro(self): + return self.template.macros['versions'] + + def __init__(self, context, request): + super(ListVersions, self).__init__(context, request) + cont = self.controller + if (cont is not None and not IUnauthenticatedPrincipal.providedBy( + self.request.principal)): + cont.macros.register('portlet_right', 'versions', title='Versions', + subMacro=self.template.macros['portlet_versions'], + info=self) + + def versions(self): + versionable = IVersionable(self.context) + versions = versionable.versions + for v in sorted(versions): + yield BaseView(versions[v], self.request) + diff --git a/versioning/configure.zcml b/versioning/configure.zcml index 13a2ddd..0609914 100644 --- a/versioning/configure.zcml +++ b/versioning/configure.zcml @@ -16,4 +16,13 @@ set_schema="loops.versioning.interfaces.IVersionable" /> + + + + diff --git a/versioning/util.py b/versioning/util.py index 61aad46..c96bb79 100644 --- a/versioning/util.py +++ b/versioning/util.py @@ -36,17 +36,16 @@ def getVersion(obj, request): versionable = IVersionable(obj, None) if versionable is None: return obj - if not versionRequest: - # find and return a standard version - v = versionable.releasedVersion - if v is None: - v = versionable.currentVersion - return v - # we might have a versionId in the request - v = versionable.versions.get(versionRequest) - if v is not None: - return v - return obj + if versionRequest: + # we might have a versionId in the request + v = versionable.versions.get(versionRequest) + if v is not None: + return v + # find and return a standard version + v = versionable.releasedVersion + if v is None: + v = versionable.currentVersion + return v def getMaster(obj): diff --git a/versioning/version_macros.pt b/versioning/version_macros.pt new file mode 100644 index 0000000..83e9d41 --- /dev/null +++ b/versioning/version_macros.pt @@ -0,0 +1,54 @@ + +
+

Versions


+ + + + + + + + + + + + + + + + + + + +
TitleTypeVSizeModification Date
+ + Resource Title + + Type + 1.1 + + Type + Type
+
+
+ + + + + + + + +