Skip to content
Snippets Groups Projects
Commit 452a491e authored by chbaeh's avatar chbaeh
Browse files

add remaining fields

parent f813c0c7
Branches
Tags
No related merge requests found
...@@ -16,14 +16,15 @@ ckan.module('odsh_form', function ($) ...@@ -16,14 +16,15 @@ ckan.module('odsh_form', function ($)
// toggle input for 'Namensgebung' depending on the selected licence // toggle input for 'Namensgebung' depending on the selected licence
// TODO: this implementation should be more generic // TODO: this implementation should be more generic
var id = '#field-license'; var id = '#field-license';
var id_name = '#field-licenseAttributionByText-value';
var toggle = function () var toggle = function ()
{ {
if ($(id).val().indexOf('dl-by-de/2.0') !== -1) if ($(id).val().indexOf('dl-by-de/2.0') !== -1)
{ {
$('#field-licence-name').prop('disabled', false); $(id_name).prop('disabled', false);
} else } else
{ {
$('#field-licence-name').prop('disabled', true); $(id_name).prop('disabled', true);
} }
} }
toggle(id) toggle(id)
......
...@@ -128,5 +128,5 @@ def odsh_extract_value_from_extras(extras, key): ...@@ -128,5 +128,5 @@ def odsh_extract_value_from_extras(extras, key):
if not extras: if not extras:
return None return None
for item in extras: for item in extras:
if 'key' in item and item['key'].lower() == key: if 'key' in item and item['key'].lower() == key.lower():
return item['value'] return item['value']
No preview for this file type
...@@ -165,16 +165,19 @@ msgstr "Dateien" ...@@ -165,16 +165,19 @@ msgstr "Dateien"
msgid "Spatial uri" msgid "Spatial uri"
msgstr "Raumbezug" msgstr "Raumbezug"
msgid "Spatial uri: The specified URI is not known" msgid "odsh_spatial_uri_unknown_error_label"
msgstr "Der räumliche Bezug is ungültig" msgstr "Der räumliche Bezug is ungültig"
msgid "Spatial uri: Fehlender Wert" msgid "odsh_spatial_uri_error_label"
msgstr "Bitte geben Sie einen räumlichen Bezug an" msgstr "Bitte geben Sie einen räumlichen Bezug an"
msgid "Beginn des Zeitraumes: Fehlender Wert" msgid "odsh_temporal_start_error_label"
msgstr "Bitte wählen Sie einen Beginn des Zeitraumes aus" msgstr "Bitte wählen Sie einen Beginn des Zeitraumes aus"
msgid "Ende des Zeitraumes: Fehlender Wert" msgid "odsh_temporal_end_error_label"
msgstr "Bitte wählen Sie ein Ende des Zeitraumes aus"
msgid "odsh_temporal_error_label"
msgstr "Bitte wählen Sie einen Zeitraum aus" msgstr "Bitte wählen Sie einen Zeitraum aus"
msgid "Name: Fehlender Wert" msgid "Name: Fehlender Wert"
......
...@@ -74,7 +74,13 @@ def odsh_group_id_selected(selected, group_id): ...@@ -74,7 +74,13 @@ def odsh_group_id_selected(selected, group_id):
return False return False
def known_spatial_uri(key, data, errors, context): def known_spatial_uri(key, data, errors, context):
value = _extract_value(key, data, 'spatial_uri')
if not value:
raise toolkit.Invalid('spatial_uri:odsh_spatial_uri_error_label')
mapping_file = config.get('ckanext.odsh.spatial.mapping') mapping_file = config.get('ckanext.odsh.spatial.mapping')
try: try:
mapping_file = urllib2.urlopen(mapping_file) mapping_file = urllib2.urlopen(mapping_file)
...@@ -86,14 +92,14 @@ def known_spatial_uri(key, data, errors, context): ...@@ -86,14 +92,14 @@ def known_spatial_uri(key, data, errors, context):
spatial = str() spatial = str()
cr = csv.reader(mapping_file, delimiter="\t") cr = csv.reader(mapping_file, delimiter="\t")
for row in cr: for row in cr:
if row[0] == data[key]: if row[0].encode('UTF-8') == value:
not_found = False not_found = False
spatial_text = row[1] spatial_text = row[1]
loaded = json.loads(row[2]) loaded = json.loads(row[2])
spatial = json.dumps(loaded['geometry']) spatial = json.dumps(loaded['geometry'])
break break
if not_found: if not_found:
raise toolkit.Invalid("The specified URI is not known") raise toolkit.Invalid('spatial_uri:odsh_spatial_uri_unknown_error_label')
# Get the current extras index # Get the current extras index
current_indexes = [k[1] for k in data.keys() current_indexes = [k[1] for k in data.keys()
...@@ -106,6 +112,7 @@ def known_spatial_uri(key, data, errors, context): ...@@ -106,6 +112,7 @@ def known_spatial_uri(key, data, errors, context):
data[('extras', new_index+1, 'key')] = 'spatial' data[('extras', new_index+1, 'key')] = 'spatial'
data[('extras', new_index+1, 'value')] = spatial data[('extras', new_index+1, 'value')] = spatial
def _extract_value(key, data, field): def _extract_value(key, data, field):
key = None key = None
for k in data.keys(): for k in data.keys():
...@@ -118,17 +125,20 @@ def _extract_value(key,data,field): ...@@ -118,17 +125,20 @@ def _extract_value(key,data,field):
return data[(key[0], key[1], 'value')] return data[(key[0], key[1], 'value')]
def odsh_validate_issued(key, data, errors, context): def odsh_validate_extra_date(key, field, data, errors, context):
value = _extract_value(key,data,'issued') value = _extract_value(key, data, field)
if not value: if not value:
raise toolkit.Invalid('issued:odsh_issued_error_label') raise toolkit.Invalid(field+':odsh_'+field+'_error_label')
try: try:
datetime.datetime.strptime(value, '%Y-%m-%d') datetime.datetime.strptime(value, '%Y-%m-%d')
except ValueError: except ValueError:
raise toolkit.Invalid('issued:odsh_issued_not_date_error_label') raise toolkit.Invalid(field+':odsh_'+field+'_not_date_error_label')
def odsh_validate_extra_date_factory(field):
return lambda key, data, errors, context: odsh_validate_extra_date(key, field, data, errors, context)
def odsh_tag_name_validator(value, context): def odsh_tag_name_validator(value, context):
...@@ -274,24 +284,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -274,24 +284,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def _fields(self): def _fields(self):
return ['title', 'notes'] return ['title', 'notes']
def _extraFields(self):
return ['temporal_start', 'temporal_end', 'spatial_uri', 'licenseAttributionByText']
def _update_schema(self, schema): def _update_schema(self, schema):
for field in self._extraFields():
if field == 'licenseAttributionByText':
schema.update({field: [
toolkit.get_validator('ignore_missing'),
toolkit.get_converter('convert_to_extras')]})
elif field == 'spatial_uri':
schema.update({field: [
toolkit.get_converter('not_empty'),
toolkit.get_converter('known_spatial_uri'),
toolkit.get_converter('convert_to_extras')]})
else:
schema.update({field: [
toolkit.get_converter('not_empty'),
toolkit.get_converter('convert_to_extras')]})
for field in self._fields(): for field in self._fields():
schema.update({field: [toolkit.get_converter('not_empty')]}) schema.update({field: [toolkit.get_converter('not_empty')]})
...@@ -309,10 +302,14 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -309,10 +302,14 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
}) })
schema['extras'].update({ schema['extras'].update({
'key': [toolkit.get_converter('odsh_validate_issued')] 'key': [
toolkit.get_converter('odsh_validate_issued'),
toolkit.get_converter('odsh_validate_temporal_start'),
toolkit.get_converter('odsh_validate_temporal_end'),
toolkit.get_converter('known_spatial_uri'),
]
}) })
def create_package_schema(self): def create_package_schema(self):
schema = super(OdshPlugin, self).create_package_schema() schema = super(OdshPlugin, self).create_package_schema()
self._update_schema(schema) self._update_schema(schema)
...@@ -325,10 +322,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -325,10 +322,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def show_package_schema(self): def show_package_schema(self):
schema = super(OdshPlugin, self).show_package_schema() schema = super(OdshPlugin, self).show_package_schema()
for field in self._extraFields():
schema.update({
field: [toolkit.get_converter('convert_from_extras')]
})
return schema return schema
def is_fallback(self): def is_fallback(self):
...@@ -344,7 +337,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -344,7 +337,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def get_validators(self): def get_validators(self):
return {'odsh_convert_groups_string': odsh_convert_groups_string, return {'odsh_convert_groups_string': odsh_convert_groups_string,
'known_spatial_uri': known_spatial_uri, 'known_spatial_uri': known_spatial_uri,
'odsh_validate_issued': odsh_validate_issued, 'odsh_validate_issued': odsh_validate_extra_date_factory('issued'),
'odsh_validate_temporal_start': odsh_validate_extra_date_factory('temporal_start'),
'odsh_validate_temporal_end': odsh_validate_extra_date_factory('temporal_end'),
'odsh_tag_name_validator': odsh_tag_name_validator} 'odsh_tag_name_validator': odsh_tag_name_validator}
def extend_search_convert_local_to_utc_timestamp(self, str_timestamp): def extend_search_convert_local_to_utc_timestamp(self, str_timestamp):
......
...@@ -53,9 +53,11 @@ is_required=false) %} ...@@ -53,9 +53,11 @@ is_required=false) %}
{% endcall %} {% endcall %}
{% endmacro %} {% endmacro %}
{% macro input_extra(field, value='', index='') %} {% macro input_extra(field, value='', index='', placeholder='', type='text', attrs={}) %}
{%- set _type = 'text' if type=='date' and not value else type -%}
{%- set onFocus = 'onfocus=(this.type=\'date\')' if type=='date' and not value else '' -%}
<input id="field-{{field}}-key" type="hidden" name="extras__{{index}}__key" value="{{field}}" /> <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}}" /> <input id="field-{{field}}-value" type="{{_type}}" name="extras__{{index}}__value" value="{{value | empty_and_escape }}" placeholder="{{ placeholder }}" {{ onFocus }} {{ attributes(attrs) }}/>
{% endmacro %} {% endmacro %}
{# {#
......
...@@ -44,7 +44,8 @@ Example: ...@@ -44,7 +44,8 @@ Example:
<div class="license-detail info-detail"> <div class="license-detail info-detail">
<div>{{ _('License') }}:</div> <div>{{ _('License') }}:</div>
{%set lic=pkg.license_title if pkg.license_title else '-'%} {%set lic=pkg.license_title if pkg.license_title else '-'%}
{%set name=' (' + pkg.licenseAttributionByText +')' if pkg.licenseAttributionByText else ''%} {%set licenseAttributionByText = h.odsh_extract_value_from_extras(pkg.extras,'licenseAttributionByText') %}
{%set name=' (' + licenseAttributionByText +')' if licenseAttributionByText else ''%}
<p>{{ lic }}{{ name }}</p> <p>{{ lic }}{{ name }}</p>
</div> </div>
{% endblock %} {% endblock %}
...@@ -52,8 +53,10 @@ Example: ...@@ -52,8 +53,10 @@ Example:
{% block timerange %} {% block timerange %}
<div class="timerange-detail info-detail"> <div class="timerange-detail info-detail">
<div>{{ _('timerange') }}:</div> <div>{{ _('timerange') }}:</div>
{%set start=h.odsh_render_datetime(pkg.temporal_start) if pkg.temporal_start else ''%} {% set temporal_start = h.odsh_extract_value_from_extras(pkg.extras,'temporal_start') %}
{%set end=h.odsh_render_datetime(pkg.temporal_end) if pkg.temporal_end else ''%} {% set temporal_end = h.odsh_extract_value_from_extras(pkg.extras,'temporal_end') %}
{%set start=h.odsh_render_datetime(temporal_start) if temporal_start else ''%}
{%set end=h.odsh_render_datetime(temporal_end) if temporal_end else ''%}
<p>{{ start }} - {{ end }}</p> <p>{{ start }} - {{ end }}</p>
</div> </div>
{% endblock %} {% endblock %}
......
...@@ -54,11 +54,15 @@ is_required=true,placeholder=_('Enter title')) }} ...@@ -54,11 +54,15 @@ is_required=true,placeholder=_('Enter title')) }}
</div> </div>
<div class='span3'> <div class='span3'>
<!-- field Namensnennung --> <!-- field Namensnennung -->
{{ form.input_raw('licenseAttributionByText', id='field-licence-name', value=data.licenseAttributionByText, {% set field = 'licenseAttributionByText' %}
error=errors.licenseAttributionByText, {% set value = h.odsh_extract_value_from_extras(data.extras,field) %}
classes=['control-full'],type='text',is_required=true,attrs={'disabled':true, <div class="control-group {{ " error" if error }} control-full">
<div class="controls">
{{ form.input_extra(field, value=value, index=h.odsh_create_checksum(field), type='text', attrs={'disabled':true,
'data-module':"odsh_form", 'data-module-licensetoggle':'true' }, placeholder=_('enter name')) }} 'data-module':"odsh_form", 'data-module-licensetoggle':'true' }, placeholder=_('enter name')) }}
</div> </div>
</div>
</div>
<div class="span6 inline-error"> <div class="span6 inline-error">
{{error}} {{error}}
</div> </div>
...@@ -67,47 +71,57 @@ is_required=true,placeholder=_('Enter title')) }} ...@@ -67,47 +71,57 @@ is_required=true,placeholder=_('Enter title')) }}
{% endblock %} {% endblock %}
<!-- timerange --> <!-- timerange -->
{% set error_string = _(_('Temporal end') + ': '+errors.temporal_end[0]) if errors.temporal_end %} {% set error_start = h.odsh_extract_error('temporal_start', errors) %}
{% set error_end = h.odsh_extract_error('temporal_end', errors) %}
{% set error_string = 'odsh_temporal_error_label' if error_start and error_end else (error_start if error_start else (error_end if error_end))%}
<label for="start-end" class="control-label">{{ _('timerange') }}: <label for="start-end" class="control-label">{{ _('timerange') }}:
<span title="{{ _("This field is required") }}" class="control-required">*</span> <span title="{{ _("This field is required") }}" class="control-required">*</span>
</label> </label>
<div class='row-fluid'> <div class='row-fluid'>
<div id='start-end' class='span3'> <div id='start-end' class='span3'>
<!-- field temporal_start --> <!-- field temporal_start -->
{% set temporal_start_label=_('odsh_temporal_start_label') %} {% set field = 'temporal_start' %}
{% set data_temporal_start = data.temporal_start.split('T')[0] if data.temporal_start else None %} {% set data_temporal_start = h.odsh_extract_value_from_extras(data.extras,field) %}
{{ form.input_raw('temporal_start', id='field-temporal-start', value=data_temporal_start, {% set value = data_temporal_start.split('T')[0] if data_temporal_start else None %}
error=errors.temporal_start, <div class="control-group {{ " error" if error_start }} control-full">
classes=['control-full'],type='date',is_required=true,placeholder=_('from')) <div class="controls">
}} {{ form.input_extra(field, value=value, index=h.odsh_create_checksum(field), type='date', placeholder=_('from')) }}
</div>
</div>
</div> </div>
<div class='span3'> <div class='span3'>
<!-- field temporal_end --> <!-- field temporal_end -->
{% set temporal_end_label='Ende des Zeitraumes' %} {% set field = 'temporal_end' %}
{% set data_temporal_end = data.temporal_end.split('T')[0] if data.temporal_end else None %} {% set data_temporal_end = h.odsh_extract_value_from_extras(data.extras,field) %}
{{ form.input_raw('temporal_end', id='field-temporal-end', value=data_temporal_end, {% set value = data_temporal_end.split('T')[0] if data_temporal_end else None %}
error=errors.temporal_end, classes=['control-full'],type='date',is_required=true, placeholder=_('to')) <div class="control-group {{ " error" if error_end }} control-full">
}} <div class="controls">
{{ form.input_extra(field, value=value, index=h.odsh_create_checksum(field), type='date', placeholder=_('to')) }}
</div>
</div> </div>
</div>
{% if error_string %}
<div class="span6 inline-error"> <div class="span6 inline-error">
{{error_string}} {{_(error_string)}}
</div> </div>
{% endif %}
</div> </div>
<!-- field issued --> <!-- field issued -->
{% set field = 'issued' %} {% set field = 'issued' %}
{% set value = h.odsh_extract_value_from_extras(data.extras,field) %} {% set value = h.odsh_extract_value_from_extras(data.extras,field) %}
<div class="control-group control-full"> {% set error = h.odsh_extract_error(field, errors) %}
<div class="control-group {{ " error" if error }} control-full">
<label class="control-label" for="field-{{field}}">Veröffentlichungsdatum: <span title="Dieses Feld ist erforderlich" class="control-required">*</span> </label> <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="controls">
<div class="row-fluid"> <div class="row-fluid">
<div class="span6"> <div class="span6">
{{ form.input_extra(field, value=value if value else h.odsh_now(), index=h.odsh_create_checksum(field)) }} {{ form.input_extra(field, value=value if value else h.odsh_now(), index=h.odsh_create_checksum(field), type='date') }}
</div> </div>
<div class="span6 inline-error"> <div class="span6 inline-error">
{% if h.odsh_extract_error(field, errors) %} {% if error %}
{{_(h.odsh_extract_error(field, errors))}} {{_(error)}}
{% endif %} {% endif %}
</div> </div>
</div> </div>
...@@ -168,11 +182,24 @@ is_required=true,placeholder=_('Enter title')) }} ...@@ -168,11 +182,24 @@ is_required=true,placeholder=_('Enter title')) }}
{% endblock %} {% endblock %}
<!-- field spatial_uri --> <!-- field spatial_uri -->
{% set error_string = _('Spatial uri' + ': '+errors.spatial_uri[0]) if errors.spatial_uri%} {% set field = 'spatial_uri' %}
{{ form.input('spatial_uri', id='field-spatial-uri', label=_('Spatial uri'), {% set value = h.odsh_extract_value_from_extras(data.extras,field) %}
value=data.spatial_uri, {% set error = h.odsh_extract_error(field, errors) %}
error=error_string, classes=['control-full'],type='text',is_required=true, <div class="control-group {{ " error" if error }} control-full">
placeholder=_('Enter spatial uri')) }} <label class="control-label" for="field-{{field}}">{{_('Spatial uri')}}: <span title="Dieses Feld ist erforderlich" class="control-required">*</span> </label>
<div class="controls">
<div class="row-fluid">
<div class="span6">
{{ form.input_extra(field, value=value, index=h.odsh_create_checksum(field), type='text', placeholder=_('Enter spatial uri')) }}
</div>
<div class="span6 inline-error">
{% if error %}
{{_(error)}}
{% endif %}
</div>
</div>
</div>
</div>
<!-- field private --> <!-- field private -->
<div class="control-group"> <div class="control-group">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment