move 'parts' logic to ConceptView class so that parts can be used in standard (non-Lobo) views
This commit is contained in:
parent
ae1ef58276
commit
a2cc1ee9a3
4 changed files with 46 additions and 37 deletions
|
@ -131,6 +131,7 @@ class BaseView(GenericView, I18NView):
|
|||
|
||||
actions = {}
|
||||
portlet_actions = []
|
||||
parts = ()
|
||||
icon = None
|
||||
modeName = 'view'
|
||||
isToplevel = False
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2011 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
|
||||
|
@ -200,16 +200,22 @@ class BaseRelationView(BaseView):
|
|||
class ConceptView(BaseView):
|
||||
|
||||
template = concept_macros
|
||||
templateName = 'concept.standard'
|
||||
macroName = 'conceptdata'
|
||||
partPrefix = 'part_'
|
||||
defaultParts = ('title', 'fields',
|
||||
'children', 'resources', 'workitems', 'comments',)
|
||||
|
||||
def childViewFactory(self, *args, **kw):
|
||||
return ConceptRelationView(*args, **kw)
|
||||
|
||||
@Lazy
|
||||
def macro(self):
|
||||
return self.template.macros['conceptdata']
|
||||
def macros(self):
|
||||
return self.controller.getTemplateMacros(self.templateName, self.template)
|
||||
|
||||
#def __init__(self, context, request):
|
||||
# super(ConceptView, self).__init__(context, request)
|
||||
@property
|
||||
def macro(self):
|
||||
return self.macros[self.macroName]
|
||||
|
||||
def setupController(self):
|
||||
cont = self.controller
|
||||
|
@ -222,6 +228,24 @@ class ConceptView(BaseView):
|
|||
subMacro=concept_macros.macros['parents'],
|
||||
priority=20, info=self)
|
||||
|
||||
def getParts(self):
|
||||
parts = (self.params.get('parts') or []) # deprecated!
|
||||
if not parts:
|
||||
parts = (self.options('parts') or self.typeOptions('parts') or
|
||||
self.defaultParts)
|
||||
return self.getPartViews(parts)
|
||||
|
||||
def getPartViews(self, parts):
|
||||
result = []
|
||||
for p in parts:
|
||||
viewName = self.partPrefix + p
|
||||
view = component.queryMultiAdapter((self.adapted, self.request),
|
||||
name=viewName)
|
||||
if view is not None:
|
||||
view.parent = self
|
||||
result.append(view)
|
||||
return result
|
||||
|
||||
@Lazy
|
||||
def adapted(self):
|
||||
return adapted(self.context, self.languageInfo)
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
<html i18n:domain="loops">
|
||||
|
||||
|
||||
<metal:data define-macro="conceptinfo">
|
||||
<tal:part repeat="part item/parts">
|
||||
<metal:part use-macro="part/renderer" />
|
||||
</tal:part>
|
||||
</metal:data>
|
||||
|
||||
|
||||
<metal:data define-macro="conceptdata">
|
||||
<div tal:attributes="class string:content-$level;">
|
||||
<metal:block use-macro="view/concept_macros/concepttitle" />
|
||||
|
|
|
@ -41,18 +41,12 @@ class Base(BaseConceptView):
|
|||
templateName = 'lobo.standard'
|
||||
macroName = None
|
||||
|
||||
@Lazy
|
||||
def macros(self):
|
||||
return self.controller.getTemplateMacros(self.templateName, self.template)
|
||||
|
||||
@property
|
||||
def macro(self):
|
||||
return self.macros[self.macroName]
|
||||
|
||||
@Lazy
|
||||
def params(self):
|
||||
ann = self.request.annotations.get('loops.view', {})
|
||||
return parse_qs(ann.get('params') or '')
|
||||
#@Lazy
|
||||
# better implementation in BaseView:
|
||||
# splits comma-separated list of values automatically
|
||||
#def params(self):
|
||||
# ann = self.request.annotations.get('loops.view', {})
|
||||
# return parse_qs(ann.get('params') or '')
|
||||
|
||||
|
||||
class ConceptView(BaseConceptView):
|
||||
|
@ -152,25 +146,8 @@ class ConceptView(BaseConceptView):
|
|||
class Layout(Base, ConceptView):
|
||||
|
||||
macroName = 'layout'
|
||||
|
||||
def getParts(self):
|
||||
parts = (self.params.get('parts') or [''])[0].split(',') # obsolete
|
||||
if not parts or not parts[0]:
|
||||
parts = (self.options('parts') or
|
||||
self.typeOptions('parts') or
|
||||
['h1', 'g3'])
|
||||
return self.getPartViews(parts)
|
||||
|
||||
def getPartViews(self, parts):
|
||||
result = []
|
||||
for p in parts:
|
||||
viewName = 'lobo_' + p
|
||||
view = component.queryMultiAdapter((self.adapted, self.request),
|
||||
name=viewName)
|
||||
if view is not None:
|
||||
view.parent = self
|
||||
result.append(view)
|
||||
return result
|
||||
partPrefix = 'lobo_'
|
||||
defaultParts = ('h1', 'g3',)
|
||||
|
||||
|
||||
class BasePart(Base):
|
||||
|
@ -192,7 +169,7 @@ class BasePart(Base):
|
|||
return preds
|
||||
|
||||
def getChildren(self):
|
||||
subtypeNames = (self.params.get('subtypes') or [''])[0].split(',')
|
||||
subtypeNames = (self.params.get('subtypes') or [])
|
||||
subtypes = [self.conceptManager[st] for st in subtypeNames if st]
|
||||
result = []
|
||||
childRels = self.context.getChildRelations(self.childPredicates)
|
||||
|
|
Loading…
Add table
Reference in a new issue