From 084f6d4b2f5c247e46f4d8efccbc5113583f9411 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 12 May 2016 01:35:08 -0400 Subject: [PATCH] Add an aditional step to verify that the update button is checked on required metadata types. --- mayan/apps/metadata/forms.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mayan/apps/metadata/forms.py b/mayan/apps/metadata/forms.py index d6a5a93cd6..e40ea1aab4 100644 --- a/mayan/apps/metadata/forms.py +++ b/mayan/apps/metadata/forms.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from django import forms +from django.core.exceptions import ValidationError from django.forms.formsets import formset_factory from django.utils.translation import string_concat, ugettext_lazy as _ @@ -81,6 +82,19 @@ class MetadataForm(forms.Form): ) def clean(self): + metadata_type = getattr(self, 'metadata_type', None) + + if metadata_type: + required = self.metadata_type.get_required_for( + document_type=self.document_type + ) + if required and not self.cleaned_data.get('update'): + raise ValidationError( + _( + '"%s" is required for this document type.' + ) % self.metadata_type.label + ) + if self.cleaned_data.get('update') and hasattr(self, 'metadata_type'): self.cleaned_data['value'] = self.metadata_type.validate_value( document_type=self.document_type,