Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add adapters for adding reports
  • Loading branch information
rockfruit committed Feb 12, 2014
1 parent 7ff4b86 commit 99d3e64
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 46 deletions.
19 changes: 14 additions & 5 deletions bika/lims/browser/reports/__init__.py
Expand Up @@ -58,7 +58,7 @@ def __call__(self):
for name, adapter in adapters:
report_dict = adapter(self.context, self.request)
report_dict['id'] = name
self.additional_reports.append()
self.additional_reports.append(report_dict)

return self.template()

Expand All @@ -79,7 +79,7 @@ def __call__(self):
for name, adapter in adapters:
report_dict = adapter(self.context, self.request)
report_dict['id'] = name
self.additional_reports.append()
self.additional_reports.append(report_dict)

return self.template()

Expand Down Expand Up @@ -206,6 +206,12 @@ def __call__(self):

# if there's an error, we return productivity.pt which requires these.
self.selection_macros = SelectionMacrosView(self.context, self.request)
self.additional_reports = []
adapters = getAdapters((self.context, ), IProductivityReport)
for name, adapter in adapters:
report_dict = adapter(self.context, self.request)
report_dict['id'] = name
self.additional_reports.append(report_dict)

report_id = self.request.get('report_id', '')
if not report_id:
Expand Down Expand Up @@ -251,12 +257,15 @@ def __call__(self):
# once the PDF has been generated. temporary plot image files, etc.
self.request['to_remove'] = []

if "module" in self.request:
module = self.request["module"]
if "report_module" in self.request:
module = self.request["report_module"]
else:
module = "bika.lims.browser.reports.%s" % report_id
try:
exec("from %s import Report")
exec("from %s import Report" % module)
# required during error redirect: the report must have a copy of
# additional_reports, because it is used as a surrogate view.
Report.additional_reports = self.additional_reports
except ImportError:
message = "Report %s.Report not found (shouldn't happen)" % module
self.logger.error(message)
Expand Down
59 changes: 39 additions & 20 deletions bika/lims/browser/reports/selection_macros/__init__.py
Expand Up @@ -31,12 +31,14 @@ def __init__(self, context, request):
self.rc = self.reference_catalog

select_analysiscategory_pt = ViewPageTemplateFile("select_analysiscategory.pt")
def select_analysiscategory(self):
def select_analysiscategory(self, style=None):
self.style = style
self.analysiscategories = self.bsc(portal_type='AnalysisCategory', sort_on='sortable_title')
return self.select_analysiscategory_pt()

select_analysisservice_pt = ViewPageTemplateFile("select_analysisservice.pt")
def select_analysisservice(self, allow_blank=True, multiselect=False):
def select_analysisservice(self, allow_blank=True, multiselect=False, style=None):
self.style = style
self.allow_blank = allow_blank
self.multiselect = multiselect
self.analysisservices = self.bsc(portal_type='AnalysisService', sort_on='sortable_title')
Expand All @@ -57,7 +59,8 @@ def parse_analysisservice(self, request):
return res

select_analysisspecification_pt = ViewPageTemplateFile("select_analysisspecification.pt")
def select_analysisspecification(self):
def select_analysisspecification(self, style=None):
self.style = style
specfolder_uid = self.context.bika_setup.bika_analysisspecs.UID()
res = []
bsc = getToolByName(self.context, "bika_setup_catalog")
Expand All @@ -73,18 +76,21 @@ def select_analysisspecification(self):
return self.select_analysisspecification_pt()

select_analyst_pt = ViewPageTemplateFile("select_analyst.pt")
def select_analyst(self):
self.analysts = getUsers(self.context, ['Manager', 'LabManager', 'Analyst'])
def select_analyst(self, allow_blank=False, style=None):
self.style = style
self.analysts = getUsers(self.context, ['Manager', 'Analyst', 'LabManager'], allow_blank)
return self.select_analyst_pt()

select_user_pt = ViewPageTemplateFile("select_user.pt")
def select_user(self, allow_blank=True):
def select_user(self, allow_blank=True, style=None):
self.style = style
self.allow_blank = allow_blank
self.users = getUsers(self.context, None, allow_blank)
return self.select_user_pt()

select_client_pt = ViewPageTemplateFile("select_client.pt")
def select_client(self):
def select_client(self, style=None):
self.style = style
self.clients = self.pc(portal_type='Client', inactive_state='active', sort_on='sortable_title')
return self.select_client_pt()

