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

@ -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):