Skip to content

Commit b772c7c

Browse files
committed
Move csv resources out of static folder
Should only be used to serve frontend assets and was causing issues with migrations on CI test build
1 parent 99be5d6 commit b772c7c

File tree

9 files changed

+21
-15
lines changed

9 files changed

+21
-15
lines changed

app/dashboard/helpers.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import csv
55
from copy import deepcopy
66

7-
from django.contrib.staticfiles.storage import staticfiles_storage
87
from django.utils.translation import gettext_lazy as _
98
from django.db.models import Value, Q, F, Case, When
109
from django.db.models.functions import Concat, Replace
1110
from django.templatetags.static import static
1211
from numbers import Number
1312

13+
from epa.settings import RESOURCES_DIR
1414
from projects.models import Viewer, Project
1515
import pickle
1616
from django.conf import settings as django_settings
@@ -93,10 +93,10 @@
9393
KPI_PARAMETERS = {}
9494
KPI_PARAMETERS_ASSETS = {}
9595

96-
if os.path.exists(staticfiles_storage.path("MVS_kpis_list.csv")) is True:
97-
with open(
98-
staticfiles_storage.path("MVS_kpis_list.csv"), encoding="utf-8"
99-
) as csvfile:
96+
MVS_KPIS_LIST_PATH = RESOURCES_DIR / "MVS_kpis_list.csv"
97+
98+
if MVS_KPIS_LIST_PATH.exists():
99+
with open(MVS_KPIS_LIST_PATH, encoding="utf-8") as csvfile:
100100
csvreader = csv.reader(csvfile, delimiter=",", quotechar='"')
101101
CARRIER_PLACEHOLDER = ":carrier:"
102102
for i, row in enumerate(csvreader):
@@ -132,9 +132,7 @@
132132
# {"name": _(verbose), "id": label, "unit": _(unit)}
133133
# )
134134

135-
with open(
136-
staticfiles_storage.path("MVS_kpis_list.csv"), encoding="utf-8"
137-
) as csvfile:
135+
with open(MVS_KPIS_LIST_PATH, encoding="utf-8") as csvfile:
138136
csvreader = csv.reader(csvfile, delimiter=",", quotechar='"')
139137
for i, row in enumerate(csvreader):
140138
if i == 0:

app/epa/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
4242
]
4343

44+
# Resources dir (containing helper csv files)
45+
RESOURCES_DIR = BASE_DIR / "resources"
46+
4447
# SECURITY WARNING: don't run with debug turned on in production!
4548
DEBUG = env.bool("DEBUG", default=False)
4649
PROD_ENV = env.bool("PROD_ENV", default=False)

app/projects/helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import csv
66
from openpyxl import load_workbook
77
from django import forms
8-
from django.contrib.staticfiles.storage import staticfiles_storage
98
from django.core.exceptions import ValidationError
109
from django.utils.translation import gettext_lazy as _
1110
from django.utils.html import html_safe
11+
12+
from epa.settings import RESOURCES_DIR
1213
from projects.dtos import convert_to_dto
1314
from projects.models import Timeseries, AssetType
1415
from projects.constants import MAP_MVS_EPA
@@ -19,11 +20,11 @@
1920
TS_MANUAL_TYPE = "manual"
2021
TS_INPUT_TYPES = (TS_MANUAL_TYPE, TS_SELECT_TYPE, TS_UPLOAD_TYPE)
2122

23+
MVS_PARAMETERS_LIST_PATH = RESOURCES_DIR / "MVS_parameters_list.csv"
24+
2225
PARAMETERS = {}
23-
if os.path.exists(staticfiles_storage.path("MVS_parameters_list.csv")) is True:
24-
with open(
25-
staticfiles_storage.path("MVS_parameters_list.csv"), encoding="utf-8"
26-
) as csvfile:
26+
if MVS_PARAMETERS_LIST_PATH.exists():
27+
with open(MVS_PARAMETERS_LIST_PATH, encoding="utf-8") as csvfile:
2728
csvreader = csv.reader(csvfile, delimiter=",", quotechar='"')
2829
for i, row in enumerate(csvreader):
2930
if i == 0:

app/projects/management/commands/update_assettype.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from django.core.management.base import BaseCommand, CommandError
22
import pandas as pd
33
import json
4+
5+
from epa.settings import RESOURCES_DIR
46
from projects.models import *
57

68

@@ -15,7 +17,7 @@ def add_arguments(self, parser):
1517
def handle(self, *args, **options):
1618
update_assets = options["update"]
1719

18-
df = pd.read_csv("static/assettypes_list.csv")
20+
df = pd.read_csv(RESOURCES_DIR / "assettypes_list.csv")
1921
assets = df.to_dict(orient="records")
2022

2123
for asset_params in assets:

app/projects/management/commands/update_valuetype.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from django.core.management.base import BaseCommand, CommandError
22
import pandas as pd
3+
4+
from epa.settings import RESOURCES_DIR
35
from projects.models import *
46

57

@@ -14,7 +16,7 @@ def add_arguments(self, parser):
1416
def handle(self, *args, **options):
1517
update_valuetypes = options["update"]
1618

17-
df = pd.read_csv("static/valuetypes_list.csv")
19+
df = pd.read_csv(RESOURCES_DIR / "valuetypes_list.csv")
1820
valuetypes = df.to_dict(orient="records")
1921
for vt_params in valuetypes:
2022
qs = ValueType.objects.filter(type=vt_params["type"])

0 commit comments

Comments
 (0)