Dodanie przycisków do zapisywania i usuwania fragmentów.
[redakcja.git] / apps / api / management / commands / doc_update_text.py
1 #!/usr/bin/env python
2 # -*- conding: utf-8 -*-
3 __author__="lreqc"
4 __date__ ="$2009-09-08 14:31:26$"
5
6 from django.core.management.base import BaseCommand
7 from django.utils import simplejson as json
8 from django.test.client import Client
9 from django.core.urlresolvers import reverse
10
11 from optparse import make_option
12
13 class Command(BaseCommand):
14     
15     option_list = BaseCommand.option_list + (
16         make_option('-u', '--user', action='store', dest='username'),
17         make_option('-p', '--password', action='store', dest='password'),
18         make_option('-m', '--message', action='store', dest='message'),
19     )
20     
21     def handle(self, *args, **options):
22         client = Client()
23         if not options['username'] or not options['password']:
24             raise CommandError("You must provide login data")
25
26         client.login(username=options['username'], \
27             password=options['password'])
28
29         print options['username'], options['password']
30
31         filename = args[0]
32         docid = args[1]
33
34         url = reverse("document_view", args=[docid])
35         print "Quering %s" % url
36         resp = client.get(url)
37
38         result = json.loads(resp.content)
39         print result
40
41         print "Current revision for '%s': %s" % (docid, result['user_revision'])
42         url = reverse("doctext_view", args=[ docid, result['user_revision'] ])
43         print "Sending PUT to %s" % url
44
45         resp = client.put(url, {
46             'contents': open(filename).read(),
47             'message': options['message'] or ''
48             
49         })
50
51         print resp.status_code, resp.content