Skip to content
Snippets Groups Projects
Commit a05b9a2b authored by anonymous's avatar anonymous
Browse files

uses sorting in licenses.json instead of alphabetical order

parent beded57d
Branches
Tags
No related merge requests found
...@@ -168,3 +168,17 @@ def odsh_extract_value_from_extras(extras, key): ...@@ -168,3 +168,17 @@ def odsh_extract_value_from_extras(extras, key):
if 'value' in item: if 'value' in item:
return item['value'] return item['value']
return None 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]
...@@ -239,7 +239,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -239,7 +239,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
'odsh_encodeurl': odsh_helpers.odsh_encodeurl, 'odsh_encodeurl': odsh_helpers.odsh_encodeurl,
'odsh_extract_error': odsh_helpers.odsh_extract_error, 'odsh_extract_error': odsh_helpers.odsh_extract_error,
'odsh_extract_value_from_extras': odsh_helpers.odsh_extract_value_from_extras, '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): def before_map(self, map):
......
...@@ -43,7 +43,7 @@ is_required=true,placeholder=_('Enter title')) }} ...@@ -43,7 +43,7 @@ is_required=true,placeholder=_('Enter title')) }}
<div class="controls"> <div class="controls">
<select id="field-license" name="license_id"> <select id="field-license" name="license_id">
{% set existing_license_id = data.get('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" {% <option value="{{ license_id }}" {% if existing_license_id==license_id %}selected="selected" {%
endif %}>{{ license_desc }}</option> endif %}>{{ license_desc }}</option>
{% endfor %} {% endfor %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment