Skip to content

Commit

Permalink
Initial administration app
Browse files Browse the repository at this point in the history
  • Loading branch information
symroe committed Jun 27, 2024
1 parent a68a08b commit 2fb1de6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions wcivf/apps/administrations/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Register your models here.
6 changes: 6 additions & 0 deletions wcivf/apps/administrations/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AdministrationsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "administrations"
58 changes: 58 additions & 0 deletions wcivf/apps/administrations/helpers.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file.
1 change: 1 addition & 0 deletions wcivf/apps/administrations/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your models here.
1 change: 1 addition & 0 deletions wcivf/apps/administrations/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your tests here.
1 change: 1 addition & 0 deletions wcivf/apps/administrations/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your views here.

0 comments on commit 2fb1de6

Please sign in to comment.