Skip to content

Commit

Permalink
Fix dynamic analysis specification listing error for empty excel colu…
Browse files Browse the repository at this point in the history
…mns (1.3.x) (#1825)

* Fix dynamic analysis specification listing error for empty excel columns

* Fix TypeError while creating Dynamic Analysis Specs

```
ERROR Zope.SiteErrorLog 1625760797.610.228053622856 http://localhost:9090/senaite/bika_setup/dynamic_analysisspecs/++add++DynamicAnalysisSpec
Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.z3cform.layout, line 66, in __call__
  Module plone.z3cform.layout, line 50, in update
  Module plone.dexterity.browser.add, line 118, in update
  Module plone.z3cform.fieldsets.extensible, line 59, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 145, in update
  Module plone.app.z3cform.csrf, line 21, in execute
  Module z3c.form.action, line 98, in execute
  Module z3c.form.button, line 315, in __call__
  Module z3c.form.button, line 170, in __call__
  Module plone.dexterity.browser.add, line 97, in handleAdd
  Module z3c.form.group, line 98, in extractData
  Module z3c.form.form, line 148, in extractData
  Module z3c.form.field, line 324, in extract
  Module z3c.form.field, line 216, in validate
  Module z3c.form.validator, line 201, in validate
  Module z3c.form.validator, line 206, in validateObject
  Module zope.interface.interface, line 590, in validateInvariants
  Module bika.lims.content.dynamic_analysisspec, line 69, in validate_sepecs_file
TypeError: 'generator' object has no attribute '__getitem__'
```

* Changelog
  • Loading branch information
xispa committed Jul 8, 2021
1 parent 8941835 commit 34fb032
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
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

0 comments on commit 34fb032

Please sign in to comment.