Skip to content
Merged
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
10 changes: 5 additions & 5 deletions vbos/datasets/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def import_file(self, request):
VectorItem.objects.create(
dataset=form.cleaned_data["dataset"],
metadata=metadata.properties,
name=metadata.name,
name=metadata.name.strip(),
ref=metadata.ref,
attribute=metadata.attribute,
attribute=metadata.attribute.strip(),
province=Province.objects.filter(
name__iexact=metadata.province
name__iexact=metadata.province.strip()
).first(),
area_council=AreaCouncil.objects.filter(
name__iexact=metadata.area_council
name__iexact=metadata.area_council.strip()
).first(),
geometry=GEOSGeometry(json.dumps(item["geometry"])),
)
Expand Down Expand Up @@ -184,7 +184,7 @@ def import_file(self, request):
TabularItem.objects.create(
dataset=form.cleaned_data["dataset"],
metadata=csv_row.metadata,
attribute=csv_row.attribute,
attribute=csv_row.attribute.strip(),
value=csv_row.value,
date=csv_row.date,
province=Province.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion vbos/datasets/fixtures/test.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Year,Month,Attribute,Province,Area Council,Value,Other
2024,January,ecce,TAFEA,Futuna,1154,yes
2024,January,ecce ,TAFEA,Futuna,1154,yes
2022,may,secondary,TAFEA,Futuna,1154,no
2025,,primary,,,1154
6 changes: 2 additions & 4 deletions vbos/datasets/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ class Meta:


class ProvinceSerializer(GeoFeatureModelSerializer):

class Meta:
model = Province
geo_field = "geometry"
fields = "__all__"


class AreaCouncilSerializer(GeoFeatureModelSerializer):

class Meta:
model = AreaCouncil
geo_field = "geometry"
Expand Down Expand Up @@ -146,8 +144,8 @@ def __init__(self, *args, **kwargs):
queryset = self.context["view"].get_queryset()
all_keys = set()
for item in queryset:
if item.data and isinstance(item.data, dict):
all_keys.update(item.data.keys())
if item.metadata and isinstance(item.metadata, dict):
all_keys.update(item.metadata.keys())

# Create a field for each key
for key in all_keys:
Expand Down
4 changes: 4 additions & 0 deletions vbos/datasets/test/test_tabular_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ def test_tabular_datasets_data(self):
assert req.data.get("results")[0]["attribute"] == "Employed Population"
assert req.data.get("results")[0]["additional_value"] == "test"

# test xlsx format
req = self.client.get(url, {"format": "xlsx"})
assert req.status_code == status.HTTP_200_OK

def test_filter_data(self):
url = reverse("datasets:tabular-data", args=[self.dataset_2.id])
req = self.client.get(url, {"date_after": "2025-01-01"})
Expand Down