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

Move parts of extra-field handling into macro, compute hash for index

parent 7ad7263d
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import datetime
from dateutil import parser
from ckan.common import config
import urllib
import hashlib
get_action = logic.get_action
log = logging.getLogger(__name__)
......@@ -109,6 +110,10 @@ def odsh_upload_known_formats():
def odsh_encodeurl(url):
return urllib.quote(url, safe='')
def odsh_create_checksum(in_string):
hashstring = hashlib.md5(in_string.encode('utf-8')).hexdigest()
return int(hashstring, base=16)
def odsh_extract_error(key, errors):
if not errors or not ('extras' in errors):
return None
......
......@@ -74,7 +74,6 @@ def odsh_group_id_selected(selected, group_id):
return False
def known_spatial_uri(key, data, errors, context):
mapping_file = config.get('ckanext.odsh.spatial.mapping')
try:
......@@ -204,7 +203,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
'odsh_upload_known_formats': odsh_helpers.odsh_upload_known_formats,
'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_extract_value_from_extras': odsh_helpers.odsh_extract_value_from_extras,
'odsh_create_checksum': odsh_helpers.odsh_create_checksum
}
def before_map(self, map):
......
......@@ -53,6 +53,11 @@ is_required=false) %}
{% endcall %}
{% endmacro %}
{% macro input_extra(field, value='', index='') %}
<input id="field-{{field}}-key" type="hidden" name="extras__{{index}}__key" value="{{field}}" />
<input id="field-{{field}}-value" type="text" name="extras__{{index}}__value" value="{{value}}" />
{% endmacro %}
{#
Builds a single checkbox input.
......
......@@ -98,16 +98,12 @@ is_required=true,placeholder=_('Enter title')) }}
{% set field = 'issued' %}
{% set value = h.odsh_extract_value_from_extras(data.extras,field) %}
{% set value_extras = value if value else h.odsh_now() %}
{% set index = 4 %}
<div class="control-group control-full">
<label class="control-label" for="field-{{field}}">Veröffentlichungsdatum: <span title="Dieses Feld ist erforderlich" class="control-required">*</span> </label>
<div class="controls">
<div class="row-fluid">
<div class="span6">
<input id="field-{{field}}-key" type="hidden" name="extras__{{index}}__key" value="{{field}}" />
<input id="field-{{field}}-value" type="text" name="extras__{{index}}__value" value="{{value_extras}}" />
{{ form.input_extra(field, value=value if value else h.odsh_now(), index=h.odsh_create_checksum(field)) }}
</div>
<div class="span6 inline-error">
{% if h.odsh_extract_error(field, errors) %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment