Skip to content

Commit

Permalink
Links to codelists - rewrite to OCDS Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
odscjames committed Dec 6, 2023
1 parent 535a3a7 commit c1f9abd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
8 changes: 8 additions & 0 deletions cove_oc4ids/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
from decimal import Decimal
import re

from cove.views import cove_web_input_error, explore_data_context
from django.conf import settings
Expand Down Expand Up @@ -88,6 +89,13 @@ def explore_oc4ids(request, pk):
db_data.rendered = True
db_data.save()

for path_string, codelist_info in context["additional_open_codelist_values"].items():
if codelist_info["codelist_url"].startswith(schema_oc4ids.codelists):
codelist_info["codelist_url"] = (
"https://standard.open-contracting.org/infrastructure/latest/en/reference/codelists/#"
+ re.sub(r"([A-Z])", r"\1", codelist_info["codelist"].split(".")[0]).lower()
)

template = "cove_oc4ids/explore.html"

return render(request, template, context)
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ django-bootstrap3==15.0.0
# via
# -r requirements.in
# libcoveweb
django-environ==0.6.0
# via libcoveweb
et-xmlfile==1.1.0
# via openpyxl
flattentool==0.24.0
Expand Down Expand Up @@ -70,7 +68,7 @@ libcoveoc4ids[perf]==0.4.2
# via -r requirements.in
libcoveocds==0.11.0
# via libcoveoc4ids
libcoveweb==0.26.0
libcoveweb==0.30.1
# via -r requirements.in
lxml==4.9.1
# via flattentool
Expand Down
6 changes: 1 addition & 5 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ django-bootstrap3==15.0.0
# via
# -r requirements.txt
# libcoveweb
django-environ==0.6.0
# via
# -r requirements.txt
# libcoveweb
docopt==0.6.2
# via coveralls
et-xmlfile==1.1.0
Expand Down Expand Up @@ -138,7 +134,7 @@ libcoveocds==0.11.0
# via
# -r requirements.txt
# libcoveoc4ids
libcoveweb==0.26.0
libcoveweb==0.30.1
# via -r requirements.txt
libsass==0.21.0
# via -r requirements_dev.in
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/codelists.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.9",
"uri": "https://standard.open-contracting.org/infrastructure/0.9/en/_static/example.json",
"publishedDate": "2018-12-10T15:53:00Z",
"publisher": {
"name": "Open Data Services Co-operative Limited",
"scheme": "GB-COH",
"uid": "9506232",
"uri": "http://data.companieshouse.gov.uk/doc/company/09506232"
},
"license": "http://opendatacommons.org/licenses/pddl/1.0/",
"publicationPolicy": "https://standard.open-contracting.org/1.1/en/implementation/publication_policy/",
"projects": [
{
"id": "proj1",
"status": "Bad news captain",
"sector": [
"little square buildings",
"pointy roofs"
],
"type": "shiny and new"
}
]
}
25 changes: 25 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest
from cove.input.models import SuppliedData
from django.core.files.base import ContentFile
Expand All @@ -21,3 +22,27 @@ def test_explore_page(client, json_data):
data.current_app = "cove_oc4ids"
resp = client.get(data.get_absolute_url())
assert resp.status_code == 200




@pytest.mark.django_db
def test_codelist_url_extension_codelists(client):
file_name = os.path.join(
"tests",
"fixtures",
"codelists.json",
)
with open(os.path.join(file_name)) as fp:
user_data = fp.read()
data = SuppliedData.objects.create()
data.original_file.save("test.json", ContentFile(user_data))
data.current_app = "cove_oc4ids"
resp = client.get(data.get_absolute_url())

assert resp.status_code == 200
assert len(resp.context["additional_open_codelist_values"]) == 1
assert (
resp.context["additional_open_codelist_values"]["projects/sector"]["codelist_url"]
== "https://standard.open-contracting.org/infrastructure/latest/en/reference/codelists/#projectsector"
)

0 comments on commit c1f9abd

Please sign in to comment.