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 = {}
|
actions = {}
|
||||||
portlet_actions = []
|
portlet_actions = []
|
||||||
|
parts = ()
|
||||||
icon = None
|
icon = None
|
||||||
modeName = 'view'
|
modeName = 'view'
|
||||||
isToplevel = False
|
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
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -200,16 +200,22 @@ class BaseRelationView(BaseView):
|
||||||
class ConceptView(BaseView):
|
class ConceptView(BaseView):
|
||||||
|
|
||||||
template = concept_macros
|
template = concept_macros
|
||||||
|
templateName = 'concept.standard'
|
||||||
|
macroName = 'conceptdata'
|
||||||
|
partPrefix = 'part_'
|
||||||
|
defaultParts = ('title', 'fields',
|
||||||
|
'children', 'resources', 'workitems', 'comments',)
|
||||||
|
|
||||||
def childViewFactory(self, *args, **kw):
|
def childViewFactory(self, *args, **kw):
|
||||||
return ConceptRelationView(*args, **kw)
|
return ConceptRelationView(*args, **kw)
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def macro(self):
|
def macros(self):
|
||||||
return self.template.macros['conceptdata']
|
return self.controller.getTemplateMacros(self.templateName, self.template)
|
||||||
|
|
||||||
#def __init__(self, context, request):
|
@property
|
||||||
# super(ConceptView, self).__init__(context, request)
|
def macro(self):
|
||||||
|
return self.macros[self.macroName]
|
||||||
|
|
||||||
def setupController(self):
|
def setupController(self):
|
||||||
cont = self.controller
|
cont = self.controller
|
||||||
|
@ -222,6 +228,24 @@ class ConceptView(BaseView):
|
||||||
subMacro=concept_macros.macros['parents'],
|
subMacro=concept_macros.macros['parents'],
|
||||||
priority=20, info=self)
|
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
|
@Lazy
|
||||||
def adapted(self):
|
def adapted(self):
|
||||||
return adapted(self.context, self.languageInfo)
|
return adapted(self.context, self.languageInfo)
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
<html i18n:domain="loops">
|
<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">
|
<metal:data define-macro="conceptdata">
|
||||||
<div tal:attributes="class string:content-$level;">
|
<div tal:attributes="class string:content-$level;">
|
||||||
<metal:block use-macro="view/concept_macros/concepttitle" />
|
<metal:block use-macro="view/concept_macros/concepttitle" />
|
||||||
|
|
|
@ -41,18 +41,12 @@ class Base(BaseConceptView):
|
||||||
templateName = 'lobo.standard'
|
templateName = 'lobo.standard'
|
||||||
macroName = None
|
macroName = None
|
||||||
|
|
||||||
@Lazy
|
#@Lazy
|
||||||
def macros(self):
|
# better implementation in BaseView:
|
||||||
return self.controller.getTemplateMacros(self.templateName, self.template)
|
# splits comma-separated list of values automatically
|
||||||
|
#def params(self):
|
||||||
@property
|
# ann = self.request.annotations.get('loops.view', {})
|
||||||
def macro(self):
|
# return parse_qs(ann.get('params') or '')
|
||||||
return self.macros[self.macroName]
|
|
||||||
|
|
||||||
@Lazy
|
|
||||||
def params(self):
|
|
||||||
ann = self.request.annotations.get('loops.view', {})
|
|
||||||
return parse_qs(ann.get('params') or '')
|
|
||||||
|
|
||||||
|
|
||||||
class ConceptView(BaseConceptView):
|
class ConceptView(BaseConceptView):
|
||||||
|
@ -152,25 +146,8 @@ class ConceptView(BaseConceptView):
|
||||||
class Layout(Base, ConceptView):
|
class Layout(Base, ConceptView):
|
||||||
|
|
||||||
macroName = 'layout'
|
macroName = 'layout'
|
||||||
|
partPrefix = 'lobo_'
|
||||||
def getParts(self):
|
defaultParts = ('h1', 'g3',)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class BasePart(Base):
|
class BasePart(Base):
|
||||||
|
@ -192,7 +169,7 @@ class BasePart(Base):
|
||||||
return preds
|
return preds
|
||||||
|
|
||||||
def getChildren(self):
|
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]
|
subtypes = [self.conceptManager[st] for st in subtypeNames if st]
|
||||||
result = []
|
result = []
|
||||||
childRels = self.context.getChildRelations(self.childPredicates)
|
childRels = self.context.getChildRelations(self.childPredicates)
|
||||||
|
|
Loading…
Add table
Reference in a new issue