mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 16:40:36 +00:00
parent
c2c33fe1e8
commit
1b313c2b62
1 changed files with 20 additions and 6 deletions
|
@ -231,14 +231,28 @@ class FileLinkForm(CustomForm):
|
|||
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):
|
||||
|
|
Loading…
Reference in a new issue