Skip to content

Commit

Permalink
Render unit after result and interim fields (senaite#2134)
Browse files Browse the repository at this point in the history
* Added helper method to render the unit

* Render the unit after the result field

* Render unit after interim fields

* Changelog added
  • Loading branch information
ramonski authored Sep 19, 2022
1 parent 62b538b commit 9829b28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
2.3.0 (unreleased)
------------------

- #2134 Render unit after result and interim fields
- #2129 Fix Traceback when invalidating a Sample with Remarks
- #2128 Fix referenceresults widget view mode
- #2127 Fix instrument expiry date display in listing view
Expand Down
18 changes: 18 additions & 0 deletions src/bika/lims/browser/analyses/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,12 @@ def folderitems(self):

return items

def render_unit(self, unit, css_class="unit small text-secondary"):
"""Render HTML element for unit
"""
return "<span class='{css_class}'>{unit}</span>".format(
unit=unit, css_class=css_class)

def _folder_item_category(self, analysis_brain, item):
"""Sets the category to the item passed in
Expand Down Expand Up @@ -856,6 +862,11 @@ def _folder_item_result(self, analysis_brain, item):
item["CaptureDate"] = capture_date_str
item["result_captured"] = capture_date_str

# Add the unit after the result
unit = item.get("Unit")
if unit:
item["after"]["Result"] = self.render_unit(unit)

# Get the analysis object
obj = self.get_object(analysis_brain)

Expand Down Expand Up @@ -951,11 +962,18 @@ def _folder_item_calculation(self, analysis_brain, item):
continue

interim_value = interim_field.get("value", "")
interim_unit = interim_field.get("unit", "")
interim_formatted = formatDecimalMark(interim_value, self.dmk)
interim_field["formatted_value"] = interim_formatted
item[interim_keyword] = interim_field
item["class"][interim_keyword] = "interim"

# render the unit after the interim field
if interim_unit:
formatted_interim_unit = format_supsub(interim_unit)
item["after"][interim_keyword] = self.render_unit(
formatted_interim_unit)

# Note: As soon as we have a separate content type for field
# analysis, we can solely rely on the field permission
# "senaite.core: Field: Edit Analysis Result"
Expand Down

0 comments on commit 9829b28

Please sign in to comment.