Show More
@@ -1,5 +1,5 b'' | |||
|
1 | 1 | import re |
|
2 | import urllib | |
|
2 | import urllib.parse | |
|
3 | 3 | import httplib2 |
|
4 | 4 | from django.core.management import BaseCommand |
|
5 | 5 | from boards.models import GlobalId |
@@ -7,18 +7,23 b' from boards.models import GlobalId' | |||
|
7 | 7 | __author__ = 'neko259' |
|
8 | 8 | |
|
9 | 9 | |
|
10 |
REGEX_GLOBAL_ID = r'\[ |
|
|
10 | REGEX_GLOBAL_ID = re.compile(r'(\w+)::([\w\+/]+)::(\d+)') | |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | class Command(BaseCommand): |
|
14 | 14 | help = 'Send a sync or get request to the server.' + \ |
|
15 | 15 | 'sync_with_server <server_url> [post_global_id]' |
|
16 | 16 | |
|
17 | def add_arguments(self, parser): | |
|
18 | parser.add_argument('url', type=str) | |
|
19 | parser.add_argument('global_id', type=str) | |
|
20 | ||
|
17 | 21 | def handle(self, *args, **options): |
|
18 | url = args[0] | |
|
19 | if len(args) > 1: | |
|
20 |
|
|
|
21 |
match = |
|
|
22 | url = options.get('url') | |
|
23 | global_id_str = options.get('global_id') | |
|
24 | if global_id_str: | |
|
25 | match = REGEX_GLOBAL_ID.match(global_id_str) | |
|
26 | if match: | |
|
22 | 27 | key_type = match.group(1) |
|
23 | 28 | key = match.group(2) |
|
24 | 29 | local_id = match.group(3) |
@@ -28,10 +33,14 b' class Command(BaseCommand):' | |||
|
28 | 33 | |
|
29 | 34 | xml = GlobalId.objects.generate_request_get([global_id]) |
|
30 | 35 | data = {'xml': xml} |
|
31 | body = urllib.urlencode(data) | |
|
36 | body = urllib.parse.urlencode(data) | |
|
32 | 37 | h = httplib2.Http() |
|
33 | 38 | response, content = h.request(url, method="POST", body=body) |
|
34 | 39 | |
|
35 | 40 | # TODO Parse content and get the model list |
|
41 | ||
|
42 | print(content) | |
|
43 | else: | |
|
44 | raise Exception('Invalid global ID') | |
|
36 | 45 | else: |
|
37 | 46 | raise Exception('Full sync is not supported yet.') |
General Comments 0
You need to be logged in to leave comments.
Login now