Commit 50992523 authored by Marko Kuder's avatar Marko Kuder
Browse files

podrocja are now implemented differently (more linked to vocab)

- needs rerun of paster custom_tags init!
- podrocja are now not saved as extras, but in package_tag table
parent a0b15f99
......@@ -25,10 +25,10 @@ class CustomTags(CkanCommand):
import ckan.plugins.toolkit as tk
import ckan.model as model
existing = model.Vocabulary.by_name(u'Področja')
existing = model.Vocabulary.by_name('podrocja')
if not existing:
result1 = tk.get_action('vocabulary_create')(
data_dict={'name': u'Področja', 'tags': [
data_dict={'name': 'podrocja', 'tags': [
{'name': u'Energetika'},
{'name': u'Finance in davki'},
{'name': u'Gospodarstvo'},
......
......@@ -33,6 +33,9 @@ ignore = tk.get_validator('ignore')
ignore_empty = tk.get_validator('ignore_empty')
keep_extras = tk.get_validator('keep_extras')
not_missing = tk.get_validator('not_missing')
free_tags_only = tk.get_converter('free_tags_only')
convert_to_tags = tk.get_converter('convert_to_tags')
convert_from_tags = tk.get_converter('convert_from_tags')
geographic_granularity = [('', ''),
('national', 'national'),
......@@ -295,9 +298,7 @@ class DatasetForm(p.SingletonPlugin):
'publish-date': [ignore_missing, date_to_db, convert_to_extras],
'publish-restricted': [ignore_missing, bool_, convert_to_extras],
'podrocje_id': [unicode, convert_to_extras],
'podrocje_name': [ignore_missing, unicode, convert_to_extras],
#'podrocje_in_form': [ignore_missing, unicode],
'podrocje': [unicode, convert_to_tags('podrocja')],
'dostopnost_id': [unicode, convert_to_extras],
'dostopnost_desc': [ignore_missing, unicode, convert_to_extras],
......@@ -346,7 +347,7 @@ class DatasetForm(p.SingletonPlugin):
'__extras': [keep_extras]
},
'tags': {
'__extras': [keep_extras]
'__extras': [keep_extras, free_tags_only]
},
#'kljucne_besede': [ignore_missing, from_json, list_to_comma, convert_from_extras],
......@@ -380,8 +381,7 @@ class DatasetForm(p.SingletonPlugin):
'sla': [convert_from_extras, ignore_missing],
'national_statistic': [convert_from_extras, ignore_missing],
'podrocje_id': [convert_from_extras],
'podrocje_name': [convert_from_extras, ignore_missing],
'podrocje': [convert_from_tags('podrocja')],
'dostopnost_id': [convert_from_extras],
'dostopnost_desc': [convert_from_extras, ignore_missing],
......
......@@ -741,7 +741,7 @@ def get_package_fields(package, package_dict, pkg_extras, dataset_was_harvested,
from ckanext.dgu.schema import GeoCoverageType
from ckanext.dgu.lib.resource_helpers import DatasetFieldNames, DisplayableFields
field_names = DatasetFieldNames(['date_added_to_dgu', 'mandate', 'temporal_coverage', 'geographic_coverage', 'schema', 'codelist', 'sla', 'podrocje_name', 'tag_list', 'kljucne_besede', 'dostopnost_desc', 'povezanost_desc', 'vrsta_pravne_podlage', 'sop_stevilka', 'pogoji_licence'])
field_names = DatasetFieldNames(['date_added_to_dgu', 'mandate', 'temporal_coverage', 'geographic_coverage', 'schema', 'codelist', 'sla', 'podrocje', 'tag_list', 'kljucne_besede', 'dostopnost_desc', 'povezanost_desc', 'vrsta_pravne_podlage', 'sop_stevilka', 'pogoji_licence'])
field_names_display_only_if_value = ['date_update_future', 'precision', 'update_frequency', 'temporal_granularity', 'taxonomy_url', 'data_issued', 'data_modified', 'la-function', 'la-service'] # (mostly deprecated) extra field names, but display values anyway if the metadata is there
if is_an_official():
field_names_display_only_if_value.append('external_reference')
......@@ -818,9 +818,12 @@ def get_package_fields(package, package_dict, pkg_extras, dataset_was_harvested,
mandates = render_mandates(pkg_extras)
#Podrocje!
#podrocje_name = pkg_extras.get('podrocje_name')
podrocje_name = podrocje_id_to_name(pkg_extras.get('podrocje_id', ''))
podrocje_id = pkg_extras.get('podrocje_id')
podrocje = package_dict.get('podrocje', '')
if podrocje:
if isinstance(podrocje, types.ListType):
podrocje = ', '.join(podrocje)
if isinstance(podrocje, types.StringType):
podrocje = unicode(podrocje)
#Dostopnost!
dostopnost_name = dostopnost_id_to_desc(pkg_extras.get('dostopnost_id', ''))
......@@ -878,9 +881,7 @@ def get_package_fields(package, package_dict, pkg_extras, dataset_was_harvested,
'temporal_coverage': {'label': 'Temporal coverage', 'value': temporal_coverage},
#'geographic_coverage': {'label': 'Geographic coverage', 'value': GeoCoverageType.strip_off_binary(pkg_extras.get('geographic_coverage', ''))},
'geographic_coverage': {'label': 'Geographic coverage', 'value': pkg_extras.get('geographic_coverage', '')},
#'podrocje_name': {'label': u'Področje', 'value': pkg_extras.get('podrocje_name', '')},
'podrocje_name': {'label': u'Področje', 'value': podrocje_id_to_name(pkg_extras.get('podrocje_id', '')) },
'podrocje_id': {'label': u'Področje id', 'value': pkg_extras.get('podrocje_id', '')},
'podrocje': {'label': u'Področje', 'value': podrocje},
#'kljucne_besede': {'label': u'Ključne besede', 'value': kljucne_besede_list_to_string(pkg_extras.get('kljucne_besede', ''))},
'kljucne_besede': {'label': u'Ključne besede', 'value': ",".join([t['name'] for t in package_dict.get('tags', [])])},
'dostopnost_desc': {'label': u'Dostopnost podatkov', 'value': dostopnost_id_to_desc(pkg_extras.get('dostopnost_id', '')) },
......@@ -1336,15 +1337,12 @@ def license_choices(data):
#We return option_podrocje_id, podrocje_desc
def podrocje_choices(data):
podrocjeValues = t.get_action('vocabulary_list')()
for i in range(len(podrocjeValues)):
if podrocjeValues[i]['name'].encode('utf8') == u'Področja'.encode('utf8'):
podrocja = []
for j in range(len(podrocjeValues[i]['tags'])):
podrocja.append((podrocjeValues[i]['tags'][j]['id'], podrocjeValues[i]['tags'][j]['name'])) #return id, name
#podrocja.append(podrocjeValues[i]['tags'][j]['name']) #return name
return podrocja
return []
try:
tag_list = t.get_action('tag_list')
podrocja_codes = tag_list(data_dict={'vocabulary_id': 'podrocja'})
return podrocja_codes
except t.ObjectNotFound:
return []
#We return dostopnost_option_id, dostopnost_desc
def dostopnost_choices(data):
......@@ -1362,7 +1360,7 @@ def dostopnost_choices(data):
def podrocje_id_to_name(id):
podrocjeValues = t.get_action('vocabulary_list')()
for i in range(len(podrocjeValues)):
if podrocjeValues[i]['name'].encode('utf8') == u'Področja'.encode('utf8'):
if podrocjeValues[i]['name'] == 'podrocja':
for j in range(len(podrocjeValues[i]['tags'])):
if podrocjeValues[i]['tags'][j]['id'] == id:
return podrocjeValues[i]['tags'][j]['name']
......
......@@ -153,22 +153,21 @@ Passed in:
<br/>
<div class="form-group">
<label for="podrocje_id">Področje:</label>
<label for="podrocje">Področje:</label>
<p class="instructions basic">Izberite področje, povezano s to zbirko podatkov.</p>
{# We have to convert podrocje_id into podrocje_name in helpers.py #}
{% set podrocje_id = data.get('podrocje_id') %}
<select class="form-control" id="podrocje_id" name="podrocje_id">
<option value=" " {% if not podrocje_id %}selected="selected"{% endif %} >Izberite področje...</option>
{% for podrocje_option_id, podrocje_option_name in h.podrocje_choices(data) %}
<option value="{{podrocje_option_id}}" {% if podrocje_id == podrocje_option_id %}selected="selected" {% endif %} >
{{podrocje_option_name}}
{% set podrocje = data.get('podrocje') %}
<select class="form-control" id="podrocje" name="podrocje">
<option value=" " {% if not podrocje %}selected="selected"{% endif %} >Izberite področje...</option>
{% for podrocje_option in h.podrocje_choices(data) %}
<option value="{{podrocje_option}}" {% if podrocje_option in data.get('podrocje', []) %}selected="selected" {% endif %} >
{{podrocje_option}}
</option>
{% endfor %}
</select>
</div>
{{ m.display_error(errors, 'podrocje_id', True, 'Izberite Področje') }}
{{ m.display_error(errors, 'podrocje', True, 'Izberite Področje') }}
<!-- GREM NAZAJ NA PREJŠNJO REŠITEV, SPODAJ
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment