Skip to content

Commit 3112f2c

Browse files
committed
fixup csv uploads to preserve entry data and existing prefix
1 parent 01bc286 commit 3112f2c

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

.flaskenv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FLASK_DEBUG=True
2-
FLASK_CONFIG=config.DevelopmentConfig
2+
FLASK_CONFIG=application.config.DevelopmentConfig
33
FLASK_APP=application.wsgi:app
44
SECRET_KEY=replaceinprod
55
DATABASE_URL=postgresql://localhost/dluhc-datasets

application/blueprints/main/views.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from flask import (
88
Blueprint,
99
abort,
10+
current_app,
1011
flash,
1112
make_response,
1213
redirect,
@@ -176,7 +177,11 @@ def add_record(id):
176177
data["start-date"] = start_date
177178

178179
# set prefix to as it is not in form
179-
data["prefix"] = dataset.dataset
180+
data["prefix"] = (
181+
dataset.dataset
182+
if dataset.dataset not in current_app.config.WIKIDATA_PREFIX_DATASETS
183+
else "wikidata"
184+
)
180185
data["entry-date"] = datetime.datetime.today().strftime("%Y-%m-%d")
181186

182187
last_record = (

application/commands.py

+16
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,22 @@ def remove_orgs():
727727
db.session.commit()
728728

729729

730+
@data_cli.command("wikidata-prefix")
731+
def wikidata_prefix():
732+
from flask import current_app
733+
734+
for dataset in current_app.config["WIKIDATA_PREFIX_DATASETS"]:
735+
print(f"Setting wikidata prefix for {dataset}")
736+
dataset = Dataset.query.filter(Dataset.dataset == dataset).one_or_none()
737+
if dataset is None:
738+
print(f"Dataset {dataset} does not exist")
739+
continue
740+
for record in dataset.records:
741+
record.prefix = "wikidata"
742+
db.session.add(record)
743+
db.session.commit()
744+
745+
730746
def _get_repo(config):
731747
app_id = config.get("GITHUB_APP_ID")
732748
repo_name = config.get("DATASETS_REPO")

config/config.py application/config.py

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ class Config:
2424
SPECIFICATION_REPO_URL = os.getenv("SPECIFICATION_REPO_URL")
2525
PLATFORM_URL = os.getenv("PLATFORM_URL")
2626
PLANNING_DATA_DESIGN_URL = os.getenv("PLANNING_DATA_DESIGN_URL")
27+
WIKIDATA_PREFIX_DATASETS = set(
28+
[
29+
"development-corporation",
30+
"national-park-authority",
31+
"nonprofit",
32+
"public-authority",
33+
"passenger-transport-executive",
34+
"regional-park-authority",
35+
"waste-authority",
36+
]
37+
)
2738

2839

2940
class DevelopmentConfig(Config):

application/wsgi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from application.factory import create_app
44

5-
app = create_app(os.getenv("FLASK_CONFIG") or "config.DevelopmentConfig")
5+
app = create_app(os.getenv("FLASK_CONFIG") or "application.config.DevelopmentConfig")

config/__init__.py

-3
This file was deleted.

tests/unit/test_forms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
def app():
1111
from application.factory import create_app
1212

13-
app = create_app("config.TestConfig")
13+
app = create_app("application.config.TestConfig")
1414
yield app
1515

1616

1717
fields = [
18-
Field(field="organisation", datatype="curie", name="Orgasnisation"),
18+
Field(field="organisation", datatype="curie", name="Organisation"),
1919
Field(field="prefix", datatype="string", name="Prefix"),
2020
Field(field="reference", datatype="string", name="Reference"),
2121
Field(field="documentation-url", datatype="url", name="Documentation url"),

0 commit comments

Comments
 (0)