Skip to content

Commit

Permalink
update dataset areas_avaible in base importers
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Nov 21, 2023
1 parent 775b53d commit e3cbbe7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions hub/management/commands/base_importers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import cache
from time import sleep

from django.core.management.base import BaseCommand
Expand All @@ -7,7 +8,7 @@
import pandas as pd
from tqdm import tqdm

from hub.models import Area, AreaData, DataSet, DataType
from hub.models import Area, AreaData, AreaType, DataSet, DataType
from utils.mapit import (
BadRequestException,
ForbiddenException,
Expand All @@ -20,6 +21,7 @@

class BaseAreaImportCommand(BaseCommand):
cast_field = IntegerField
area_type = "WMC"

def __init__(self):
super().__init__()
Expand All @@ -37,6 +39,10 @@ def get_label(self, config):
def delete_data(self):
pass

@cache
def get_area_type(self):
return AreaType.objects.get(code=self.area_type)

def add_data_sets(self, df=None):
for name, config in self.data_sets.items():
label = self.get_label(config)
Expand Down Expand Up @@ -69,10 +75,12 @@ def add_data_sets(self, df=None):
**config["defaults"],
},
)
data_set.areas_available.add(self.get_area_type())

data_type, created = DataType.objects.update_or_create(
data_set=data_set,
name=name,
area_type=self.get_area_type(),
defaults={
"data_type": config["defaults"]["data_type"],
"label": label,
Expand Down Expand Up @@ -163,7 +171,6 @@ def update_max_min(self):

class BaseImportFromDataFrameCommand(BaseAreaImportCommand):
uses_gss = True
area_type = "WMC"

def get_row_data(self, row, conf):
return row[conf["col"]]
Expand Down

0 comments on commit e3cbbe7

Please sign in to comment.