Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display batch labels in listing #2350

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.5.0 (unreleased)
------------------

- #2350 Display batch labels in listing
- #2347 Remove unused inline validation view
- #2346 Fix unauthorized error when accessing dispatch/partition sample view with shared client role
- #2343 Allow to define the sorting criteria for Result Options
Expand Down
19 changes: 19 additions & 0 deletions src/bika/lims/browser/batchfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(self, context, request):
("BatchID", {
"title": _("Batch ID"),
"index": "getId", }),
("BatchLabels", {
"title": _("Batch Labels"),
"sortable": False, }),
("Description", {
"title": _("Description"),
"sortable": False, }),
Expand Down Expand Up @@ -156,6 +159,15 @@ def can_add(self):
return False
return True

def to_pretty_label(self, label):
"""Make a pretty label for the given label string

:param label: text batch label
:returns: Bootstrap HTML batch label
"""
tpl = u"<span class='badge badge-secondary mr-1'>{}</span>"
return tpl.format(api.safe_unicode(label))

def folderitem(self, obj, item, index):
"""Applies new properties to the item (Batch) that is currently being
rendered as a row in the list
Expand All @@ -178,6 +190,7 @@ def folderitem(self, obj, item, index):
client = obj.getClient()
created = api.get_creation_date(obj)
date = obj.getBatchDate()
batch_labels = obj.getLabelNames()

# total sample progress
progress = obj.getProgress()
Expand All @@ -191,6 +204,12 @@ def folderitem(self, obj, item, index):
item["replace"]["Title"] = get_link(url, title)
item["created"] = self.ulocalized_time(created, long_format=True)
item["BatchDate"] = self.ulocalized_time(date, long_format=True)
item["BatchLabels"] = ""

if batch_labels:
item["BatchLabels"] = ",".join(batch_labels)
item["replace"]["BatchLabels"] = "".join(map(
self.to_pretty_label, batch_labels))

if client:
client_url = api.get_url(client)
Expand Down