Skip to content

Commit

Permalink
[Fixes GeoNode#10945] Time serie raise issue when has time is selecte…
Browse files Browse the repository at this point in the history
…d without Time series settining provided (GeoNode#10946)

Co-authored-by: Giovanni Allegri <[email protected]>
  • Loading branch information
mattiagiupponi and giohappy authored Apr 21, 2023
1 parent 35b1eb1 commit d68e996
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions geonode/layers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,30 @@ def test_dataset_time_form_should_raise_error_if_invalid_payload(self):
form.errors["presentation"][0],
)

def test_resource_form_is_invalid_with_incompleted_timeserie_data(self):
self.client.login(username="admin", password="admin")
url = reverse("dataset_metadata", args=(self.dataset.alternate,))
response = self.client.post(
url,
data={
"resource-owner": self.dataset.owner.id,
"resource-title": "layer_title",
"resource-date": "2022-01-24 16:38 pm",
"resource-date_type": "creation",
"resource-language": "eng",
"resource-has_time": True,
"dataset_attribute_set-TOTAL_FORMS": 0,
"dataset_attribute_set-INITIAL_FORMS": 0,
},
)
expected = {
"success": False,
"errors": [
"The Timeseries configuration is invalid. Please select at least one option between the `attribute` and `end_attribute`, otherwise remove the 'has_time' flag"
],
}
self.assertDictEqual(expected, response.json())


class SetLayersPermissionsCommand(GeoNodeBaseTestSupport):
"""
Expand Down
14 changes: 14 additions & 0 deletions geonode/layers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,20 @@ def dataset_metadata(
}
logger.error(f"{out.get('errors')}")
return HttpResponse(json.dumps(out), content_type="application/json", status=400)
elif (
layer.has_time
and timeseries_form.is_valid()
and not timeseries_form.cleaned_data.get("attribute", "")
and not timeseries_form.cleaned_data.get("end_attribute", "")
):
out = {
"success": False,
"errors": [
"The Timeseries configuration is invalid. Please select at least one option between the `attribute` and `end_attribute`, otherwise remove the 'has_time' flag"
],
}
logger.error(f"{out.get('errors')}")
return HttpResponse(json.dumps(out), content_type="application/json", status=400)
else:
dataset_form = DatasetForm(instance=layer, prefix="resource", user=request.user)
dataset_form.disable_keywords_widget_for_non_superuser(request.user)
Expand Down

0 comments on commit d68e996

Please sign in to comment.