Skip to content

Commit

Permalink
libcoveweb2: additional_fields: additional_checks: jsonschema_validat…
Browse files Browse the repository at this point in the history
…ion: Print JSON values nicer

* quote strings
* print lists as lists, with longer ones collapsed by default

#20
#13
#22
  • Loading branch information
jarofgreen committed Dec 20, 2022
1 parent d00df4e commit ba98bb3
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 40 deletions.
48 changes: 24 additions & 24 deletions cove_ofds/templates/cove_ofds/additional_checks_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.missing_node_id }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.missing_node_id %}
</td>
</tr>
{% endfor %}
Expand All @@ -50,7 +50,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.missing_node_id }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.missing_node_id %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -90,7 +90,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.incorrect_type }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.incorrect_type %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -130,7 +130,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.incorrect_coordinates }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.incorrect_coordinates %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -170,7 +170,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.incorrect_type }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.incorrect_type %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -210,7 +210,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.incorrect_coordinates }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.incorrect_coordinates %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -251,7 +251,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.phase_id_not_found }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.phase_id_not_found %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -281,7 +281,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.phase_id_not_found }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.phase_id_not_found %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -311,7 +311,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.phase_id_not_found }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.phase_id_not_found %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -356,10 +356,10 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.name_in_reference }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_in_reference %}
</td>
<td>
{{ additional_check.name_should_be }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_should_be %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -390,10 +390,10 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.name_in_reference }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_in_reference %}
</td>
<td>
{{ additional_check.name_should_be }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_should_be %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -424,10 +424,10 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.name_in_reference }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_in_reference %}
</td>
<td>
{{ additional_check.name_should_be }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_should_be %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -469,7 +469,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.organisation_id_not_found }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.organisation_id_not_found %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -499,7 +499,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.organisation_id_not_found }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.organisation_id_not_found %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -529,7 +529,7 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.organisation_id_not_found }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.organisation_id_not_found %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -577,10 +577,10 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.name_in_reference }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_in_reference %}
</td>
<td>
{{ additional_check.name_should_be }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_should_be %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -615,10 +615,10 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.name_in_reference }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_in_reference %}
</td>
<td>
{{ additional_check.name_should_be }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_should_be %}
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -649,10 +649,10 @@ <h4>
{{ additional_check.path }}
</td>
<td>
{{ additional_check.name_in_reference }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_in_reference %}
</td>
<td>
{{ additional_check.name_should_be }}
{% include "libcoveweb2/show_json_value.html" with value=additional_check.name_should_be %}
</td>
</tr>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% load i18n %}
{% load cove_tags %}
{% load ofds_cove_tags %}


<div style="text-align: right;">
Expand Down Expand Up @@ -46,12 +45,12 @@
</td>
{% if col_instance %}
<td>
{{ error.instance|error_instance_display }}
{% include "libcoveweb2/show_json_value.html" with value=error.instance %}
</td>
{% endif %}
{% if col_validator_value %}
<td>
{{ error.validator_value }}
{% include "libcoveweb2/show_json_value.html" with value=error.validator_value %}
</td>
{% endif %}
</tr>
Expand Down
Empty file removed cove_ofds/templatetags/__init__.py
Empty file.
11 changes: 0 additions & 11 deletions cove_ofds/templatetags/ofds_cove_tags.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<td>{{info.count}}</td>
<td>
{% for example in info.examples %}
{{example}} <br />
{% include "libcoveweb2/show_json_value.html" with value=example %} <br />
{% endfor %}
</td>
<td>
Expand Down Expand Up @@ -64,7 +64,7 @@ <h4>{% blocktrans %}Child fields of {{parent_full_path}}{% endblocktrans %} </h4
<td>{{info.count}}</td>
<td>
{% for example in info.examples %}
{{example}} <br />
{% include "libcoveweb2/show_json_value.html" with value=example %} <br />
{% endfor %}
</td>
</tr>
Expand Down
32 changes: 32 additions & 0 deletions libcoveweb2/templates/libcoveweb2/show_json_value.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% load cove_tags %}

{% if value|get_variable_type == 'str' %}
"{{ value }}"
{% elif value|get_variable_type == 'list' %}
{% if value|length > 5 %}
<ul>
{% for v in value|slice:":5" %}
<li>{% include "libcoveweb2/show_json_value.html" with value=v dont_expand_lists=True %}</li>
{% endfor %}
</ul>
{% show_json_value_more_id as id %}
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#{{ id }}" aria-expanded="false" aria-controls="{{ id }}">
Show/Hide more
</button>
<div class="collapse" id="{{ id }}">
<ul>
{% for v in value|slice:"5:" %}
<li>{% include "libcoveweb2/show_json_value.html" with value=v dont_expand_lists=True %}</li>
{% endfor %}
</ul>
</div>
{% else %}
<ul>
{% for v in value %}
<li>{% include "libcoveweb2/show_json_value.html" with value=v dont_expand_lists=True %}</li>
{% endfor %}
</ul>
{% endif %}
{% else %}
{{ value }}
{% endif %}
19 changes: 19 additions & 0 deletions libcoveweb2/templatetags/cove_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,22 @@ def take_or_sample(population, k):
@register.filter(name="list_from_attribute")
def list_from_attribute(list_of_dicts, key_name):
return [value[key_name] for value in list_of_dicts]


@register.filter(name="get_variable_type")
def get_variable_type(value):
return type(value).__name__


show_json_value_more_counter = 0


@register.simple_tag
def show_json_value_more_id():
"""
Used by libcoveweb2/templates/libcoveweb2/show_json_value.html
To make sure that every time we need a show/hide link there, we get a unique CSS ID
"""
global show_json_value_more_counter
show_json_value_more_counter = show_json_value_more_counter + 1
return "json_value_more_" + str(show_json_value_more_counter)

0 comments on commit ba98bb3

Please sign in to comment.