Expand All @@ -100,12 +106,14 @@ def parse_client(self, request):
return res

select_contact_pt = ViewPageTemplateFile("select_contact.pt")
def select_contact(self):
def select_contact(self, style=None):
self.style = style
self.contacts = self.pc(portal_type='Contact', inactive_state='active', sort_on='sortable_title')
return self.select_contact_pt()

select_daterange_pt = ViewPageTemplateFile("select_daterange.pt")
def select_daterange(self, field_id, field_title):
def select_daterange(self, field_id, field_title, style=None):
self.style = style
self.field_id = field_id
self.field_title = _(field_title)
return self.select_daterange_pt()
Expand Down Expand Up @@ -136,34 +144,41 @@ def parse_daterange(self, request, field_id, field_title):
return res

select_instrument_pt = ViewPageTemplateFile("select_instrument.pt")
def select_instrument(self):
def select_instrument(self, style=None):
self.style = style
self.instruments = self.bsc(portal_type='Instrument', inactive_state='active', sort_on='sortable_title')
return self.select_instrument_pt()

select_period_pt = ViewPageTemplateFile("select_period.pt")
def select_period(self):
def select_period(self, style=None):
self.style = style
return self.select_period_pt()

select_profile_pt = ViewPageTemplateFile("select_profile.pt")
def select_profile(self):
def select_profile(self, style=None):
self.style = style
self.analysisprofiles = self.bsc(portal_type='AnalysisProfile', inactive_state='active', sort_on='sortable_title')
return self.select_profile_pt()

select_supplier_pt = ViewPageTemplateFile("select_supplier.pt")
def select_supplier(self):
def select_supplier(self, style=None):
self.style = style
self.suppliers = self.bsc(portal_type='Supplier', inactive_state='active', sort_on='sortable_title')
return self.select_supplier_pt()

select_reference_sample_pt = ViewPageTemplateFile("select_reference_sample.pt")
def select_reference_sample(self):
def select_reference_sample(self, style=None):
self.style = style
return self.select_reference_sample_pt()

select_reference_service_pt = ViewPageTemplateFile("select_reference_service.pt")
def select_reference_service(self):
def select_reference_service(self, style=None):
self.style = style
return self.select_reference_service_pt()

select_state_pt = ViewPageTemplateFile("select_state.pt")
def select_state(self, workflow_id, field_id, field_title):
def select_state(self, workflow_id, field_id, field_title, style=None):
self.style = style
self.field_id = field_id
self.field_title = field_title
states = self.portal_workflow[workflow_id].states
Expand All @@ -185,7 +200,8 @@ def parse_state(self, request, workflow_id, field_id, field_title):
return res

select_samplepoint_pt = ViewPageTemplateFile("select_samplepoint.pt")
def select_samplepoint(self, allow_blank=True, multiselect=False):
def select_samplepoint(self, allow_blank=True, multiselect=False, style=None):
self.style = style
self.allow_blank = allow_blank
self.multiselect = multiselect
self.samplepoints = self.bsc(portal_type='SamplePoint', inactive_state='active', sort_on='sortable_title')
Expand All @@ -203,7 +219,8 @@ def parse_samplepoint(self, request):
return res

select_sampletype_pt = ViewPageTemplateFile("select_sampletype.pt")
def select_sampletype(self, allow_blank=True, multiselect=False):
def select_sampletype(self, allow_blank=True, multiselect=False, style=None):
self.style = style
self.allow_blank = allow_blank
self.multiselect = multiselect
self.sampletypes = self.bsc(portal_type='SampleType', inactive_state='active', sort_on='sortable_title')
Expand All @@ -221,10 +238,12 @@ def parse_sampletype(self, request):
return res

select_groupingperiod_pt = ViewPageTemplateFile("select_groupingperiod.pt")
def select_groupingperiod(self, allow_blank=True, multiselect=False):
def select_groupingperiod(self, allow_blank=True, multiselect=False, style=None):
self.style = style
self.allow_blank = allow_blank
return self.select_groupingperiod_pt()

select_output_format_pt = ViewPageTemplateFile("select_output_format.pt")
def select_output_format(self):
def select_output_format(self, style=None):
self.style = style
return self.select_output_format_pt()
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" i18n:domain="bika" tal:attributes="style view/style|nothing">
<label i18n:translate="">Analysis category</label><br/>
<select name="CategoryUID:ignore_empty"
style=""
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" i18n:domain="bika" tal:attributes="style view/style|nothing">

