08d61fe1afafff9d788599c9e3805028fc8059b1
[redakcja.git] / apps / api / management / commands / doc_share.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 NoArgsCommand
7
8 # from optparse import make_option
9
10 class Command(NoArgsCommand):
11       
12     def handle(self, *args, **options):
13         client = Client()
14         if not options['username'] or not options['password']:
15             raise CommandError("You must provide login data")
16
17         client.login(username=options['username'], \
18             password=options['password'])
19
20         print options['username'], options['password']
21
22         docid = args[0]
23
24         url = reverse("document_view", args=[docid])
25         print "Quering %s" % url
26         resp = client.get(url)
27
28         result = json.loads(resp.content)
29         print result
30
31         print "Current revision for '%s': %s" % (docid, result['user_revision'])
32         url = reverse("docmerge_view", args=[docid])
33         print "Sending POST to %s" % url
34         resp = client.post(url, {
35             'type': 'share',
36             'target_revision': result['user_revision'],
37             'message': 'Sharing.. :)'          
38         })
39
40         print resp.status_code, resp.content