provide more control on what is shown in list or grid via new 'represents' predicate for resources

This commit is contained in:
Helmut Merz 2012-03-05 18:36:27 +01:00
parent c71669f1a7
commit 5d3bcf3cfa
3 changed files with 33 additions and 9 deletions

View file

@ -17,7 +17,7 @@
title cell/description"> title cell/description">
<div class="legend"> <div class="legend">
<b tal:content="cell/title" /><br /> <b tal:content="cell/title" /><br />
<i tal:content="structure cell/renderedDescription" /> <i tal:content="structure cell/textRepresentation" />
</div> </div>
</a> </a>
</div> </div>
@ -36,7 +36,7 @@
<a tal:attributes="href cell/targetUrl"> <a tal:attributes="href cell/targetUrl">
<b tal:content="cell/title" /></a><br /> <b tal:content="cell/title" /></a><br />
<tal:desc condition="cell/description"> <tal:desc condition="cell/description">
<span tal:content="structure cell/renderedDescription" /></tal:desc> <span tal:content="structure cell/textRepresentation" /></tal:desc>
<br /> <br />
</div> </div>
</tal:cell> </tal:cell>

View file

@ -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
@ -18,8 +18,6 @@
""" """
View classes for lobo (blueprint-based) layouts. View classes for lobo (blueprint-based) layouts.
$Id$
""" """
from cgi import parse_qs from cgi import parse_qs
@ -66,8 +64,20 @@ class ConceptView(BaseConceptView):
@Lazy @Lazy
def resources(self): def resources(self):
return self.getResources()
@Lazy
def representingResources(self):
pred = self.representationPredicate
if pred is None:
return {}
return self.getResources([pred])
def getResources(self, predicates=None):
result = dict(texts=[], images=[], files=[]) result = dict(texts=[], images=[], files=[])
for r in self.context.getResources([self.defaultPredicate]): if predicates is None:
predicates = [self.defaultPredicate]
for r in self.context.getResources(predicates):
if r.contentType.startswith('text/'): if r.contentType.startswith('text/'):
result['texts'].append(r) result['texts'].append(r)
if r.contentType.startswith('image/'): if r.contentType.startswith('image/'):
@ -81,6 +91,10 @@ class ConceptView(BaseConceptView):
for r in self.resources['images']: for r in self.resources['images']:
yield r yield r
@Lazy
def representationPredicate(self):
return self.conceptManager.get('represents')
# properties from base class: title, description, renderedDescription # properties from base class: title, description, renderedDescription
@Lazy @Lazy
@ -99,6 +113,12 @@ class ConceptView(BaseConceptView):
return u'' return u''
return self.renderDescription(self.textDescription) return self.renderDescription(self.textDescription)
@Lazy
def textRepresentation(self):
for r in self.representingResources.get('texts', []):
return self.renderText(r.data, r.contentType)
return self.renderedDescription
@Lazy @Lazy
def targetUrl(self): def targetUrl(self):
return self.nodeView.getUrlForTarget(self.context) return self.nodeView.getUrlForTarget(self.context)

View file

@ -67,9 +67,13 @@ class StatefulConceptIndexInfo(IndexInfo):
@property @property
def availableStatesDefinitions(self): def availableStatesDefinitions(self):
globalOptions = IOptions(self.context.getLoopsRoot()) globalOptions = IOptions(self.context.getLoopsRoot())
typeOptions = IOptions(adapted(self.context.conceptType)) type = self.context.conceptType
return (globalOptions('organize.stateful.concept', []) + if type is None: # may happen during object creation
typeOptions('organize.stateful', [])) return globalOptions('organize.stateful.concept', [])
else:
typeOptions = IOptions(adapted(type))
return (globalOptions('organize.stateful.concept', []) +
typeOptions('organize.stateful', []))
class StatefulResourceIndexInfo(IndexInfo): class StatefulResourceIndexInfo(IndexInfo):