added check of existing url for book

sould also fix #1899
This commit is contained in:
Willi Hohenstein 2022-02-02 22:34:30 +01:00
parent c2c33fe1e8
commit 1b313c2b62

View file

@ -231,14 +231,28 @@ class FileLinkForm(CustomForm):
def clean(self): def clean(self):
"""make sure the domain isn't blocked or pending""" """make sure the domain isn't blocked or pending"""
cleaned_data = super().clean() 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 domain = urlparse(url).netloc
if models.LinkDomain.objects.filter(domain=domain).exists(): if models.LinkDomain.objects.filter(domain=domain).exists():
status = models.LinkDomain.objects.get(domain=domain).status status = models.LinkDomain.objects.get(domain=domain).status
if status == 'blocked': if status == "blocked":
self.add_error("url", _("Domain is blocked. Don't try this url again.")) self.add_error(
elif status == 'pending': "url",
self.add_error("url", _("Domain already pending. Please try later.")) _(
"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): class EditionForm(CustomForm):