Skip to content
Open
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.7.0 (unreleased)
------------------

- #2931 Fix Laboratory address widget labels for countries with mixed subdivision types
- #2953 Fix IClientAwareMixin interface mismatch breaking client access on DX content
- #2955 Defer workflow transition lookup with a React content-menu component
- #2954 Declare i18n:domain on duration widget templates
Expand Down
9 changes: 9 additions & 0 deletions src/senaite/core/api/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ def get_subdivisions(thing, default=_marker):
# Sort by code
return sorted(subdivisions, key=lambda s: s.code)

def get_subdivision_type(subdivisions, default):
if not subdivisions:
return default

types = set([sub.type for sub in subdivisions])
if len(types) == 1:
return subdivisions[0].type

return default

def get_country_or_subdivision(thing, default=_marker):
"""Returns the country or subdivision for the thing passed-in
Expand Down
15 changes: 8 additions & 7 deletions src/senaite/core/z3cform/widgets/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,19 @@ def get_input_widget_attributes(self):
subdivisions = geo.get_subdivisions(country, [])
sub1[country] = map(lambda sub: sub.name, subdivisions)

label = _("State")
if subdivisions:
label = _(subdivisions[0].type)
state_label = _(u"label_subdivision_state", default=u"State")
label = geo.get_subdivision_type(subdivisions, state_label)
labels[country]["subdivision1"] = translate(label)

subdivision1 = item.get("subdivision1")
if subdivision1 and subdivision1 not in sub2:
subdivisions = geo.get_subdivisions(subdivision1, [])
sub2[subdivision1] = map(lambda sub: sub.name, subdivisions)

label = _("District")
if subdivisions:
label = _(subdivisions[0].type)
district_label = _(
u"label_subdivision_district", default=u"District"
)
label = geo.get_subdivision_type(subdivisions, district_label)
labels[country]["subdivision2"] = translate(label)

attributes = {
Expand Down Expand Up @@ -305,12 +305,13 @@ def __call__(self):
# Extract the subdivisions for this parent
parent = safe_unicode(parent)
items = geo.get_subdivisions(parent, default=[])
subdivision_type = geo.get_subdivision_type(items, "State")

def to_dict(subdivision):
return {
"name": subdivision.name,
"code": subdivision.code,
"type": self.context.translate(_(subdivision.type)),
"type": self.context.translate(_(subdivision_type)),
}
return [to_dict(item) for item in items]

Expand Down
Loading