ckan / ckan/ckanext-scheming

Table view snippet for repeating fields.

Open
#206 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
102
Forks
182
PR merge metrics
No merged PRs in 30d

Description

PR #203 adds support for repeating composite fields. The following is a very simple patch that adds support for parent-level display snippets of repeating and composite fields so containers other than the default dl/dd can be used. In this case, it adds a `table.html` snippet that will render all of its children in a table. Columns with a `display_snippet: null` will be excluded, and the display snippet will be used to render the cell content like normal.

![image](https://user-images.githubusercontent.com/72590/54007600-a0970c00-4130-11e9-9f51-3f1e5be4c639.png)

It should be extended to use the helper for checking for empty fields to prevent rendering a table with no content.

```diff
diff --git a/ckanext/scheming/templates/scheming/display_snippets/table.html b/ckanext/scheming/templates/scheming/display_snippets/table.html
new file mode 100644
index 0000000..eeebf06
--- /dev/null
+++ b/ckanext/scheming/templates/scheming/display_snippets/table.html
@@ -0,0 +1,33 @@
+
+
+
+ {% for subfield in field.subfields %}
+ {% if subfield.display_snippet %}
+
+ {% endif %}
+ {% endfor %}
+
+
+
+ {% for group in data %}
+
+ {% for subfield in field.subfields %}
+ {% set options = subfield.display_snippet_options|default({}) %}
+ {% if group[subfield.field_name] %}
+ {% if options.row_header %}{% endif %}
+ {% else %}
+
+ {% endif %}
+ {% endfor %}
+
+ {% endfor %}
+
+{{ h.scheming_language_text(subfield.label) }}{% else %}{% endif %}
+ {%- snippet 'scheming/snippets/display_field.html',
+ field=subfield,
+ data=group,
+ errors=errors,
+ entity_type=entity_type,
+ object_type=object_type
+ -%}
+ {% if options.row_header %}{% else %}
diff --git a/ckanext/scheming/templates/scheming/snippets/display_field.html b/ckanext/scheming/templates/scheming/snippets/display_field.html
index 9061e00..b9e86ee 100644
--- a/ckanext/scheming/templates/scheming/snippets/display_field.html
+++ b/ckanext/scheming/templates/scheming/snippets/display_field.html
@@ -1,8 +1,21 @@
{#- master snippet for all scheming display fields -#}
{#- render the field the user requested, or use a default field -#}
{%- if field.subfields %}
- {% set group_data = h.scheming_composite_load(data[field.field_name]) %}
+ {% set group_data = h.scheming_composite_load(data[field.field_name]) %}

+ {% if field.display_snippet %}
+ {%- set display_snippet = field.display_snippet -%}
+ {%- if '/' not in display_snippet -%}
+ {%- set display_snippet = 'scheming/display_snippets/' + display_snippet -%}
+ {%- endif -%}
+ {%- snippet display_snippet,
+ field=field,
+ data=group_data,
+ errors=errors,
+ entity_type=entity_type,
+ object_type=object_type
+ -%}
+ {% else %}
{% for group in group_data %}


{%- for subfield in field.subfields %}
@@ -23,6 +36,7 @@
{% endfor -%}

{% endfor %}
+ {% endif %}
{% else %}
{%- set display_snippet = field.display_snippet -%}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with ckanext/scheming/templates/scheming/display_snippets/table.html and snippets/display_field.html, then locate the existing helper for checking empty fields. Update the table rendering behavior so an empty table is not produced, and verify the rendered output for repeating composite fields with empty and populated data.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
frontend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.