Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
janbaykara committed Jan 5, 2025
1 parent ee90454 commit a8cfe59
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 39 deletions.
37 changes: 13 additions & 24 deletions hub/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
AreaData,
DataSet,
DataType,
ExternalDataSource,
GenericData,
Membership,
Organisation,
Person,
PersonData,
Report,
User,
UserProperties,
ExternalDataSource,
GenericData
)


Expand Down Expand Up @@ -265,38 +265,27 @@ class MembershipAdmin(admin.ModelAdmin):
OrganisationInline,
]


# External data source
@admin.register(ExternalDataSource)
class ExternalDataSourceAdmin(admin.ModelAdmin):
list_display = (
"name",
"orgname"
)
list_display = ("name", "orgname")

search_fields = ("name", "orgname")

search_fields = (
"name",
"orgname"
)

def orgname(self, obj):
return obj.organisation.name
orgname.admin_order_field = 'author' #Allows column order sorting
orgname.short_description = 'Author Name' #Renames column head

orgname.admin_order_field = "author" # Allows column order sorting
orgname.short_description = "Author Name" # Renames column head


# Generic data
@admin.register(GenericData)
class GenericDataAdmin(admin.ModelAdmin):
list_display = (
"name",
"source",
"value"
)
list_display = ("name", "source", "value")

search_fields = (
"name",
"source",
"value"
)
search_fields = ("name", "source", "value")

def source(self, obj):
return obj.data_type.data_set.external_data_source.name
return obj.data_type.data_set.external_data_source.name
6 changes: 4 additions & 2 deletions hub/data_imports/geocoding_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def import_record(
data_type: "DataType",
loaders: "Loaders",
):
from hub.models import GenericData, Geocoder, ExternalDataSource
from hub.models import ExternalDataSource, GenericData, Geocoder

update_data = get_update_data(source, record)
id = source.get_record_id(record)
Expand Down Expand Up @@ -155,7 +155,9 @@ async def import_area_data(

for item in source.geocoding_config.get("components", []):
parent_area = area
literal_lih_area_type__code = item.get("metadata", {}).get("lih_area_type__code", None)
literal_lih_area_type__code = item.get("metadata", {}).get(
"lih_area_type__code", None
)
literal_mapit_type = item.get("metadata", {}).get("mapit_type", None)
area_set = "LIH" if literal_lih_area_type__code is not None else "MAPIT"
area_types = literal_lih_area_type__code or literal_mapit_type
Expand Down
8 changes: 4 additions & 4 deletions hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,15 +1097,15 @@ class GeographyTypes(models.TextChoices):
def uses_valid_geocoding_config(self):
# TODO: Could replace this with a Pydantic schema or something
return (
self.geocoding_config is not None and
isinstance(self.geocoding_config, dict) and
self.geocoding_config.get("type", None) is not None
self.geocoding_config is not None
and isinstance(self.geocoding_config, dict)
and self.geocoding_config.get("type", None) is not None
and self.geocoding_config.get("type", None) in self.GeographyTypes.values
and self.geocoding_config.get("components", None) is not None
and isinstance(self.geocoding_config.get("components", None), list)
and len(self.geocoding_config.get("components", [])) > 0
) == True

geography_column_type = TextChoicesField(
choices_enum=GeographyTypes,
default=GeographyTypes.POSTCODE,
Expand Down
26 changes: 18 additions & 8 deletions hub/tests/test_external_data_source_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ def setUpTestData(cls):
geocoding_config={
"type": ExternalDataSource.GeographyTypes.AREA,
"components": [
{"field": "council", "metadata": { "lih_area_type__code": ["STC", "DIS"] }},
{"field": "ward", "metadata": { "lih_area_type__code": "WD23" }}
]
}
{
"field": "council",
"metadata": {"lih_area_type__code": ["STC", "DIS"]},
},
{"field": "ward", "metadata": {"lih_area_type__code": "WD23"}},
],
},
)

def test_geocoding_test_rig_is_valid(self):
Expand Down Expand Up @@ -183,7 +186,9 @@ def test_geocoding_matches(self):
try:
try:
if d.json["ward"] is None:
self.assertIsNone(d.postcode_data, "None shouldn't geocode.")
self.assertIsNone(
d.postcode_data, "None shouldn't geocode."
)
continue
elif d.json["expected_area_gss"] is None:
self.assertIsNone(
Expand Down Expand Up @@ -212,7 +217,9 @@ def test_geocoding_matches(self):
print(e)
print("Geocoding failed:", d.id, json.dumps(d.json, indent=4))
print("--Geocode data:", d.id, json.dumps(d.geocode_data, indent=4))
print("--Postcode data:", d.id, json.dumps(d.postcode_data, indent=4))
print(
"--Postcode data:", d.id, json.dumps(d.postcode_data, indent=4)
)
raise
except TypeError as e:
print(e)
Expand All @@ -231,9 +238,12 @@ def test_by_mapit_types(self):
"components": [
{
"field": "council",
"metadata": { "mapit_type": mapit_types.MAPIT_COUNCIL_TYPES },
"metadata": {"mapit_type": mapit_types.MAPIT_COUNCIL_TYPES},
},
{
"field": "ward",
"metadata": {"mapit_type": mapit_types.MAPIT_WARD_TYPES},
},
{"field": "ward", "metadata": { "mapit_type": mapit_types.MAPIT_WARD_TYPES}},
],
}
self.source.save()
Expand Down
2 changes: 1 addition & 1 deletion local_intelligence_hub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
# Application definition

INSTALLED_APPS = [
'django.contrib.gis',
"django.contrib.gis",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.postgres",
Expand Down

0 comments on commit a8cfe59

Please sign in to comment.