Skip to content
Snippets Groups Projects
Commit 352a78e3 authored by Dennis's avatar Dennis
Browse files

uses sorting in licenses.json instead of alphabetical order

parent 3d087533
No related branches found
No related tags found
No related merge requests found
......@@ -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]
......@@ -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):
......
......@@ -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 %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment