Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import area-based entities #110

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hub/graphql/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ class ExternalDataSourceInput:
data_type: auto
description: auto
organisation: auto
geography_column: auto
geography_column_type: auto
point_field: auto
point_field_type: auto
postcode_field: auto
first_name_field: auto
last_name_field: auto
Expand Down
21 changes: 13 additions & 8 deletions hub/graphql/types/model_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class FieldDefinition:
@strawberry_django.filter(models.ExternalDataSource)
class ExternalDataSourceFilter:
data_type: auto
geography_column_type: auto
point_field_type: auto


@strawberry.type
Expand Down Expand Up @@ -547,13 +547,18 @@ def generic_data_for_hub(self, hostname: str) -> List["GenericData"]:
hub = site.root_page.specific
data = []
for layer in hub.layers:
# Point within
data.extend(
models.GenericData.objects.filter(
data_type__data_set__external_data_source=layer.get("source"),
data_type__data_set__external_data_source__can_display_points_publicly=True,
data_type__data_set__external_data_source__can_display_details_publicly=True,
point__within=self.polygon,
**layer.get("filter", {}),
Q(
data_type__data_set__external_data_source=layer.get("source"),
data_type__data_set__external_data_source__can_display_points_publicly=True,
data_type__data_set__external_data_source__can_display_details_publicly=True,
) & (
Q(point__within=self.polygon) |
Q(areas__overlaps=self.polygon)
) &
Q(**layer.get("filter", {}))
)
)
return data
Expand Down Expand Up @@ -807,8 +812,8 @@ class BaseDataSource(Analytics):
description: auto
created_at: auto
last_update: auto
geography_column: auto
geography_column_type: auto
point_field: auto
point_field_type: auto
postcode_field: auto
first_name_field: auto
last_name_field: auto
Expand Down
8 changes: 4 additions & 4 deletions hub/graphql/types/public_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ async def enrich_postcode(
str(source.id): source.data_loader_factory()
async for source in models.ExternalDataSource.objects.filter(
organisation__members__user=user,
geography_column__isnull=False,
geography_column_type__isnull=False,
point_field__isnull=False,
point_field_type__isnull=False,
).all()
},
)
Expand All @@ -111,8 +111,8 @@ async def enrich_postcodes(
str(source.id): source.data_loader_factory()
async for source in models.ExternalDataSource.objects.filter(
organisation__members__user=user,
geography_column__isnull=False,
geography_column_type__isnull=False,
point_field__isnull=False,
point_field_type__isnull=False,
).all()
},
)
Expand Down
Empty file added hub/lib/__init_.py
Empty file.
12 changes: 12 additions & 0 deletions hub/lib/area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from utils.py import ensure_list


def treated_area_name_or_code(area):
if isinstance(area, str):
areas = "/".split(area)
# trim all areas
areas = [area.strip() for area in areas]
return areas
elif isinstance(area, list):
return [area.strip() for area in area]
return ensure_list(area)
4 changes: 2 additions & 2 deletions hub/management/commands/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def handle(self, *args, **kwargs):
api_key=settings.SEED_AIRTABLE_MEMBERLIST_API_KEY,
base_id=settings.SEED_AIRTABLE_MEMBERLIST_BASE_ID,
table_id=settings.SEED_AIRTABLE_MEMBERLIST_TABLE_NAME,
geography_column_type=AirtableSource.GeographyTypes.POSTCODE,
geography_column="Postcode",
point_field_type=AirtableSource.PointFieldTypes.POSTCODE,
point_field="Postcode",
postcode_field="Postcode",
start_time_field="Start",
title_field="Name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Migration(migrations.Migration):
("council", "Council"),
("constituency", "Constituency"),
],
choices_enum=hub.models.ExternalDataSource.GeographyTypes,
choices_enum=hub.models.ExternalDataSource.PointFieldTypes,
default="postcode",
max_length=12,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Migration(migrations.Migration):
("constituency", "Constituency"),
("constituency_2025", "Constituency (2024)"),
],
choices_enum=hub.models.ExternalDataSource.GeographyTypes,
choices_enum=hub.models.ExternalDataSource.PointFieldTypes,
default="postcode",
max_length=17,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Migration(migrations.Migration):
("parliamentary_constituency", "Constituency"),
("parliamentary_constituency_2025", "Constituency (2024)"),
],
choices_enum=hub.models.ExternalDataSource.GeographyTypes,
choices_enum=hub.models.ExternalDataSource.PointFieldTypes,
default="postcode",
max_length=31,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Migration(migrations.Migration):
("PARLIAMENTARY_CONSTITUENCY", "Constituency"),
("PARLIAMENTARY_CONSTITUENCY_2025", "Constituency (2024)"),
],
choices_enum=hub.models.ExternalDataSource.GeographyTypes,
choices_enum=hub.models.ExternalDataSource.PointFieldTypes,
default="POSTCODE",
max_length=31,
),
Expand Down
18 changes: 18 additions & 0 deletions hub/migrations/0136_genericdata_areas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-06-22 00:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("hub", "0135_hubhomepage_primary_colour_and_more"),
]

