Refactor archive_feed command to confirm deletion of entries before proceeding
All checks were successful
Deploy to Server / deploy (push) Successful in 12s
All checks were successful
Deploy to Server / deploy (push) Successful in 12s
This commit is contained in:
parent
603090205a
commit
f9cac0974d
1 changed files with 23 additions and 10 deletions
|
|
@ -56,14 +56,18 @@ class Command(BaseCommand):
|
||||||
if count == 0:
|
if count == 0:
|
||||||
msg = f"No entries found for feed: {url}"
|
msg = f"No entries found for feed: {url}"
|
||||||
self.stdout.write(self.style.WARNING(msg))
|
self.stdout.write(self.style.WARNING(msg))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
proceed: bool = True
|
||||||
if not force:
|
if not force:
|
||||||
return self.confirm_and_list_entries(url, entries_qs, count)
|
proceed: bool = self.confirm_and_list_entries(
|
||||||
|
url=url,
|
||||||
entries_qs.delete()
|
entries_qs=entries_qs,
|
||||||
msg = f"Deleted {count} entries for feed: {url}"
|
count=count,
|
||||||
self.stdout.write(self.style.SUCCESS(msg))
|
)
|
||||||
|
if proceed:
|
||||||
|
entries_qs.delete()
|
||||||
|
msg = f"Deleted {count} entries for feed: {url}"
|
||||||
|
self.stdout.write(self.style.SUCCESS(msg))
|
||||||
|
|
||||||
new_entries: int = fetch_and_archive_feed(feed)
|
new_entries: int = fetch_and_archive_feed(feed)
|
||||||
if new_entries:
|
if new_entries:
|
||||||
|
|
@ -73,15 +77,23 @@ class Command(BaseCommand):
|
||||||
else:
|
else:
|
||||||
msg: str = "\tFeed is up to date, but no new entries were archived."
|
msg: str = "\tFeed is up to date, but no new entries were archived."
|
||||||
self.stdout.write(self.style.WARNING(msg))
|
self.stdout.write(self.style.WARNING(msg))
|
||||||
return None
|
|
||||||
|
|
||||||
def confirm_and_list_entries(
|
def confirm_and_list_entries(
|
||||||
self,
|
self,
|
||||||
url: str,
|
url: str,
|
||||||
entries_qs: QuerySet[Entry, Entry],
|
entries_qs: QuerySet[Entry, Entry],
|
||||||
count: int,
|
count: int,
|
||||||
) -> None:
|
) -> bool:
|
||||||
"""Confirm with the user before deleting entries and list some of them."""
|
"""Confirm with the user before deleting entries and list some of them.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url (str): The URL of the feed.
|
||||||
|
entries_qs (QuerySet[Entry, Entry]): The queryset of entries to be deleted.
|
||||||
|
count (int): The total number of entries to be deleted.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if user confirms, False otherwise.
|
||||||
|
"""
|
||||||
msg: str = f"The following {count} entries will be removed for feed: {url}"
|
msg: str = f"The following {count} entries will be removed for feed: {url}"
|
||||||
self.stdout.write(self.style.WARNING(msg))
|
self.stdout.write(self.style.WARNING(msg))
|
||||||
|
|
||||||
|
|
@ -94,7 +106,8 @@ class Command(BaseCommand):
|
||||||
confirm: str = input("Are you sure you want to proceed? (yes/no): ")
|
confirm: str = input("Are you sure you want to proceed? (yes/no): ")
|
||||||
if confirm.lower() != "yes":
|
if confirm.lower() != "yes":
|
||||||
self.stdout.write(self.style.ERROR("Operation cancelled."))
|
self.stdout.write(self.style.ERROR("Operation cancelled."))
|
||||||
return
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_entry_title(entry: Entry) -> str | None:
|
def get_entry_title(entry: Entry) -> str | None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue