From ab1c041ff93f5be1d1cc9f7d6fee855673471ac9 Mon Sep 17 00:00:00 2001 From: Fredrik Larsen Date: Mon, 9 Jan 2023 15:41:26 +0100 Subject: [PATCH] Fix issue with `ou info` (address country) If an OU address contains a country field, the `ou info` bofhd command will fail. This is because we try to use the country code constant number in the output, when we *should* look up the country code string. This doesn't really happen much, as pretty much only old, invalid org units contains country codes... --- Cerebrum/modules/bofhd/bofhd_ou_cmds.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Cerebrum/modules/bofhd/bofhd_ou_cmds.py b/Cerebrum/modules/bofhd/bofhd_ou_cmds.py index 82ca129df..02c7b0217 100644 --- a/Cerebrum/modules/bofhd/bofhd_ou_cmds.py +++ b/Cerebrum/modules/bofhd/bofhd_ou_cmds.py @@ -21,7 +21,6 @@ from __future__ import unicode_literals import logging -import re import six @@ -348,11 +347,19 @@ def ou_info(self, operator, target): 'from_ou': from_ou_str.format(it_contact['from_ou_id']) }) - for a in ou.get_entity_address(): - if a['country'] is not None: - a['country'] = ', ' + a['country'] - else: + for row in ou.get_entity_address(): + a = dict(row) + # TODO: This "breaks" our structured output, should reconsider... + # + # If we are to pre-format fields like this, we should really just + # return an additinal formatted address line for the format + # suggestion, rather than messing with partially formatted fields + # prefixed with ', ' + if a['country'] is None: a['country'] = '' + else: + a['country'] = ', ' + six.text_type( + self.const.Country(a['country'])) if a['p_o_box'] is not None: a['p_o_box'] = "PO box %s, " % a['p_o_box']