Commit 1ccdfc63 authored by Tom Mortimer-Jones's avatar Tom Mortimer-Jones
Browse files

Add a technical documentation field

parent 6ef7fae6
......@@ -274,6 +274,7 @@ class DatasetForm(p.SingletonPlugin):
'published_via': [ignore_missing, unicode, convert_to_extras],
'mandate': [ignore_missing, remove_blanks, to_json, convert_to_extras],
'technical_docs': [ignore_missing, remove_blanks, to_json, convert_to_extras],
'license_id': [unicode],
'access_constraints': [ignore_missing, unicode],
......@@ -351,6 +352,7 @@ class DatasetForm(p.SingletonPlugin):
'published_via': [convert_from_extras, ignore_missing],
'mandate': [convert_from_extras, from_json, ignore_missing],
'technical_docs': [convert_from_extras, from_json, ignore_missing],
'national_statistic': [convert_from_extras, ignore_missing],
'theme-primary': [convert_from_extras, ignore_missing],
'theme-secondary': [convert_from_extras, ignore_missing],
......@@ -714,7 +714,7 @@ def get_package_fields(package, pkg_extras, dataset_was_harvested,
from ckanext.dgu.lib.resource_helpers import DatasetFieldNames, DisplayableFields
from ckanext.dgu.schema import THEMES
field_names = DatasetFieldNames(['date_added_to_dgu', 'mandate', 'temporal_coverage', 'geographic_coverage'])
field_names = DatasetFieldNames(['date_added_to_dgu', 'mandate', 'technical-docs', 'temporal_coverage', 'geographic_coverage'])
field_names_display_only_if_value = ['date_update_future', 'precision', 'update_frequency', 'temporal_granularity', 'taxonomy_url', 'data_modified'] # (mostly deprecated) extra field names, but display values anyway if the metadata is there
if is_an_official():
......@@ -794,23 +794,36 @@ def get_package_fields(package, pkg_extras, dataset_was_harvested,
secondary_themes = unicode(secondary_themes)
secondary_themes = THEMES.get(secondary_themes,
def linkify(string):
if string.startswith('http://') or string.startswith('https://'):
return '<a href="%s" target="_blank">%s</a>' % (string, string)
return string
mandates = pkg_extras.get('mandate')
if mandates:
def linkify(string):
if string.startswith('http://') or string.startswith('https://'):
return '<a href="%s" target="_blank">%s</a>' % (string, string)
return string
mandates = json.loads(mandates)
if not isinstance(mandates, list):
mandates = [mandates]
mandates = [Markup.escape(m) for m in mandates]
mandates = [linkify(m) for m in mandates]
mandates = Markup("<br>".join(mandates))
except ValueError:
pass # Not JSON for some reason...
technical_docs = pkg_extras.get('technical_docs')
if technical_docs:
technical_docs = json.loads(technical_docs)
if not isinstance(technical_docs, list):
technical_docs = [technical_docs]
technical_docs = [Markup.escape(m) for m in technical_docs]
technical_docs = [linkify(m) for m in technical_docs]
technical_docs = Markup("<br>".join(technical_docs))
except ValueError:
pass # Not JSON for some reason...
field_value_map = {
# field_name : {display info}
'date_added_to_dgu': {'label': 'Added to', 'value': package.metadata_created.strftime('%d/%m/%Y')},
......@@ -833,6 +846,7 @@ def get_package_fields(package, pkg_extras, dataset_was_harvested,
'theme': {'label': 'Theme', 'value': primary_theme},
'theme-secondary': {'label': 'Themes (secondary)', 'value': secondary_themes},
'mandate': {'label': 'Mandate', 'value': mandates},
'technical-docs': {'label': 'Technical Documentation', 'value': technical_docs},
'metadata-language': {'label': 'Metadata language', 'value': pkg_extras.get('metadata-language', '').replace('eng', 'English')},
'metadata-date': {'label': 'Metadata date', 'value': DateType.db_to_form(pkg_extras.get('metadata-date', ''))},
'dataset-reference-date': {'label': 'Dataset reference date', 'value': dataset_reference_date},
......@@ -2124,3 +2138,12 @@ def get_mandate_list(data):
if not isinstance(mandate, list):
log.error('Mandate should be a list: %r', mandate)
return mandate
def get_technical_docs_list(data):
technical_docs = data.get('technical_docs') or []
if isinstance(technical_docs, basestring):
# this is the case when only one <input> is on the form
return [technical_docs]
if not isinstance(technical_docs, list):
log.error('Technical docs should be a list: %r', technical_docs)
return technical_docs
......@@ -1397,6 +1397,7 @@ body.controller-package.action-edit {
.resource-url .error input {
background: transparent url(../images/icons/error.png) 98% center no-repeat;
#mandates-list {
list-style: none;
margin-left: 0;
......@@ -88,6 +88,18 @@
return false;
$('#technical-docs-add').click(function(e) {
var list = $('#technical-docs-list');
var new_doc = list.children().first().clone();
new_doc.children().first().attr('value', '');
return false;
// Correctly handle disabled nav buttons
$('a.disabled').click(function(e) {
......@@ -602,7 +602,7 @@ Passed in:
<span class="checking-links-label" style="display: none;">Checking, please wait...</span>
<div class="well form-inline">
<div class="well clearfix">
<p class="instructions basic">The law (or other public commitment) that caused the data to be collected (if appropriate).</p>
<p>For example, civil servants' salaries are recorded because of Public Record Act 1958 s.2, for which you would put: <a href="" target="_blank"></a></p>
......@@ -618,6 +618,19 @@ Passed in:
<div class="well clearfix">
<h3>Technical Documentation</h3>
<p class="instructions basic">Please provide links to where users of this data can find technical documentation to support their use of this data.</p>
<div class="form-group">
{%- set technical_docs = h.get_technical_docs_list(data) or [''] -%}
<ul id="technical-docs-list">
{% for technical_doc in technical_docs %}
<li><input class="form-control" name="technical_docs" size="80" type="text" value="{{technical_doc}}"/></li>
{% endfor %}
<a href="javascript:;" id="technical-docs-add" class="btn btn-primary pull-right add-button"><i class="icon-plus"></i> &nbsp;Add Entry</a>
<fieldset class="tab-pane boxed whitebox fade" id="section-temporal-field">
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