work in progress: use reports for standard listings
This commit is contained in:
parent
20c8d9778e
commit
8608fa0997
5 changed files with 98 additions and 15 deletions
|
@ -75,4 +75,20 @@
|
||||||
class="loops.expert.browser.report.ResultsView"
|
class="loops.expert.browser.report.ResultsView"
|
||||||
permission="zope.View" />
|
permission="zope.View" />
|
||||||
|
|
||||||
|
<zope:adapter
|
||||||
|
name="concept_report.html"
|
||||||
|
for="loops.interfaces.IConcept
|
||||||
|
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||||
|
provides="zope.interface.Interface"
|
||||||
|
factory="loops.expert.browser.report.ReportConceptView"
|
||||||
|
permission="zope.View" />
|
||||||
|
|
||||||
|
<zope:adapter
|
||||||
|
name="concept_results.html"
|
||||||
|
for="loops.interfaces.IConcept
|
||||||
|
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||||
|
provides="zope.interface.Interface"
|
||||||
|
factory="loops.expert.browser.report.ResultsConceptView"
|
||||||
|
permission="zope.View" />
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
|
|
@ -137,9 +137,6 @@ class ResultsConceptView(ConceptView):
|
||||||
""" View on a concept using the results of a report.
|
""" View on a concept using the results of a report.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
reportName = None # define in subclass if applicable
|
|
||||||
reportType = None # set for using special report instance adapter
|
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def result_macros(self):
|
def result_macros(self):
|
||||||
return self.controller.getTemplateMacros('results', results_template)
|
return self.controller.getTemplateMacros('results', results_template)
|
||||||
|
@ -157,12 +154,22 @@ class ResultsConceptView(ConceptView):
|
||||||
def hasReportPredicate(self):
|
def hasReportPredicate(self):
|
||||||
return self.conceptManager['hasreport']
|
return self.conceptManager['hasreport']
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def reportName(self):
|
||||||
|
return (self.getOptions('report_name') or [None])[0]
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def reportType(self):
|
||||||
|
return (self.getOptions('report_type') or [None])[0]
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def report(self):
|
def report(self):
|
||||||
if self.reportName:
|
if self.reportName:
|
||||||
return adapted(self.conceptManager[self.reportName])
|
return adapted(self.conceptManager[self.reportName])
|
||||||
type = self.context.conceptType
|
reports = self.context.getParents([self.hasReportPredicate])
|
||||||
reports = type.getParents([self.hasReportPredicate])
|
if not reports:
|
||||||
|
type = self.context.conceptType
|
||||||
|
reports = type.getParents([self.hasReportPredicate])
|
||||||
return adapted(reports[0])
|
return adapted(reports[0])
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
|
|
|
@ -38,6 +38,10 @@
|
||||||
set_schema="loops.expert.report.IReportInstance" />
|
set_schema="loops.expert.report.IReportInstance" />
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
|
<adapter factory="loops.expert.standard.TypeInstances"
|
||||||
|
name="type_instances"
|
||||||
|
provides="loops.expert.report.IReportInstance" />
|
||||||
|
|
||||||
<utility
|
<utility
|
||||||
provides="zope.schema.interfaces.IVocabularyFactory"
|
provides="zope.schema.interfaces.IVocabularyFactory"
|
||||||
component="loops.expert.report.ReportTypeSourceList"
|
component="loops.expert.report.ReportTypeSourceList"
|
||||||
|
|
|
@ -92,17 +92,19 @@ class ReportInstance(BaseReport):
|
||||||
|
|
||||||
def getResults(self, dynaParams=None):
|
def getResults(self, dynaParams=None):
|
||||||
crit = self.queryCriteria
|
crit = self.queryCriteria
|
||||||
if crit is None:
|
|
||||||
return []
|
|
||||||
limits = self.limits
|
limits = self.limits
|
||||||
if dynaParams is not None:
|
if crit is None:
|
||||||
for k, v in dynaParams.items():
|
parts = Jeep()
|
||||||
if k == 'limits':
|
#return ResultSet(self, [])
|
||||||
limits = v
|
else:
|
||||||
break
|
if dynaParams is not None:
|
||||||
if k in crit.parts.keys():
|
for k, v in dynaParams.items():
|
||||||
crit.parts[k].comparisonValue = v
|
if k == 'limits':
|
||||||
parts = Jeep(crit.parts)
|
limits = v
|
||||||
|
break
|
||||||
|
if k in crit.parts.keys():
|
||||||
|
crit.parts[k].comparisonValue = v
|
||||||
|
parts = Jeep(crit.parts)
|
||||||
result = list(self.selectObjects(parts)) # may modify parts
|
result = list(self.selectObjects(parts)) # may modify parts
|
||||||
qc = CompoundQueryCriteria(parts)
|
qc = CompoundQueryCriteria(parts)
|
||||||
return ResultSet(self, result, rowFactory=self.rowFactory,
|
return ResultSet(self, result, rowFactory=self.rowFactory,
|
||||||
|
|
54
expert/standard.py
Normal file
54
expert/standard.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2013 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
loops standard reports.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
|
||||||
|
from cybertools.util.jeep import Jeep
|
||||||
|
from loops.browser.concept import ConceptView
|
||||||
|
from loops.expert.field import Field, TargetField, DateField, StateField, \
|
||||||
|
TextField, HtmlTextField, UrlField
|
||||||
|
from loops.expert.report import ReportInstance
|
||||||
|
|
||||||
|
|
||||||
|
title = UrlField('title', u'Title',
|
||||||
|
description=u'A short descriptive text.',
|
||||||
|
executionSteps=['output'])
|
||||||
|
|
||||||
|
|
||||||
|
class TypeInstances(ReportInstance):
|
||||||
|
|
||||||
|
fields = Jeep((title,))
|
||||||
|
defaultOutputFields = fields
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def targets(self):
|
||||||
|
targetPredicate = self.view.conceptManager['querytarget']
|
||||||
|
return self.view.context.getChildren([targetPredicate])
|
||||||
|
|
||||||
|
def selectObjects(self, parts):
|
||||||
|
result = []
|
||||||
|
for t in self.targets:
|
||||||
|
for c in t.getChildren([self.view.typePredicate]):
|
||||||
|
result.append(c)
|
||||||
|
print '***', self.targets, result
|
||||||
|
return result
|
||||||
|
|
Loading…
Add table
Reference in a new issue