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
|
@ -227,18 +227,32 @@ class FileLinkForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.FileLink
|
model = models.FileLink
|
||||||
fields = ["url", "filetype", "availability", "book", "added_by"]
|
fields = ["url", "filetype", "availability", "book", "added_by"]
|
||||||
|
|
||||||
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):
|
||||||
|
|
Loading…
Reference in a new issue