Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwood committed Feb 19, 2024
1 parent e84dd47 commit df3adf3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
19 changes: 15 additions & 4 deletions cove/cove_360/templates/cove_360/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ <h3 class="panel-title panel-title-explore">
{% if metadata.license %}
<strong> License: </strong> <a href="{{metadata.license}}">{{metadata.license}} </a><br>
{% endif %}
{% if metadata.extension %}
<strong>Extension: </strong> {{metadata.extension}}<br>
{% if extension_metadatas %}
<strong>Extensions: </strong> {% for extension_metadata in extension_metadatas %}<a href="{{extension_metadata.documentationUrl}}">{{extension_metadata.id}}</a> {% endfor %}<br>
{% endif %}
</div>
</div>
Expand Down Expand Up @@ -322,7 +322,8 @@ <h3 class="panel-title panel-title-explore">
{% else %}
{% trans "Congratulations! Your data is using the 360Giving Data Standard. We used the " %}
{% endif %}
<a href="https://www.threesixtygiving.org/standard/reference/#toc-360giving-json-schemas"> 360Giving JSON Package Schema</a> {% trans "to check this." %}
<a href="https://www.threesixtygiving.org/standard/reference/#toc-360giving-json-schemas"> 360Giving JSON Package Schema</a>
{% trans "to check this." %}
</p>
<div class="explore-help">{% trans "This means that the data" %}
{% if validation_errors or additional_closed_codelist_values %}
Expand All @@ -333,7 +334,17 @@ <h3 class="panel-title panel-title-explore">

{% blocktrans %}the requirements of the <a href="https://standard.threesixtygiving.org/en/latest/technical/reference/">360Giving Data Standard</a>.{% endblocktrans %}
{% blocktrans %} Making sure your data uses the standard correctly is important. Otherwise it cannot be used alongside other valid 360Giving data and cannot be included in 360Giving tools, such as GrantNav and 360Insights.{% endblocktrans %}
</diV>
</div>

{% if extension_metadatas %}
<p class="explanation">{% trans "The following 360Giving standard extensions were also used to check your data:" %}</p>
<ul>
{% for extension_metadata in extension_metadatas %}
<li><a href="extension_metadata.documentationUrl" title="{{extension_metadata.description}}">{{extension_metadata.title}} ({{extension_metadata.id}})</a></li>
{% endfor %}
</ul>
{% endif %}

{% if validation_errors or additional_closed_codelist_values %}
<br>
<p class="explanation">&nbsp;{% trans "The following <strong>errors</strong> are preventing your data from being valid 360Giving data. Please use the feedback below to find and resolve the issues in your file" %}</p>
Expand Down
6 changes: 3 additions & 3 deletions cove/cove_360/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def explore_360(request, pk, template='cove_360/explore.html'):
'msg': _('360Giving JSON should have an object as the top level, the JSON you supplied does not.'),
})

extension_infos = schema_360.resolve_extension(json_data)
extension_metadatas = schema_360.resolve_extension(json_data)

context.update(convert_json(upload_dir, upload_url, file_name, schema_url=schema_360.schema_file,
request=request, flatten=request.POST.get('flatten'),
Expand All @@ -133,7 +133,7 @@ def explore_360(request, pk, template='cove_360/explore.html'):

try:
# Check data for presence of any schema extensions if exists re-convert using the newly patched schema
if extension_infos := schema_360.resolve_extension(json_data):
if extension_metadatas := schema_360.resolve_extension(json_data):
# Delete old converted data. If it is detected by libcove it will skip conversion (unflattening)
os.unlink(context["converted_path"])

Expand All @@ -142,7 +142,7 @@ def explore_360(request, pk, template='cove_360/explore.html'):
with open(context['converted_path'], encoding='utf-8') as fp:
json_data = json.load(fp, parse_float=Decimal)

context["extension_infos"] = extension_infos
context["extension_metadatas"] = extension_metadatas
except ExtensionsError as err:
raise CoveInputDataError(context={
'sub_title': _("Sorry, we can't process the data with the specified extension(s)"),
Expand Down
14 changes: 8 additions & 6 deletions lib360dataquality/cove/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ def resolve_extension(self, json_data) -> Optional[list]:
if len(extension_ids) == 0:
raise ExtensionsError("Extension key found but with no value(s)")

extension_infos = []
extension_metadatas = []

for extension_id in extension_ids.split(";"):
try:
r = requests.get(f"{EXTENSIONS_REGISTRY_BASE_URL}/{extension_id}.json")
r.raise_for_status()
extension_info = r.json()
extension_infos.append(extension_info)
extension_metadata = r.json()
extension_metadatas.append(extension_metadata)
except (json.JSONDecodeError, requests.HTTPError):
raise ExtensionsError("Couldn't not fetch or parse extension metadata")

for extension_schemas in extension_info["schemas"]:
for extension_schemas in extension_metadata["schemas"]:
try:
r = requests.get(extension_schemas["uri"])
r.raise_for_status()
Expand All @@ -182,10 +182,12 @@ def resolve_extension(self, json_data) -> Optional[list]:
self._pkg_schema_obj, extension
)

self.extension_codelist_urls.extend(extension_info["codelists"])
self.extension_codelist_urls.extend(extension_metadata["codelists"])

# Write out the new schema objects
self.write_pkg_schema_file()
self.write_schema_file()

return extension_infos
print(f"METADAS : {extension_metadatas}")

return extension_metadatas
2 changes: 1 addition & 1 deletion lib360dataquality/cove/threesixtygiving.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def group_validation_errors(validation_errors, file_type, openpyxl_workbook):
validation_errors_grouped["required"].append((error_json, error_extra))
elif error["validator"] == "format" or (error["validator"] == "oneOf" and "format" in error["validator_value"][0]):
validation_errors_grouped["format"].append((error_json, error_extra))
else:
else: # We're getting oneOf stuff here that appears to be fomr some other error
validation_errors_grouped["other"].append((error_json, error_extra))
return validation_errors_grouped

Expand Down

0 comments on commit df3adf3

Please sign in to comment.