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