Informowanie widoku XMLView o zmianie zawartoĊ›ci po wstawieniu taga przy pomocy przyc...
[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 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     )
19     
20     def handle(self, *args, **options):
21         client = Client()
22         if not options['username'] or not options['password']:
23             raise CommandError("You must provide login data")
24
25         client.login(username=options['username'], \
26             password=options['password'])
27
28         print options['username'], options['password']
29
30         docid = args[0]
31
32         url = reverse("document_view", args=[docid])
33         print "Quering %s" % url
34         resp = client.get(url)
35
36         result = json.loads(resp.content)
37         print result
38
39         print "Current revision for '%s': %s" % (docid, result['user_revision'])
40         url = reverse("docmerge_view", args=[docid])
41         print "Sending POST to %s" % url
42         resp = client.post(url, {
43             'type': 'share',
44             'target_revision': result['user_revision'],
45             'message': 'Sharing.. :)'          
46         })
47
48         print resp.status_code, resp.content