operations = [
migrations.AddField(
model_name="genericdata",
name="areas",
field=models.ManyToManyField(related_name="generic_data", to="hub.area"),
),
]
23 changes: 23 additions & 0 deletions hub/migrations/0137_add_more_geography_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.11 on 2024-06-22 00:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("hub", "0136_genericdata_areas"),
]

operations = [
migrations.RenameField(
model_name="externaldatasource",
old_name="geography_column",
new_name="point_field",
),
migrations.RenameField(
model_name="externaldatasource",
old_name="geography_column_type",
new_name="point_field_type",
)
]
45 changes: 45 additions & 0 deletions hub/migrations/0138_externaldatasource_polygon_field_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 4.2.11 on 2024-06-22 01:35

from django.db import migrations, models
import django_choices_field.fields
import hub.models


class Migration(migrations.Migration):

dependencies = [
("hub", "0137_add_more_geography_fields"),
]

operations = [
migrations.AddField(
model_name="externaldatasource",
name="polygon_field",
field=models.CharField(blank=True, max_length=250, null=True),
),
migrations.AddField(
model_name="externaldatasource",
name="polygon_field_type",
field=django_choices_field.fields.TextChoicesField(
choices=[
("WARD", "Ward"),
("ADMIN_DISTRICT", "Council"),
("PARLIAMENTARY_CONSTITUENCY", "Constituency"),
("PARLIAMENTARY_CONSTITUENCY_2025", "Constituency (2024)"),
],
choices_enum=hub.models.ExternalDataSource.PolygonFieldTypes,
default="PARLIAMENTARY_CONSTITUENCY_2025",
max_length=31,
),
),
migrations.AlterField(
model_name="externaldatasource",
name="point_field_type",
field=django_choices_field.fields.TextChoicesField(
choices=[("ADDRESS", "Address"), ("POSTCODE", "Postcode")],
choices_enum=hub.models.ExternalDataSource.PointFieldTypes,
default="POSTCODE",
max_length=8,
),
),
]
12 changes: 12 additions & 0 deletions hub/migrations/0139_enable_trigrams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Django 4.2.11 on 2024-06-22 01:35

from django.db import migrations
from django.contrib.postgres.operations import TrigramExtension


class Migration(migrations.Migration):
dependencies = [
("hub", "0138_externaldatasource_polygon_field_and_more"),
]

operations = [TrigramExtension()]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 4.2.11 on 2024-06-22 02:27

from django.db import migrations
import django_choices_field.fields
import hub.models


class Migration(migrations.Migration):

dependencies = [
("hub", "0139_enable_trigrams"),
]

operations = [
migrations.AlterField(
model_name="externaldatasource",
name="point_field_type",
field=django_choices_field.fields.TextChoicesField(
blank=True,
choices=[("ADDRESS", "Address"), ("POSTCODE", "Postcode")],
choices_enum=hub.models.ExternalDataSource.PointFieldTypes,
max_length=8,
null=True,
),
),
migrations.AlterField(
model_name="externaldatasource",
name="polygon_field_type",
field=django_choices_field.fields.TextChoicesField(
blank=True,
choices=[
("WARD", "Ward"),
("ADMIN_DISTRICT", "Council"),
("PARLIAMENTARY_CONSTITUENCY", "Constituency"),
("PARLIAMENTARY_CONSTITUENCY_2025", "Constituency (2024)"),
],
choices_enum=hub.models.ExternalDataSource.PolygonFieldTypes,
max_length=31,
null=True,
),
),
]
Loading