mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 09:31:08 +00:00
Add management commands to merge editions and authors
This commit is contained in:
parent
71e2486d01
commit
bd893e29de
3 changed files with 54 additions and 0 deletions
12
bookwyrm/management/commands/merge_authors.py
Normal file
12
bookwyrm/management/commands/merge_authors.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
""" PROCEED WITH CAUTION: uses deduplication fields to permanently
|
||||
merge author data objects """
|
||||
from bookwyrm import models
|
||||
from bookwyrm.management.merge_command import MergeCommand
|
||||
|
||||
|
||||
class Command(MergeCommand):
|
||||
"""merges two authors by ID"""
|
||||
|
||||
help = "merges specified authors into one"
|
||||
|
||||
MODEL = models.Author
|
12
bookwyrm/management/commands/merge_editions.py
Normal file
12
bookwyrm/management/commands/merge_editions.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
""" PROCEED WITH CAUTION: uses deduplication fields to permanently
|
||||
merge edition data objects """
|
||||
from bookwyrm import models
|
||||
from bookwyrm.management.merge_command import MergeCommand
|
||||
|
||||
|
||||
class Command(MergeCommand):
|
||||
"""merges two editions by ID"""
|
||||
|
||||
help = "merges specified editions into one"
|
||||
|
||||
MODEL = models.Edition
|
30
bookwyrm/management/merge_command.py
Normal file
30
bookwyrm/management/merge_command.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from bookwyrm.management.merge import merge_objects
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class MergeCommand(BaseCommand):
|
||||
"""base class for merge commands"""
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""add the arguments for this command"""
|
||||
parser.add_argument("--canonical", type=int, required=True)
|
||||
parser.add_argument("--other", type=int, required=True)
|
||||
|
||||
# pylint: disable=no-self-use,unused-argument
|
||||
def handle(self, *args, **options):
|
||||
"""merge the two objects"""
|
||||
model = self.MODEL
|
||||
|
||||
try:
|
||||
canonical = model.objects.get(id=options["canonical"])
|
||||
except model.DoesNotExist:
|
||||
print("canonical book doesn’t exist!")
|
||||
return
|
||||
try:
|
||||
other = model.objects.get(id=options["other"])
|
||||
except model.DoesNotExist:
|
||||
print("other book doesn’t exist!")
|
||||
return
|
||||
|
||||
merge_objects(canonical, other)
|
||||
|
Loading…
Reference in a new issue