SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit e648807d authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add some cleaning

parent 4ab21c8b
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,19 @@ class AffiliateJournalAddPublicationForm(forms.ModelForm):
self.crossref_data = None
super().__init__(*args, **kwargs)
def clean(self, *args, **kwargs):
cleaned_data = super().clean(*args, **kwargs)
# Check that the journal specified in the DOI data is
# the same as in the form
print(self.crossref_data)
print(self.cleaned_data['journal'])
if (self.crossref_data['journal'] !=
self.cleaned_data['journal'].name):
raise forms.ValidationError(
'The journal specified in the DOI is different.')
return cleaned_data
def clean_doi(self):
input_doi = self.cleaned_data['doi']
......
......@@ -2,6 +2,7 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.contrib import messages
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse
......@@ -61,6 +62,9 @@ def affiliatejournal_add_publication(request, slug):
form = AffiliateJournalAddPublicationForm(request.POST or None)
if form.is_valid():
form.save()
else:
for error_messages in form.errors.values():
messages.warning(request, *error_messages)
return redirect(reverse('affiliates:journal_detail',
kwargs={'slug': slug}))
......
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