work in progress: reporting, example 'work statement' report
This commit is contained in:
parent
120156cd04
commit
55fbb7eefc
5 changed files with 106 additions and 28 deletions
|
@ -73,8 +73,7 @@ class ResultsView(NodeView):
|
|||
@Lazy
|
||||
def params(self):
|
||||
params = dict(self.request.form)
|
||||
if 'report_execute' in params:
|
||||
del params['report_execute']
|
||||
params.pop('report_execute', None)
|
||||
return params
|
||||
|
||||
@Lazy
|
||||
|
@ -105,3 +104,5 @@ class ResultsView(NodeView):
|
|||
def displayedColumns(self):
|
||||
return self.reportInstance.getActiveOutputFields()
|
||||
|
||||
def getColumnRenderer(self, name):
|
||||
return self.result_macros[name]
|
||||
|
|
|
@ -19,4 +19,16 @@
|
|||
</div>
|
||||
|
||||
|
||||
<metal:standard define-macro="standard">
|
||||
<td tal:content="structure python:col.getDisplayValue(row)" />
|
||||
</metal:standard>
|
||||
|
||||
|
||||
<metal:standard define-macro="target">
|
||||
<td tal:define="value python:col.getDisplayValue(row)">
|
||||
<a tal:attributes="href value/url"
|
||||
tal:content="value/title" /></td>
|
||||
</metal:standard>
|
||||
|
||||
|
||||
</html>
|
||||
|
|
|
@ -220,10 +220,16 @@ in a results view.
|
|||
>>> from loops.expert.browser.report import ReportView, ResultsView
|
||||
>>> resultsView = ResultsView(reportNode, TestRequest())
|
||||
|
||||
>>> results = resultsView.results()
|
||||
>>> len(results.data)
|
||||
2
|
||||
|
||||
>>> results = resultsView.results().getResult()
|
||||
>>> len(results)
|
||||
1
|
||||
>>> for row in results:
|
||||
... for col in resultsView.displayedColumns:
|
||||
... print col.getDisplayValue(row),
|
||||
... print
|
||||
08/12/28 1230487200 1230491700
|
||||
{'url': '.../home/report/.36', 'title': u'loops Development'}
|
||||
{'url': '.../home/report/.33', 'title': u'john'} 4500 900 finished
|
||||
|
||||
Fin de partie
|
||||
=============
|
||||
|
|
|
@ -29,6 +29,8 @@ from cybertools.composer.report.base import LeafQueryCriteria, CompoundQueryCrit
|
|||
from cybertools.composer.report.field import Field
|
||||
from cybertools.composer.report.result import ResultSet, Row as BaseRow
|
||||
from cybertools.organize.interfaces import IWorkItems
|
||||
from cybertools.util.date import timeStamp2Date
|
||||
from cybertools.util.format import formatDate
|
||||
from cybertools.util.jeep import Jeep
|
||||
from loops.common import adapted, baseObject
|
||||
from loops.expert.report import ReportInstance
|
||||
|
@ -37,29 +39,90 @@ from loops import util
|
|||
results_template = ViewPageTemplateFile('results.pt')
|
||||
|
||||
|
||||
class TargetField(Field):
|
||||
|
||||
renderer = 'target'
|
||||
|
||||
def getValue(self, row):
|
||||
value = self.getRawValue(row)
|
||||
return util.getObjectForUid(value)
|
||||
|
||||
def getDisplayValue(self, row):
|
||||
value = self.getValue(row)
|
||||
if value is None:
|
||||
return dict(title=self.getRawValue(row), url=u'')
|
||||
view = row.parent.context.view
|
||||
return dict(title=value.title, url=view.getUrlForTarget(value))
|
||||
|
||||
|
||||
class DayField(Field):
|
||||
|
||||
def getValue(self, row):
|
||||
return timeStamp2Date(self.getRawValue(row))
|
||||
|
||||
def getDisplayValue(self, row):
|
||||
value = self.getValue(row)
|
||||
if value:
|
||||
view = row.parent.context.view
|
||||
return formatDate(value, 'date', 'short', view.languageInfo.language)
|
||||
return u''
|
||||
|
||||
|
||||
tasks = Field('tasks', u'Tasks',
|
||||
description=u'The tasks to which work items belong.',
|
||||
executionSteps=['query', 'output', 'sort'])
|
||||
work = Field('work', u'Work',
|
||||
description=u'The short description of the work.',
|
||||
executionSteps=['output'])
|
||||
workDescription = Field('workDescription', u'Work Description',
|
||||
description=u'The long description of the work.',
|
||||
executionSteps=['output'])
|
||||
day = Field('day', u'Day',
|
||||
description=u'The day the work was done.',
|
||||
executionSteps=['output', 'sort'])
|
||||
description=u'The tasks from which work items should be selected.',
|
||||
executionSteps=['query'])
|
||||
dayFrom = Field('dayFrom', u'Start Day',
|
||||
description=u'The first day from which to select work.',
|
||||
executionSteps=['query'])
|
||||
dayTo = Field('dayTo', u'End Day',
|
||||
description=u'The last day until which to select work.',
|
||||
executionSteps=['query'])
|
||||
day = DayField('day', u'Day',
|
||||
description=u'The day the work was done.',
|
||||
executionSteps=['sort', 'output'])
|
||||
timeStart = Field('start', u'Start Time',
|
||||
description=u'The time the unit of work was started.',
|
||||
executionSteps=['sort', 'output'])
|
||||
timeEnd = Field('end', u'End Time',
|
||||
description=u'The time the unit of work was finished.',
|
||||
executionSteps=['output'])
|
||||
task = TargetField('taskId', u'Task',
|
||||
description=u'The task to which work items belong.',
|
||||
executionSteps=['output'])
|
||||
party = TargetField('userName', u'Party',
|
||||
description=u'The party (usually a person) who did the work.',
|
||||
executionSteps=['sort', 'output'])
|
||||
title = Field('title', u'Title',
|
||||
description=u'The short description of the work.',
|
||||
executionSteps=['output'])
|
||||
description = Field('description', u'Description',
|
||||
description=u'The long description of the work.',
|
||||
executionSteps=['x_output'])
|
||||
duration = Field('duration', u'Duration',
|
||||
description=u'The duration of the work.',
|
||||
executionSteps=['output'])
|
||||
effort = Field('effort', u'Effort',
|
||||
description=u'The effort of the work.',
|
||||
executionSteps=['output', 'sum'])
|
||||
state = Field('state', u'State',
|
||||
description=u'The state of the work.',
|
||||
executionSteps=['query', 'output'])
|
||||
|
||||
|
||||
class WorkRow(BaseRow):
|
||||
|
||||
pass
|
||||
def getRawValue(self, attr):
|
||||
if attr in self.attributeHandlers:
|
||||
return self.attributeHandlers[attr](self, attr)
|
||||
track = self.context
|
||||
if attr in track.metadata_attributes:
|
||||
return getattr(track, attr)
|
||||
return track.data.get(attr, u'')
|
||||
|
||||
def getDay(self, attr):
|
||||
return self.context.timeStamp
|
||||
|
||||
attributeHandlers = dict(day=getDay)
|
||||
|
||||
|
||||
class WorkReportInstance(ReportInstance):
|
||||
|
@ -68,7 +131,9 @@ class WorkReportInstance(ReportInstance):
|
|||
label = u'Work Report'
|
||||
|
||||
rowFactory = WorkRow
|
||||
fields = Jeep((day, dayFrom, dayTo, tasks, work, workDescription))
|
||||
fields = Jeep((dayFrom, dayTo, tasks,
|
||||
day, timeStart, timeEnd, task, party, title, description,
|
||||
duration, effort, state))
|
||||
defaultOutputFields = fields
|
||||
|
||||
@property
|
||||
|
@ -80,12 +145,6 @@ class WorkReportInstance(ReportInstance):
|
|||
crit = [LeafQueryCriteria(f.name, f.operator, tasks, f)]
|
||||
return CompoundQueryCriteria(crit)
|
||||
|
||||
@property
|
||||
def xx_queryCriteria(self):
|
||||
crit = [LeafQueryCriteria(f.name, f.operator, None, f)
|
||||
for f in self.getAllQueryFields()]
|
||||
return CompoundQueryCriteria(crit)
|
||||
|
||||
def getResultsRenderer(self, name, defaultMacros):
|
||||
return results_template.macros[name]
|
||||
|
||||
|
@ -101,7 +160,8 @@ class WorkReportInstance(ReportInstance):
|
|||
|
||||
def selectWorkItems(self, task, parts):
|
||||
wi = self.workItems
|
||||
return wi.query(task=util.getUidForObject(task))
|
||||
states = ['done', 'done_x', 'finished']
|
||||
return wi.query(task=util.getUidForObject(task), state=states)
|
||||
|
||||
def getAllSubtasks(self, concept):
|
||||
result = []
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
</tr>
|
||||
<tr tal:repeat="row view/results">
|
||||
<tal:column repeat="col view/displayedColumns">
|
||||
<p tal:content="col/renderer" />
|
||||
<xmetal:column use-macro="python:view.getColumnRenderer(col.renderer)" />
|
||||
<metal:column use-macro="python:view.getColumnRenderer(col.renderer)" />
|
||||
</tal:column>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
Loading…
Add table
Reference in a new issue