Commit 10b86cfe7f0d523ca51bc39a422659cdddc885c5

Authored by Thiago Ribeiro
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 import time 4 import time
  5 +import pytz
  6 +
3 from django.db import connections 7 from django.db import connections
4 -from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki  
5 from django.utils import timezone 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 class TracDataAPI(ProxyDataAPI): 14 class TracDataAPI(ProxyDataAPI):
10 15
@@ -20,17 +25,21 @@ class TracDataAPI(ProxyDataAPI): @@ -20,17 +25,21 @@ class TracDataAPI(ProxyDataAPI):
20 attachment = Attachment() 25 attachment = Attachment()
21 cursor = self.attachment_cursor(empty_cursor) 26 cursor = self.attachment_cursor(empty_cursor)
22 attachment_dict = self.dictfetchall(cursor) 27 attachment_dict = self.dictfetchall(cursor)
  28 + time_zone = pytz.timezone(get_current_timezone_name())
23 for line in attachment_dict: 29 for line in attachment_dict:
24 attachment.description = line['description'] 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 attachment.title = attachment.filename 33 attachment.title = attachment.filename
28 attachment.size = line['size'] 34 attachment.size = line['size']
29 attachment.author = line['author'] 35 attachment.author = line['author']
30 attachment.used_by = line['type'] 36 attachment.used_by = line['type']
31 - attachment.url = attachment.user_by + "/" + attachment.id \ 37 + attachment.url = attachment.used_by + "/" + attachment.id \
32 + "/" + attachment.filename 38 + "/" + attachment.filename
33 local_time = line['time']/1000000 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 attachment.modified = time.strftime('%Y-%m-%d %H:%M:%S', 43 attachment.modified = time.strftime('%Y-%m-%d %H:%M:%S',
35 time.localtime(local_time)) 44 time.localtime(local_time))
36 if match("\.(\w+)$", attachment.filename): 45 if match("\.(\w+)$", attachment.filename):
@@ -43,21 +52,23 @@ class TracDataAPI(ProxyDataAPI): @@ -43,21 +52,23 @@ class TracDataAPI(ProxyDataAPI):
43 revision_dict = self.dictfetchall(cursor) 52 revision_dict = self.dictfetchall(cursor)
44 cursor = self.repository_cursor(empty_cursor) 53 cursor = self.repository_cursor(empty_cursor)
45 repository_dict = self.dictfetchall(cursor) 54 repository_dict = self.dictfetchall(cursor)
  55 + time_zone = pytz.timezone(get_current_timezone_name())
46 for line in revision_dict: 56 for line in revision_dict:
47 revision.author = line['author'] 57 revision.author = line['author']
48 revision.rev = line['rev'] 58 revision.rev = line['rev']
49 revision.message = line['message'] 59 revision.message = line['message']
50 revision.description = revision.message 60 revision.description = revision.message
51 local_time = line['time']/1000000 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 def fetch_data_ticket(self, empty_cursor): 66 def fetch_data_ticket(self, empty_cursor):
57 ticket = Ticket() 67 ticket = Ticket()
58 collaborators = [] 68 collaborators = []
59 cursor = self.ticket_cursor(empty_cursor) 69 cursor = self.ticket_cursor(empty_cursor)
60 ticket_dict = self.dictfetchall(cursor) 70 ticket_dict = self.dictfetchall(cursor)
  71 + time_zone = pytz.timezone(get_current_timezone_name())
61 for line in ticket_dict: 72 for line in ticket_dict:
62 ticket.id = line['id'] 73 ticket.id = line['id']
63 ticket.summary = line['summary'] 74 ticket.summary = line['summary']
@@ -73,12 +84,12 @@ class TracDataAPI(ProxyDataAPI): @@ -73,12 +84,12 @@ class TracDataAPI(ProxyDataAPI):
73 ticket.keywords = line['keywords'] 84 ticket.keywords = line['keywords']
74 ticket.author = ticket.reporter 85 ticket.author = ticket.reporter
75 local_time = line['time']/1000000 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 ticket.modified = str(timezone.now()) 89 ticket.modified = str(timezone.now())
79 ticket.modified_by = ticket.author 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 ticket.collaborators = collaborators 93 ticket.collaborators = collaborators
83 94
84 def fetch_data_wiki(self, empty_cursor): 95 def fetch_data_wiki(self, empty_cursor):
@@ -86,7 +97,7 @@ class TracDataAPI(ProxyDataAPI): @@ -86,7 +97,7 @@ class TracDataAPI(ProxyDataAPI):
86 cursor = self.wiki_cursor(empty_cursor) 97 cursor = self.wiki_cursor(empty_cursor)
87 wiki_dict = self.dictfetchall(cursor) 98 wiki_dict = self.dictfetchall(cursor)
88 collaborators = [] 99 collaborators = []
89 - 100 + time_zone = pytz.timezone(get_current_timezone_name())
90 for line in wiki_dict: 101 for line in wiki_dict:
91 wiki.update_user(line['author']) 102 wiki.update_user(line['author'])
92 wiki.title = line['name'] 103 wiki.title = line['name']
@@ -96,8 +107,8 @@ class TracDataAPI(ProxyDataAPI): @@ -96,8 +107,8 @@ class TracDataAPI(ProxyDataAPI):
96 collaborators.append(line['author']) 107 collaborators.append(line['author'])
97 wiki.collaborators = collaborators 108 wiki.collaborators = collaborators
98 local_time = line['time']/1000000 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 wiki.modified = str(timezone.now()) 112 wiki.modified = str(timezone.now())
102 wiki.save() 113 wiki.save()
103 114