26 lines
811 B
Python
26 lines
811 B
Python
from django.core.management.base import BaseCommand, CommandError
|
|
from library.models import Work, Collection
|
|
from library.gdrive import sync_work, sync_collection
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Synchronizes folders and works"
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument("type", type=str, choices=["work", "collection"])
|
|
parser.add_argument("pk", nargs="?", type=int)
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
if options["type"] == "work":
|
|
work = Work.objects.get(pk=options["pk"])
|
|
sync_work(work)
|
|
return
|
|
|
|
if options["type"] == "collection":
|
|
collection = Collection.objects.get(pk=options["pk"])
|
|
sync_collection(collection)
|
|
return
|
|
|
|
raise CommandError("Unknown object type")
|