work in progress: use reports for standard listings

This commit is contained in:
Helmut Merz 2013-02-15 10:25:47 +01:00
parent 20c8d9778e
commit 8608fa0997
5 changed files with 98 additions and 15 deletions

View file

@ -75,4 +75,20 @@
class="loops.expert.browser.report.ResultsView"
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>

View file

@ -137,9 +137,6 @@ class ResultsConceptView(ConceptView):
""" 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
def result_macros(self):
return self.controller.getTemplateMacros('results', results_template)
@ -157,12 +154,22 @@ class ResultsConceptView(ConceptView):
def hasReportPredicate(self):
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
def report(self):
if self.reportName:
return adapted(self.conceptManager[self.reportName])
type = self.context.conceptType
reports = type.getParents([self.hasReportPredicate])
reports = self.context.getParents([self.hasReportPredicate])
if not reports:
type = self.context.conceptType
reports = type.getParents([self.hasReportPredicate])
return adapted(reports[0])
@Lazy

View file

@ -38,6 +38,10 @@
set_schema="loops.expert.report.IReportInstance" />
</class>
<adapter factory="loops.expert.standard.TypeInstances"
name="type_instances"
provides="loops.expert.report.IReportInstance" />
<utility
provides="zope.schema.interfaces.IVocabularyFactory"
component="loops.expert.report.ReportTypeSourceList"

View file

@ -92,17 +92,19 @@ class ReportInstance(BaseReport):
def getResults(self, dynaParams=None):
crit = self.queryCriteria
if crit is None:
return []
limits = self.limits
if dynaParams is not None:
for k, v in dynaParams.items():
if k == 'limits':
limits = v
break
if k in crit.parts.keys():
crit.parts[k].comparisonValue = v
parts = Jeep(crit.parts)
if crit is None:
parts = Jeep()
#return ResultSet(self, [])
else:
if dynaParams is not None:
for k, v in dynaParams.items():
if k == 'limits':
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
qc = CompoundQueryCriteria(parts)
return ResultSet(self, result, rowFactory=self.rowFactory,

54
expert/standard.py Normal file
View 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