Commit 10b86cfe7f0d523ca51bc39a422659cdddc885c5
Committed by
Sergio Oliveira
1 parent
a46e1191
Exists in
trac_indexing
Reformulating data_api fields
Showing
1 changed file
with
27 additions
and
16 deletions
Show diff stats
colab/proxy/trac/data_api.py
1 | -from colab.proxy.utils.proxy_data_api import ProxyDataAPI | |
1 | +from datetime import datetime | |
2 | +from re import match | |
3 | +from time import mktime | |
2 | 4 | import time |
5 | +import pytz | |
6 | + | |
3 | 7 | from django.db import connections |
4 | -from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki | |
5 | 8 | from django.utils import timezone |
6 | -from re import match | |
9 | +from django.utils.timezone import get_current_timezone_name | |
7 | 10 | |
11 | +from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki | |
12 | +from colab.proxy.utils.proxy_data_api import ProxyDataAPI | |
8 | 13 | |
9 | 14 | class TracDataAPI(ProxyDataAPI): |
10 | 15 | |
... | ... | @@ -20,17 +25,21 @@ class TracDataAPI(ProxyDataAPI): |
20 | 25 | attachment = Attachment() |
21 | 26 | cursor = self.attachment_cursor(empty_cursor) |
22 | 27 | attachment_dict = self.dictfetchall(cursor) |
28 | + time_zone = pytz.timezone(get_current_timezone_name()) | |
23 | 29 | for line in attachment_dict: |
24 | 30 | attachment.description = line['description'] |
25 | - attachment.id = line['attach_id'] | |
26 | - attachment.filename = line['filemame'] | |
31 | + attachment.id = attachment.attach_id | |
32 | + attachment.filename = line['filename'] | |
27 | 33 | attachment.title = attachment.filename |
28 | 34 | attachment.size = line['size'] |
29 | 35 | attachment.author = line['author'] |
30 | 36 | attachment.used_by = line['type'] |
31 | - attachment.url = attachment.user_by + "/" + attachment.id \ | |
37 | + attachment.url = attachment.used_by + "/" + attachment.id \ | |
32 | 38 | + "/" + attachment.filename |
33 | 39 | local_time = line['time']/1000000 |
40 | + naive_date_time = datetime.fromtimestamp(mktime(time.localtime(local_time))) | |
41 | + attachment.created = time_zone.localize(naive_date_time, is_dst=None).astimezone(pytz.utc) | |
42 | + | |
34 | 43 | attachment.modified = time.strftime('%Y-%m-%d %H:%M:%S', |
35 | 44 | time.localtime(local_time)) |
36 | 45 | if match("\.(\w+)$", attachment.filename): |
... | ... | @@ -43,21 +52,23 @@ class TracDataAPI(ProxyDataAPI): |
43 | 52 | revision_dict = self.dictfetchall(cursor) |
44 | 53 | cursor = self.repository_cursor(empty_cursor) |
45 | 54 | repository_dict = self.dictfetchall(cursor) |
55 | + time_zone = pytz.timezone(get_current_timezone_name()) | |
46 | 56 | for line in revision_dict: |
47 | 57 | revision.author = line['author'] |
48 | 58 | revision.rev = line['rev'] |
49 | 59 | revision.message = line['message'] |
50 | 60 | revision.description = revision.message |
51 | 61 | local_time = line['time']/1000000 |
52 | - revision.created = time.strftime('%Y-%m-%d %H:%M:%S', | |
53 | - time.localtime(local_time)) | |
54 | - revision.repository_name = repository_dict[line['value']] | |
62 | + naive_date_time = datetime.fromtimestamp(mktime(time.localtime(local_time))) | |
63 | + revision.created = time_zone.localize(naive_date_time, is_dst=None).astimezone(pytz.utc) | |
64 | + revision.repository_name = repository_dict[line['repos']] | |
55 | 65 | |
56 | 66 | def fetch_data_ticket(self, empty_cursor): |
57 | 67 | ticket = Ticket() |
58 | 68 | collaborators = [] |
59 | 69 | cursor = self.ticket_cursor(empty_cursor) |
60 | 70 | ticket_dict = self.dictfetchall(cursor) |
71 | + time_zone = pytz.timezone(get_current_timezone_name()) | |
61 | 72 | for line in ticket_dict: |
62 | 73 | ticket.id = line['id'] |
63 | 74 | ticket.summary = line['summary'] |
... | ... | @@ -73,12 +84,12 @@ class TracDataAPI(ProxyDataAPI): |
73 | 84 | ticket.keywords = line['keywords'] |
74 | 85 | ticket.author = ticket.reporter |
75 | 86 | local_time = line['time']/1000000 |
76 | - ticket.created = time.strftime('%Y-%m-%d %H:%M:%S', | |
77 | - time.localtime(local_time)) | |
87 | + naive_date_time = datetime.fromtimestamp(mktime(time.localtime(local_time))) | |
88 | + ticket.created = time_zone.localize(naive_date_time, is_dst=None).astimezone(pytz.utc) | |
78 | 89 | ticket.modified = str(timezone.now()) |
79 | 90 | ticket.modified_by = ticket.author |
80 | - if line['report'] not in collaborators: | |
81 | - collaborators.append(line['report']) | |
91 | + if line['reporter'] not in collaborators: | |
92 | + collaborators.append(line['reporter']) | |
82 | 93 | ticket.collaborators = collaborators |
83 | 94 | |
84 | 95 | def fetch_data_wiki(self, empty_cursor): |
... | ... | @@ -86,7 +97,7 @@ class TracDataAPI(ProxyDataAPI): |
86 | 97 | cursor = self.wiki_cursor(empty_cursor) |
87 | 98 | wiki_dict = self.dictfetchall(cursor) |
88 | 99 | collaborators = [] |
89 | - | |
100 | + time_zone = pytz.timezone(get_current_timezone_name()) | |
90 | 101 | for line in wiki_dict: |
91 | 102 | wiki.update_user(line['author']) |
92 | 103 | wiki.title = line['name'] |
... | ... | @@ -96,8 +107,8 @@ class TracDataAPI(ProxyDataAPI): |
96 | 107 | collaborators.append(line['author']) |
97 | 108 | wiki.collaborators = collaborators |
98 | 109 | local_time = line['time']/1000000 |
99 | - wiki.created = time.strftime('%Y-%m-%d %H:%M:%S', | |
100 | - time.localtime(local_time)) | |
110 | + naive_date_time = datetime.fromtimestamp(mktime(time.localtime(local_time))) | |
111 | + wiki.created = time_zone.localize(naive_date_time, is_dst=None).astimezone(pytz.utc) | |
101 | 112 | wiki.modified = str(timezone.now()) |
102 | 113 | wiki.save() |
103 | 114 | ... | ... |