From 2fb1de6d6c4ce008062bbe76fde1f6144b9adaef Mon Sep 17 00:00:00 2001 From: Sym Roe Date: Thu, 27 Jun 2024 17:11:19 +0100 Subject: [PATCH] Initial administration app --- wcivf/apps/administrations/__init__.py | 0 wcivf/apps/administrations/admin.py | 1 + wcivf/apps/administrations/apps.py | 6 ++ wcivf/apps/administrations/helpers.py | 58 +++++++++++++++++++ .../administrations/migrations/__init__.py | 0 wcivf/apps/administrations/models.py | 1 + wcivf/apps/administrations/tests.py | 1 + wcivf/apps/administrations/views.py | 1 + 8 files changed, 68 insertions(+) create mode 100644 wcivf/apps/administrations/__init__.py create mode 100644 wcivf/apps/administrations/admin.py create mode 100644 wcivf/apps/administrations/apps.py create mode 100644 wcivf/apps/administrations/helpers.py create mode 100644 wcivf/apps/administrations/migrations/__init__.py create mode 100644 wcivf/apps/administrations/models.py create mode 100644 wcivf/apps/administrations/tests.py create mode 100644 wcivf/apps/administrations/views.py diff --git a/wcivf/apps/administrations/__init__.py b/wcivf/apps/administrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/wcivf/apps/administrations/admin.py b/wcivf/apps/administrations/admin.py new file mode 100644 index 000000000..846f6b406 --- /dev/null +++ b/wcivf/apps/administrations/admin.py @@ -0,0 +1 @@ +# Register your models here. diff --git a/wcivf/apps/administrations/apps.py b/wcivf/apps/administrations/apps.py new file mode 100644 index 000000000..56584a07b --- /dev/null +++ b/wcivf/apps/administrations/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AdministrationsConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "administrations" diff --git a/wcivf/apps/administrations/helpers.py b/wcivf/apps/administrations/helpers.py new file mode 100644 index 000000000..59390a21c --- /dev/null +++ b/wcivf/apps/administrations/helpers.py @@ -0,0 +1,58 @@ +import json +from pathlib import Path +from typing import Dict, List + +BASE_DATA_PATH = Path("/home/symroe/Data/StaticOrgLayer/") + + +class Administration: + def __init__(self, admin_id, data: Dict): + self.admin_id = admin_id + self.data = data + + @property + def administration_type(self): + if self.admin_id.startswith("D::"): + return "division" + return "organisation" + + @property + def role_type(self): + return self.admin_id.split("::")[-1] + + def friendly_name(self): + org_name = self.data["organisation"]["common_name"] + + if self.administration_type == "organisation": + if self.role_type == "mayor": + org_name = f"Mayor of {org_name}" + + return org_name + div_name = self.data["division"]["name"] + + if self.role_type == "local": + div_name = f"{div_name} ward" + + if self.role_type == "parl": + return f"MP for {div_name}" + return f"{org_name}: {div_name}" + + def seats_contested(self): ... + + def friendly_description(self): + return "asd" + + +class AdministrationsHelper: + def __init__(self, administration_ids: List[str]): + self.administration_ids = administration_ids + self.data_path = BASE_DATA_PATH + self.administrations: List[Administration] = [] + for admin_id in self.administration_ids: + data = self.load_json(admin_id) + self.administrations.append(Administration(admin_id, data)) + + def load_json(self, administration_id): + path = self.data_path / f"{administration_id}.json" + with path.open() as f: + return json.load(f) diff --git a/wcivf/apps/administrations/migrations/__init__.py b/wcivf/apps/administrations/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/wcivf/apps/administrations/models.py b/wcivf/apps/administrations/models.py new file mode 100644 index 000000000..6b2021999 --- /dev/null +++ b/wcivf/apps/administrations/models.py @@ -0,0 +1 @@ +# Create your models here. diff --git a/wcivf/apps/administrations/tests.py b/wcivf/apps/administrations/tests.py new file mode 100644 index 000000000..a39b155ac --- /dev/null +++ b/wcivf/apps/administrations/tests.py @@ -0,0 +1 @@ +# Create your tests here. diff --git a/wcivf/apps/administrations/views.py b/wcivf/apps/administrations/views.py new file mode 100644 index 000000000..60f00ef0e --- /dev/null +++ b/wcivf/apps/administrations/views.py @@ -0,0 +1 @@ +# Create your views here.