populate dayFrom field with a sensible default value; use form action for providing CSV export in order respect query input
This commit is contained in:
parent
f4a5b78700
commit
711488a412
5 changed files with 49 additions and 20 deletions
|
@ -38,22 +38,30 @@
|
|||
<metal:block use-macro="view/concept_macros/concepttitle" />
|
||||
<form method="get" name="report_data" class="report-meta">
|
||||
<input type="hidden" name="show_results" value="True" />
|
||||
<tal:hidden define="params item/dynamicParams"
|
||||
tal:condition="nothing">
|
||||
<tal:hidden define="params item/dynamicParams">
|
||||
<input type="hidden"
|
||||
tal:repeat="name params"
|
||||
tal:condition="nothing"
|
||||
tal:attributes="name name;
|
||||
value params/?name" /></tal:hidden>
|
||||
value params/?name" />
|
||||
<input type="hidden"
|
||||
tal:define="sortinfo request/sortinfo_results|nothing"
|
||||
tal:condition="sortinfo"
|
||||
tal:attributes="name string:sortinfo_results;
|
||||
value sortinfo" />
|
||||
</tal:hidden>
|
||||
<div metal:use-macro="item/report_macros/params" />
|
||||
<div metal:define-macro="buttons">
|
||||
<input type="submit" name="report_execute" value="Execute Report"
|
||||
onclick="this.form.action = ''"
|
||||
tal:attributes="value item/reportExecuteTitle|string:Execute Report"
|
||||
tal:condition="item/queryFields"
|
||||
i18n:attributes="value" />
|
||||
<input type="submit"
|
||||
<input type="submit" name="report_download"
|
||||
tal:condition="item/reportDownload"
|
||||
tal:attributes="name string:${item/reportDownload}:method;
|
||||
value item/reportDownloadTitle"
|
||||
tal:attributes="value item/reportDownloadTitle;
|
||||
onclick string:
|
||||
this.form.action = '${item/reportDownload}'"
|
||||
i18n:attributes="value" />
|
||||
</div>
|
||||
<br />
|
||||
|
|
|
@ -234,11 +234,11 @@ class ResultsConceptView(ConceptView):
|
|||
if not opt:
|
||||
opt = self.typeOptions('download_' + format)
|
||||
if opt:
|
||||
return opt[0]
|
||||
return '/'.join((self.nodeView.virtualTargetUrl, opt[0]))
|
||||
|
||||
#@Lazy
|
||||
#def reportDownload(self):
|
||||
# return self.downloadLink
|
||||
@Lazy
|
||||
def reportDownload(self):
|
||||
return self.downloadLink
|
||||
|
||||
def isSortableColumn(self, tableName, colName):
|
||||
if tableName == 'results':
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<div metal:define-macro="results"
|
||||
tal:define="tableName string:results">
|
||||
<br />
|
||||
<tal:download condition="item/downloadLink">
|
||||
<tal:download condition="nothing">
|
||||
<div class="button">
|
||||
<a i18n:translate=""
|
||||
tal:define="dl string:${item/downloadLink}${item/urlParamString};
|
||||
|
|
|
@ -218,7 +218,8 @@ The executable report is a report instance that is an adapter to the
|
|||
The user interface is a ReportConceptView subclass that is directly associated with the task.
|
||||
|
||||
>>> from loops.organize.work.report import WorkStatementView
|
||||
>>> reportView = WorkStatementView(task01, TestRequest())
|
||||
>>> input = dict(dayFrom='2008-01-01')
|
||||
>>> reportView = WorkStatementView(task01, TestRequest(form=input))
|
||||
>>> reportView.nodeView = nodeView
|
||||
|
||||
>>> results = reportView.results()
|
||||
|
@ -241,7 +242,7 @@ Export of work data
|
|||
-------------------
|
||||
|
||||
>>> from loops.organize.work.report import WorkStatementCSVExport
|
||||
>>> reportView = WorkStatementCSVExport(task01, TestRequest())
|
||||
>>> reportView = WorkStatementCSVExport(task01, TestRequest(form=input))
|
||||
>>> reportView.nodeView = nodeView
|
||||
|
||||
>>> output = reportView()
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
Work report definitions.
|
||||
"""
|
||||
|
||||
from datetime import date, timedelta
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.component import adapter, getAdapter
|
||||
|
@ -113,6 +114,10 @@ class PartyStateField(StateField):
|
|||
return None
|
||||
|
||||
|
||||
def yesterday(context):
|
||||
return (date.today() - timedelta(1)).isoformat()
|
||||
|
||||
|
||||
# common fields
|
||||
|
||||
tasks = Field('tasks', u'Tasks',
|
||||
|
@ -129,6 +134,7 @@ deadline = TrackDateField('deadline', u'Deadline',
|
|||
dayFrom = TrackDateField('dayFrom', u'Start Day',
|
||||
description=u'The first day from which to select work.',
|
||||
fieldType='date',
|
||||
default=yesterday,
|
||||
operator=u'ge',
|
||||
executionSteps=['query'])
|
||||
dayTo = TrackDateField('dayTo', u'End Day',
|
||||
|
@ -183,6 +189,8 @@ partyState = PartyStateField('partyState', u'Party State',
|
|||
cssClass='center',
|
||||
statesDefinition='contact_states',
|
||||
executionSteps=['query', 'output'])
|
||||
# activity
|
||||
# process
|
||||
|
||||
|
||||
# basic definitions and work report instance
|
||||
|
@ -249,6 +257,19 @@ class WorkReportInstance(ReportInstance):
|
|||
def states(self):
|
||||
return self.getOptions('report_select_state') or self.defaultStates
|
||||
|
||||
def getFieldQueryCriteria(self, field, data):
|
||||
if field.name in data:
|
||||
return LeafQueryCriteria(
|
||||
field.name, field.operator, data[field.name], field)
|
||||
else:
|
||||
default = field.default
|
||||
if default is not None:
|
||||
if callable(default):
|
||||
default = default(self)
|
||||
if default:
|
||||
return LeafQueryCriteria(
|
||||
field.name, field.operator, default, field)
|
||||
|
||||
@property
|
||||
def queryCriteria(self):
|
||||
form = self.view.request.form
|
||||
|
@ -259,9 +280,9 @@ class WorkReportInstance(ReportInstance):
|
|||
tasks = [util.getUidForObject(task) for task in tasks]
|
||||
crit = [LeafQueryCriteria(f.name, f.operator, tasks, f)]
|
||||
for f in self.getAllQueryFields():
|
||||
if f.name in form:
|
||||
crit.append(
|
||||
LeafQueryCriteria(f.name, f.operator, form[f.name], f))
|
||||
fc = self.getFieldQueryCriteria(f, form)
|
||||
if fc is not None:
|
||||
crit.append(fc)
|
||||
return CompoundQueryCriteria(crit)
|
||||
|
||||
def selectObjects(self, parts):
|
||||
|
@ -320,12 +341,11 @@ class PersonWorkReportInstance(WorkReportInstance):
|
|||
|
||||
@property
|
||||
def queryCriteria(self):
|
||||
form = self.view.request.form
|
||||
crit = self.context.queryCriteria or []
|
||||
for f in self.getAllQueryFields():
|
||||
if f.name in form:
|
||||
crit.append(
|
||||
LeafQueryCriteria(f.name, f.operator, form[f.name], f))
|
||||
fc = self.getFieldQueryCriteria(f, self.view.request.form)
|
||||
if fc is not None:
|
||||
crit.append(fc)
|
||||
return CompoundQueryCriteria(crit)
|
||||
|
||||
def selectObjects(self, parts):
|
||||
|
|
Loading…
Add table
Reference in a new issue