From 1b313c2b624d81451735e4e404f8265c7375f181 Mon Sep 17 00:00:00 2001 From: Willi Hohenstein Date: Wed, 2 Feb 2022 22:34:30 +0100 Subject: [PATCH] added check of existing url for book sould also fix #1899 --- bookwyrm/forms.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 1b13598b..684fe91f 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -227,18 +227,32 @@ class FileLinkForm(CustomForm): class Meta: model = models.FileLink fields = ["url", "filetype", "availability", "book", "added_by"] - + def clean(self): """make sure the domain isn't blocked or pending""" cleaned_data = super().clean() - url = cleaned_data.get('url') + url = cleaned_data.get("url") + filetype = cleaned_data.get("filetype") + book = cleaned_data.get("book") domain = urlparse(url).netloc if models.LinkDomain.objects.filter(domain=domain).exists(): status = models.LinkDomain.objects.get(domain=domain).status - if status == 'blocked': - self.add_error("url", _("Domain is blocked. Don't try this url again.")) - elif status == 'pending': - self.add_error("url", _("Domain already pending. Please try later.")) + if status == "blocked": + self.add_error( + "url", + _( + "This domain is blocked. Please contact your administrator if you think this is an error." + ), + ) + elif models.FileLink.objects.filter( + url=url, book=book, filetype=filetype + ).exists(): + self.add_error( + "url", + _( + "This link with file type has already been added for this book. If it is not visible, the domain is still pending." + ), + ) class EditionForm(CustomForm):