33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
import os
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from django.core.files.base import ContentFile
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from fargo.utils import make_url
|
|
from fargo.fargo.models import Document
|
|
from fargo.oauth2.models import OAuth2TempFile, OAuth2Client
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Push documents inside fargo, returns URLs'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument('--client-id', type=int)
|
|
parser.add_argument('redirect_uri')
|
|
parser.add_argument('paths', nargs='+')
|
|
|
|
def handle(self, redirect_uri, paths, client_id, **options):
|
|
client = OAuth2Client.objects.get(id=client_id)
|
|
for path in paths:
|
|
with open(path, 'rb') as file_object:
|
|
filename = os.path.basename(path)
|
|
f = ContentFile(file_object.read(), name=filename)
|
|
document = Document.objects.get_by_file(f)
|
|
oauth2_document = OAuth2TempFile.objects.create(
|
|
client=client,
|
|
document=document,
|
|
filename=filename)
|
|
uri = reverse('oauth2-put-document-authorize', args=[oauth2_document.pk])
|
|
self.stdout.write('https://localhost:8000' + make_url(uri, redirect_uri=redirect_uri))
|