X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/86c45b3bfdf6bdc52252b6565cad63a8cc7c2b5f..ac2e9ceea7cf6a59810081d52b64d9c22861c62d:/apps/api/management/commands/doc_update.py?ds=sidebyside diff --git a/apps/api/management/commands/doc_update.py b/apps/api/management/commands/doc_update.py new file mode 100644 index 00000000..525bb4a8 --- /dev/null +++ b/apps/api/management/commands/doc_update.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# -*- conding: utf-8 -*- +__author__="lreqc" +__date__ ="$2009-09-08 14:31:26$" + +from django.core.management.base import BaseCommand +from django.utils import simplejson as json +from django.test.client import Client +from django.core.urlresolvers import reverse + +from optparse import make_option + +class Command(BaseCommand): + + option_list = BaseCommand.option_list + ( + make_option('-u', '--user', action='store', dest='username'), + make_option('-p', '--password', action='store', dest='password'), + ) + + def handle(self, *args, **options): + client = Client() + if not options['username'] or not options['password']: + raise CommandError("You must provide login data") + + client.login(username=options['username'], \ + password=options['password']) + + print options['username'], options['password'] + + filename = args[0] + docid = args[1] + + url = reverse("document_view", args=[docid]) + print "Quering %s" % url + resp = client.get(url) + + result = json.loads(resp.content) + print result + + print "Current revision for '%s': %s" % (docid, result['user_revision']) + url = reverse("doctext_view", args=[ docid, result['user_revision'] ]) + print "Sending PUT to %s" % url + + resp = client.put(url, { + 'contents': open(filename).read(), + 'message': options['message'] or '' + + }) + + print resp.status_code, resp.content