Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileLinkForm: fix duplicate check #3311

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bookwyrm/forms/links.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" using django model forms """

from urllib.parse import urlparse

from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -37,10 +38,9 @@ def clean(self):
),
)
if (
not self.instance
and models.FileLink.objects.filter(
url=url, book=book, filetype=filetype
).exists()
models.FileLink.objects.filter(url=url, book=book, filetype=filetype)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but I would propose dropping filetype from this check. Thoughts?

(If file type is wrong and needs updating, the proposed change would ensure the pre-existing link is deleted first.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed; I'll change that in a separate PR after this one.

.exclude(pk=self.instance)
.exists()
):
# pylint: disable=line-too-long
self.add_error(
Expand Down
Loading