Format code using black

This commit is contained in:
Alexandre Iooss 2022-03-02 21:23:40 +01:00
parent 2ad0c8dbc7
commit 59136050fb
14 changed files with 809 additions and 413 deletions

View file

@ -5,26 +5,36 @@ from photologue.models import Gallery
class Command(BaseCommand):
help = 'List all duplicate for chosen galleries'
help = "List all duplicate for chosen galleries"
def add_arguments(self, parser):
parser.add_argument(
'--slugs', nargs='+', help='Try to find duplicate in the selected galleries', default=[])
parser.add_argument('-a', '--all', action='store_true',
help='Try to find duplicate in all galleries, overide any slugs given')
parser.add_argument('-d', '--delete', action='store_true')
"--slugs",
nargs="+",
help="Try to find duplicate in the selected galleries",
default=[],
)
parser.add_argument(
"-a",
"--all",
action="store_true",
help="Try to find duplicate in all galleries, overide any slugs given",
)
parser.add_argument("-d", "--delete", action="store_true")
def handle(self, *args, **options):
# Collect all required galleries
if options['all']:
if options["all"]:
galleries = Gallery.objects.all()
else:
galleries = []
for slug in options['slugs']:
for slug in options["slugs"]:
gallery_query = Gallery.objects.filter(slug=slug)
if not gallery_query:
raise CommandError(f"Slug {slug} does not correspond to a "
"gallery in the database.")
raise CommandError(
f"Slug {slug} does not correspond to a "
"gallery in the database."
)
galleries += gallery_query
# Find duplicates in all galleries
@ -32,18 +42,16 @@ class Command(BaseCommand):
duplicates = find_duplicate(gallery)
self.stdout.write(f"Gallery {gallery.slug}:")
for original, copies in duplicates:
self.stdout.write(f" {original.slug} is duplicated:", ending='')
self.stdout.write(f" {original.slug} is duplicated:", ending="")
for copy in copies:
self.stdout.write(f" {copy.slug}")
# Delete them if --delete
if options['delete']:
self.stdout.write(
' Deleting duplicate in {} :'.format(gallery.slug))
if options["delete"]:
self.stdout.write(" Deleting duplicate in {} :".format(gallery.slug))
for (_original, copies) in duplicates:
for copy in copies:
self.stdout.write(
' Deleting {}...'.format(copy.slug))
self.stdout.write(" Deleting {}...".format(copy.slug))
copy.delete()