Skip to content
Snippets Groups Projects
Commit 7a580e8c authored by Fanna Lautenbach's avatar Fanna Lautenbach
Browse files

add constraint and change error form for missing field key

parent 97938437
No related branches found
No related tags found
1 merge request!51add 'obs-id' as mandatory filter field
Pipeline #41515 passed
from django.core.exceptions import ValidationError
from .models import WorkSpecification, DataProductFilter
from django.forms import ModelForm
......@@ -20,6 +22,9 @@ class WorkSpecificationForm(ModelForm):
def clean(self):
self.cleaned_data = super().clean()
self.cleaned_data["filters"] = self._extract_filters()
if not 'obs_id' in self.cleaned_data["filters"]:
raise ValidationError(["You have forgotten about the 'obs_id'"])
return self.cleaned_data
class Meta:
......
......@@ -204,7 +204,11 @@
The input is invalid:
{% for field, errors in form.errors.items %}
{% for error in errors %}
<li class="text text--red text--faded">{{ field }}: {{ error }}</li>
{% if field == '__all__' %}
<li class="text text--red text--faded">{{ error }}</li>
{% else %}
<li class="text text--red text--faded">{{ field }}: {{ error }}</li>
{% endif %}
{% endfor %}
{% endfor %}
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment