diff --git a/freedoi/resolver/forms.py b/freedoi/resolver/forms.py index 822355c..26da0df 100644 --- a/freedoi/resolver/forms.py +++ b/freedoi/resolver/forms.py @@ -14,6 +14,12 @@ class PrefixForm(forms.ModelForm): if self.instance.pk: self.fields["prefix"].widget.attrs["readonly"] = True + def clean_suffix(self): + suffix = self.cleaned_data['suffix'] + if not suffix.isdigit() or len(suffix) < 2: + raise forms.ValidationError('Suffix must be numeric and at least four digits long.') + return suffix + class SuffixForm(forms.ModelForm): class Meta: @@ -32,6 +38,12 @@ class SuffixForm(forms.ModelForm): self.fields["suffix"].widget.attrs["readonly"] = True self.fields["prefix"].widget.attrs["readonly"] = True + def clean_suffix(self): + suffix = self.cleaned_data['suffix'] + if not suffix.isdigit() or len(suffix) < 4: + raise forms.ValidationError('Suffix must be numeric and at least four digits long.') + return suffix + class SuffixApprovalForm(forms.ModelForm): class Meta: @@ -52,6 +64,12 @@ class IdentifierForm(forms.ModelForm): self.fields["identifier"].widget.attrs["readonly"] = True self.fields["suffix"].widget.attrs["readonly"] = True + def clean_identifier(self): + identifier = self.cleaned_data['identifier'] + if not all(c.isalnum() or c in '/-' for c in identifier): + raise forms.ValidationError('Identifier must be alphanumeric or contain / or - characters only.') + return identifier + class PermissionForm(forms.ModelForm): class Meta: diff --git a/freedoi/resolver/templates/resolver/identifier_form.html b/freedoi/resolver/templates/resolver/identifier_form.html index c5d7564..562b314 100644 --- a/freedoi/resolver/templates/resolver/identifier_form.html +++ b/freedoi/resolver/templates/resolver/identifier_form.html @@ -4,6 +4,11 @@

{% if form.instance.pk %}Edit{% else %}Create{% endif %} Identifier

+ {% if form.errors %} + + {% endif %} {% csrf_token %} {{ form | crispy }}
diff --git a/freedoi/resolver/templates/resolver/prefix_form.html b/freedoi/resolver/templates/resolver/prefix_form.html index 9c752d0..6720d0c 100644 --- a/freedoi/resolver/templates/resolver/prefix_form.html +++ b/freedoi/resolver/templates/resolver/prefix_form.html @@ -3,6 +3,11 @@ {% load crispy_forms_tags %} {% block content %}

{% if form.instance.pk %}Edit{% else %}Create{% endif %} Prefix

+ {% if form.errors %} + + {% endif %} {% csrf_token %} {{ form | crispy }}
diff --git a/freedoi/resolver/templates/resolver/suffix_form.html b/freedoi/resolver/templates/resolver/suffix_form.html index 1085748..43e1d3a 100644 --- a/freedoi/resolver/templates/resolver/suffix_form.html +++ b/freedoi/resolver/templates/resolver/suffix_form.html @@ -4,6 +4,11 @@

{% if form.instance.pk %}Edit{% else %}Create{% endif %} Suffix

+ {% if form.errors %} + + {% endif %} {% csrf_token %} {{ form | crispy }}

Please make sure to include a full description of your intended use of the suffix in the "Description" field. Your request