Skip to content

Commit

Permalink
174 - Add mandatory check box about personally identifiable informati…
Browse files Browse the repository at this point in the history
…on (#40)

* added a multi checkbox in schema

* added a new preset

* added a new preset

* Updated preset

* Invalidate this change

* Small update to display_snippet

* Small fix to schema

* More update

* More update

* Changed default values

* Small id change

* invalidate changes on react files

* invalidate changes on react files
  • Loading branch information
A-Souhei authored Oct 2, 2024
1 parent c855e4f commit 7695951
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 18 deletions.
3 changes: 2 additions & 1 deletion ckanext/zarr/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def get_validators(self):
'autofill': zarr_validators.autofill,
'autogenerate': zarr_validators.autogenerate,
'isomonth': zarr_validators.isomonth,
'date_validator': zarr_validators.date_validator
'date_validator': zarr_validators.date_validator,
'approval_required': zarr_validators.approval_required
}

# IPackageContoller
Expand Down
23 changes: 6 additions & 17 deletions ckanext/zarr/presets.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
{
"scheming_presets_version": 1,
"about": "These are Scheming presets specific to WHO AFRO",
"about": "These are Scheming presets specific to ZaRR",
"about_url": "http://github.com/ckan/ckanext-scheming#preset",
"presets": [
{
"preset_name": "resource_giftless_upload",
"preset_name": "approval",
"values": {
"form_snippet": "resource_upload.html"
}
}, {
"preset_name": "preset_value",
"values": {
"form_snippet": "no_input.html",
"validators": "autofill"
}
}, {
"preset_name": "month",
"values": {
"form_snippet": "month.html",
"display_snippet": "month.html",
"validators": "isomonth"
"form_snippet": "confirm.html",
"display_snippet": "confirm.html",
"validators": "approval_required"
}
}
]
}
}
7 changes: 7 additions & 0 deletions ckanext/zarr/schemas/dcat_dublin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ dataset_fields:
required: true
display_group: Overview

- field_name: no_pii_confirmation
label: No PII Confirmation
form_placeholder: I confirm that this dataset contains no personally identifiable information.
preset: approval
required: true
display_group: Overview


- start_form_page:
title: Metadata
Expand Down
6 changes: 6 additions & 0 deletions ckanext/zarr/templates/scheming/display_snippets/confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% set value = data[field.field_name] %}
{% if value == '1' %}
<strong>{{ _('Yes') }}</strong>
{% else %}
<strong style="color: red">{{ _('No') }}</strong>
{% endif %}
43 changes: 43 additions & 0 deletions ckanext/zarr/templates/scheming/form_snippets/confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% import 'macros/form.html' as form %}

<style>
fieldset.checkboxes label {
font-weight: normal;
display: block;
}
fieldset.checkboxes label:after {
content: none;
}
fieldset.checkboxes label input {
width: auto;
top: 0;
}
</style>

{%- call form.input_block(
label=h.scheming_language_text(field.label),
classes=field.classes if 'classes' in field else ['control-medium'],
error=errors[field.field_name],
is_required=h.scheming_field_required(field)) -%}

{% set placeholder = h.scheming_language_text(field.form_placeholder) %}


<fieldset class="checkboxes">
<label for="approved-{{ field.field_name }}">
<input id="approved-{{ field.field_name }}"
type="checkbox"
{{"checked " if data[field.field_name] == '1'}}
name="approved-{{ field.field_name }}"
onchange="
var hiddenInput = document.getElementById('approval-status-{{ field.field_name }}');
hiddenInput.value = this.checked ? '1' : '0';
"
/>
{{ placeholder }}
</label>
<input type="hidden" id="approval-status-{{ field.field_name }}" name="{{ field.field_name }}" value="0"/>
</fieldset>

{%- snippet 'scheming/form_snippets/help_text.html', field=field -%}
{%- endcall -%}
9 changes: 9 additions & 0 deletions ckanext/zarr/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,12 @@ def validator(key, data, errors, context):
except ValueError:
errors[key].append(_("Invalid date format. Please use YYYY-MM-DD"))
return validator


@scheming_validator
def approval_required(field, schema):
def validator(key, data, errors, context):
value = data.get(key)
if value != "1":
errors[key].append(_(f"This field is mandatory."))
return validator

0 comments on commit 7695951

Please sign in to comment.