Commit a3a9021b authored by Zenon Mousmoulas's avatar Zenon Mousmoulas Committed by GitHub

Merge pull request #28 from REANNZ/master-fix-get-service-locations

AllServicePoints: fix MultipleObjectsReturned error
parents f95fd548 3f929377
......@@ -1525,22 +1525,8 @@ def get_all_services(request):
else:
response_location['enc'] = u"-"
response_location['AP_no'] = u"%s" % (sl.AP_no)
try:
response_location['inst'] = sl.institutionid.org_name.get(
lang=lang
).name
except Name_i18n.DoesNotExist:
try:
response_location['inst'] = sl.institutionid.org_name.get(lang='en').name
except Name_i18n.DoesNotExist:
response_location['inst'] = 'unknown'
try:
response_location['name'] = sl.loc_name.get(lang=lang).name
except Name_i18n.DoesNotExist:
try:
response_location['name'] = sl.loc_name.get(lang='en').name
except Name_i18n.DoesNotExist:
response_location['name'] = 'unknown'
response_location['inst'] = get_i18n_name(sl.institutionid.org_name, lang, 'en', 'unknown')
response_location['name'] = get_i18n_name(sl.loc_name, lang, 'en', 'uknown')
response_location['port_restrict'] = u"%s" % (sl.port_restrict)
response_location['transp_proxy'] = u"%s" % (sl.transp_proxy)
response_location['IPv6'] = u"%s" % (sl.IPv6)
......@@ -2359,3 +2345,13 @@ def lookupShibAttr(attrmap, requestMeta):
if len(requestMeta[attr]) > 0:
return requestMeta[attr]
return ''
def get_i18n_name(i18n_name, lang, default_lang='en', default_name='unknown'):
names = i18n_name.filter(lang=lang)
if names.count()==0:
names = i18n_name.filter(lang=default_lang)
if names.count()==0:
return default_name
else:
# follow ServiceLoc.get_name()
return ', '.join([i.name for i in names])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment