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

Fix dynamic analysis specification listing error for empty excel columns (1.3.x) #1825

Merged
merged 3 commits into from
Jul 8, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
1.3.5 (unreleased)
------------------

- #1825 Fix TypeError when creating Dynamic Analysis Specifications
- #1825 Fix dynamic analysis specification listing error for empty excel columns
- #1822 API support for supermodel objects
- #1818 Fix rejection report is attached as a ".bin" file in notification email
- #1816 Fix duplicated rejection reasons in rejection viewlet (sample view)
Expand Down
15 changes: 12 additions & 3 deletions bika/lims/browser/dynamic_analysisspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import collections

import six

from bika.lims import _
from bika.lims import api
from senaite.core.listing.view import ListingView
Expand Down Expand Up @@ -68,7 +70,7 @@ def update(self):
def before_render(self):
super(DynamicAnalysisSpecView, self).before_render()

def make_empty_item(self, **kw):
def make_empty_item(self, record):
"""Create a new empty item
"""
item = {
Expand All @@ -80,11 +82,18 @@ def make_empty_item(self, **kw):
"disabled": False,
"state_class": "state-active",
}
item.update(**kw)
for k, v in record.items():
# ensure keyword dictionary keys contains only strings
if not self.is_string(k):
continue
item[k] = v
return item

def is_string(self, value):
return isinstance(value, six.string_types)

def folderitems(self):
items = []
for record in self.specs:
items.append(self.make_empty_item(**record))
items.append(self.make_empty_item(record))
return items
6 changes: 4 additions & 2 deletions bika/lims/content/dynamic_analysisspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ def validate_sepecs_file(data):
"Please upload an Excel spreadsheet with at least "
"the following columns defined: '{}'"
.format(", ".join(REQUIRED_COLUMNS))))

try:
header = map(lambda c: c.value, xls.worksheets[0].rows[0])
except IndexError:
header_row = xls.worksheets[0].rows.next()
header = map(lambda c: c.value, header_row)
except (IndexError, AttributeError):
raise Invalid(
_("First sheet does not contain a valid column definition"))
for col in REQUIRED_COLUMNS:
Expand Down