diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index 5f16c4a0be0bfa22ba8fc4fa5f2880c5719a5af4..3cef4f2c222778f991a1c71ce8fd8fdcfb9c1d81 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -168,3 +168,17 @@ def odsh_extract_value_from_extras(extras, key): if 'value' in item: return item['value'] return None + +def license_options(existing_license_id=None): + '''Returns [(l.title, l.id), ...] for the licenses configured to be + offered. Always includes the existing_license_id, if supplied. + ''' + register = model.Package.get_license_register() + licenses = register.values() + license_ids = [license.id for license in licenses] + if existing_license_id and existing_license_id not in license_ids: + license_ids.insert(0, existing_license_id) + return [ + (license_id, + register[license_id].title if license_id in register else license_id) + for license_id in license_ids] diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 1d5701d45d7f6d9df06ad62d97ab88f850fb775f..959331613f035749efe4c998ee733d53f3c64fa6 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -239,7 +239,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'odsh_encodeurl': odsh_helpers.odsh_encodeurl, 'odsh_extract_error': odsh_helpers.odsh_extract_error, 'odsh_extract_value_from_extras': odsh_helpers.odsh_extract_value_from_extras, - 'odsh_create_checksum': odsh_helpers.odsh_create_checksum + 'odsh_create_checksum': odsh_helpers.odsh_create_checksum, + 'presorted_license_options': odsh_helpers.presorted_license_options } def before_map(self, map): diff --git a/ckanext/odsh/templates/package/snippets/package_basic_fields.html b/ckanext/odsh/templates/package/snippets/package_basic_fields.html index 8b67ef94dafecf59e1b7865e5669bd87feeafce8..d803642d5dd64d8dec20da59054cc9b12037fa27 100644 --- a/ckanext/odsh/templates/package/snippets/package_basic_fields.html +++ b/ckanext/odsh/templates/package/snippets/package_basic_fields.html @@ -43,7 +43,7 @@ is_required=true,placeholder=_('Enter title')) }} <div class="controls"> <select id="field-license" name="license_id"> {% set existing_license_id = data.get('license_id') %} - {% for license_id, license_desc in h.license_options(existing_license_id) %} + {% for license_id, license_desc in h.presorted_license_options(existing_license_id) %} <option value="{{ license_id }}" {% if existing_license_id==license_id %}selected="selected" {% endif %}>{{ license_desc }}</option> {% endfor %}