Skip to content

Commit 7a652bd

Browse files
authored
Merge pull request #128 from odscjames/2023-12-06
Links to codelists - rewrite to OCDS Standard
2 parents 24931b9 + 9522e71 commit 7a652bd

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

cove_oc4ids/views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
import re
34
from decimal import Decimal
45

56
from cove.views import cove_web_input_error, explore_data_context
@@ -84,6 +85,14 @@ def explore_oc4ids(request, pk):
8485

8586
context = common_checks_oc4ids(context, upload_dir, json_data, schema_oc4ids, lib_cove_oc4ids_config)
8687

88+
for key in ("additional_closed_codelist_values", "additional_open_codelist_values"):
89+
for path_string, codelist_info in context[key].items():
90+
if codelist_info["codelist_url"].startswith(schema_oc4ids.codelists):
91+
codelist_info["codelist_url"] = (
92+
"https://standard.open-contracting.org/infrastructure/latest/en/reference/codelists/#"
93+
+ re.sub(r"([A-Z])", r"\1", codelist_info["codelist"].split(".")[0]).lower()
94+
)
95+
8796
if not db_data.rendered:
8897
db_data.rendered = True
8998
db_data.save()

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ django-bootstrap3==15.0.0
3838
# via
3939
# -r requirements.in
4040
# libcoveweb
41-
django-environ==0.6.0
42-
# via libcoveweb
4341
et-xmlfile==1.1.0
4442
# via openpyxl
4543
flattentool==0.24.0
@@ -70,7 +68,7 @@ libcoveoc4ids[perf]==0.4.2
7068
# via -r requirements.in
7169
libcoveocds==0.11.0
7270
# via libcoveoc4ids
73-
libcoveweb==0.26.0
71+
libcoveweb==0.30.1
7472
# via -r requirements.in
7573
lxml==4.9.1
7674
# via flattentool

requirements_dev.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ django-bootstrap3==15.0.0
7373
# via
7474
# -r requirements.txt
7575
# libcoveweb
76-
django-environ==0.6.0
77-
# via
78-
# -r requirements.txt
79-
# libcoveweb
8076
docopt==0.6.2
8177
# via coveralls
8278
et-xmlfile==1.1.0
@@ -138,7 +134,7 @@ libcoveocds==0.11.0
138134
# via
139135
# -r requirements.txt
140136
# libcoveoc4ids
141-
libcoveweb==0.26.0
137+
libcoveweb==0.30.1
142138
# via -r requirements.txt
143139
libsass==0.21.0
144140
# via -r requirements_dev.in

tests/fixtures/codelists.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": "0.9",
3+
"uri": "https://standard.open-contracting.org/infrastructure/0.9/en/_static/example.json",
4+
"publishedDate": "2018-12-10T15:53:00Z",
5+
"publisher": {
6+
"name": "Open Data Services Co-operative Limited",
7+
"scheme": "GB-COH",
8+
"uid": "9506232",
9+
"uri": "http://data.companieshouse.gov.uk/doc/company/09506232"
10+
},
11+
"license": "http://opendatacommons.org/licenses/pddl/1.0/",
12+
"publicationPolicy": "https://standard.open-contracting.org/1.1/en/implementation/publication_policy/",
13+
"projects": [
14+
{
15+
"id": "proj1",
16+
"status": "Bad news captain",
17+
"sector": [
18+
"little square buildings",
19+
"pointy roofs"
20+
],
21+
"type": "shiny and new"
22+
}
23+
]
24+
}

tests/test_basic.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24
from cove.input.models import SuppliedData
35
from django.core.files.base import ContentFile
@@ -21,3 +23,25 @@ def test_explore_page(client, json_data):
2123
data.current_app = "cove_oc4ids"
2224
resp = client.get(data.get_absolute_url())
2325
assert resp.status_code == 200
26+
27+
28+
@pytest.mark.django_db
29+
def test_codelist_url_extension_codelists(client):
30+
file_name = os.path.join(
31+
"tests",
32+
"fixtures",
33+
"codelists.json",
34+
)
35+
with open(os.path.join(file_name)) as fp:
36+
user_data = fp.read()
37+
data = SuppliedData.objects.create()
38+
data.original_file.save("test.json", ContentFile(user_data))
39+
data.current_app = "cove_oc4ids"
40+
resp = client.get(data.get_absolute_url())
41+
42+
assert resp.status_code == 200
43+
assert len(resp.context["additional_open_codelist_values"]) == 1
44+
assert (
45+
resp.context["additional_open_codelist_values"]["projects/sector"]["codelist_url"]
46+
== "https://standard.open-contracting.org/infrastructure/latest/en/reference/codelists/#projectsector"
47+
)

0 commit comments

Comments
 (0)