<label i18n:translate="">Analysis service</label>
<br/>
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" i18n:domain="bika" tal:attributes="style view/style|nothing">

<label i18n:translate="label_specification">Specification</label>
<br/>
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika"
<div class="field" i18n:domain="bika" tal:attributes="style view/style|nothing"
tal:define="analysts view/analysts">

<label i18n:translate="">Analyst</label>
Expand Down
3 changes: 2 additions & 1 deletion bika/lims/browser/reports/selection_macros/select_client.pt
@@ -1,4 +1,5 @@
<div class="field" tal:condition="not:here/member_is_client" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing"
tal:condition="not:here/member_is_client" i18n:domain="bika">

<label i18n:translate="">Client</label>
<br/>
Expand Down
3 changes: 2 additions & 1 deletion bika/lims/browser/reports/selection_macros/select_contact.pt
@@ -1,4 +1,5 @@
<div class="field" tal:condition="not:here/member_is_client" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing"
tal:condition="not:here/member_is_client" i18n:domain="bika">

<label i18n:translate="">Contact</label>
<br/>
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika">

<label tal:content="string:${view/field_title}"></label>
<br/>
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika"
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika"
tal:define="groups python:['Day', 'Week', 'Month', 'Year']">

<label i18n:translate="">Group by</label>
Expand All @@ -7,7 +7,7 @@
<select name="GroupingPeriod:ignore_empty"
id="GroupingPeriod"
tal:attributes="style string:font-family:${here/base_properties/fontFamily};;font-size:100%;">
<option tal:condition="python:view.allow_blank" value=""/>
<option tal:condition="python:view.allow_blank" value=""/>
<tal:groups tal:repeat="groupingperiod groups">
<option tal:attributes="
value python:groupingperiod;
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika">

<label i18n:translate="">Instrument</label>
<br/>
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" i18n:domain="bika" tal:attributes="style view/style|nothing">

<label i18n:translate="">Output format</label>
<br/>
Expand Down
@@ -1,4 +1,4 @@
<div class="field" tal:define="
<div class="field" tal:attributes="style view/style|nothing" tal:define="
periods python:['Day', 'Week', 'Month' ]"
i18n:domain="bika">

Expand Down
3 changes: 2 additions & 1 deletion bika/lims/browser/reports/selection_macros/select_profile.pt
@@ -1,4 +1,5 @@
<div class="field" tal:condition="not:here/member_is_client" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing"
tal:condition="not:here/member_is_client" i18n:domain="bika">

<label i18n:translate="">Profile</label>
<br/>
Expand Down
@@ -1,6 +1,6 @@
<!-- This is populated with Javascript, when the Supplier is selected. -->

<div class="field" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika">

<label i18n:translate="">Reference Sample</label>
<br/>
Expand Down
@@ -1,6 +1,6 @@
<!-- This is populated with Javascript, when the ReferenceSample is selected. -->

<div class="field" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika">

<label i18n:translate="">Analysis Service</label>
<br/>
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika">

<label i18n:translate="">Sample point</label>
<br/>
Expand Down
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika">

<label i18n:translate="">Sample type</label>
<br/>
Expand Down
4 changes: 2 additions & 2 deletions bika/lims/browser/reports/selection_macros/select_state.pt
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika">

<label tal:content="view/field_title">Status</label>
<br/>
Expand All @@ -23,4 +23,4 @@

</select>

</div>
</div>
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika">
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika">

<label i18n:translate="">Reference Supplier</label>
<br/>
Expand Down
2 changes: 1 addition & 1 deletion bika/lims/browser/reports/selection_macros/select_user.pt
@@ -1,4 +1,4 @@
<div class="field" i18n:domain="bika"
<div class="field" tal:attributes="style view/style|nothing" i18n:domain="bika"
tal:define="users view/users">

<label i18n:translate="">User</label>
Expand Down
7 changes: 7 additions & 0 deletions tags
@@ -0,0 +1,7 @@
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.9~svn20110310 //
__path__ bika/__init__.py /^ __path__ = extend_path(__path__, __name__)$/;" v

0 comments on commit 99d3e64

Please sign in to comment.