Commit 4193a02abb0382b648b9c48efe1e200a85e7ab20
Committed by
Sergio Oliveira
1 parent
10b86cfe
Exists in
trac_indexing
Getting created and modified fields correctly.
Signed-off-by: Carolina Ramalho <carol15022@hotmail.com>
Showing
3 changed files
with
56 additions
and
29 deletions
Show diff stats
colab/proxy/trac/data_api.py
1 | -from datetime import datetime | ||
2 | from re import match | 1 | from re import match |
3 | from time import mktime | 2 | from time import mktime |
4 | -import time | ||
5 | -import pytz | 3 | +import datetime |
6 | 4 | ||
7 | from django.db import connections | 5 | from django.db import connections |
8 | -from django.utils import timezone | ||
9 | -from django.utils.timezone import get_current_timezone_name | ||
10 | 6 | ||
11 | from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki | 7 | from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki |
12 | from colab.proxy.utils.proxy_data_api import ProxyDataAPI | 8 | from colab.proxy.utils.proxy_data_api import ProxyDataAPI |
@@ -25,23 +21,18 @@ class TracDataAPI(ProxyDataAPI): | @@ -25,23 +21,18 @@ class TracDataAPI(ProxyDataAPI): | ||
25 | attachment = Attachment() | 21 | attachment = Attachment() |
26 | cursor = self.attachment_cursor(empty_cursor) | 22 | cursor = self.attachment_cursor(empty_cursor) |
27 | attachment_dict = self.dictfetchall(cursor) | 23 | attachment_dict = self.dictfetchall(cursor) |
28 | - time_zone = pytz.timezone(get_current_timezone_name()) | ||
29 | for line in attachment_dict: | 24 | for line in attachment_dict: |
30 | attachment.description = line['description'] | 25 | attachment.description = line['description'] |
31 | - attachment.id = attachment.attach_id | 26 | + attachment.id = line['id'] |
32 | attachment.filename = line['filename'] | 27 | attachment.filename = line['filename'] |
33 | attachment.title = attachment.filename | 28 | attachment.title = attachment.filename |
34 | attachment.size = line['size'] | 29 | attachment.size = line['size'] |
35 | attachment.author = line['author'] | 30 | attachment.author = line['author'] |
36 | attachment.used_by = line['type'] | 31 | attachment.used_by = line['type'] |
32 | + attachment.ipnr = line['ipnr'] | ||
37 | attachment.url = attachment.used_by + "/" + attachment.id \ | 33 | attachment.url = attachment.used_by + "/" + attachment.id \ |
38 | + "/" + attachment.filename | 34 | + "/" + attachment.filename |
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 | - | ||
43 | - attachment.modified = time.strftime('%Y-%m-%d %H:%M:%S', | ||
44 | - time.localtime(local_time)) | 35 | + attachment.created = self.get_attachment_created(cursor, line['id']) |
45 | if match("\.(\w+)$", attachment.filename): | 36 | if match("\.(\w+)$", attachment.filename): |
46 | attachment.mimetype = attachment.filename.lower() | 37 | attachment.mimetype = attachment.filename.lower() |
47 | attachment.save() | 38 | attachment.save() |
@@ -52,15 +43,12 @@ class TracDataAPI(ProxyDataAPI): | @@ -52,15 +43,12 @@ class TracDataAPI(ProxyDataAPI): | ||
52 | revision_dict = self.dictfetchall(cursor) | 43 | revision_dict = self.dictfetchall(cursor) |
53 | cursor = self.repository_cursor(empty_cursor) | 44 | cursor = self.repository_cursor(empty_cursor) |
54 | repository_dict = self.dictfetchall(cursor) | 45 | repository_dict = self.dictfetchall(cursor) |
55 | - time_zone = pytz.timezone(get_current_timezone_name()) | ||
56 | for line in revision_dict: | 46 | for line in revision_dict: |
57 | revision.author = line['author'] | 47 | revision.author = line['author'] |
58 | revision.rev = line['rev'] | 48 | revision.rev = line['rev'] |
59 | revision.message = line['message'] | 49 | revision.message = line['message'] |
60 | revision.description = revision.message | 50 | revision.description = revision.message |
61 | - local_time = line['time']/1000000 | ||
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) | 51 | + revision.created = self.get_revision_created(cursor, line['rev']) |
64 | revision.repository_name = repository_dict[line['repos']] | 52 | revision.repository_name = repository_dict[line['repos']] |
65 | 53 | ||
66 | def fetch_data_ticket(self, empty_cursor): | 54 | def fetch_data_ticket(self, empty_cursor): |
@@ -68,7 +56,6 @@ class TracDataAPI(ProxyDataAPI): | @@ -68,7 +56,6 @@ class TracDataAPI(ProxyDataAPI): | ||
68 | collaborators = [] | 56 | collaborators = [] |
69 | cursor = self.ticket_cursor(empty_cursor) | 57 | cursor = self.ticket_cursor(empty_cursor) |
70 | ticket_dict = self.dictfetchall(cursor) | 58 | ticket_dict = self.dictfetchall(cursor) |
71 | - time_zone = pytz.timezone(get_current_timezone_name()) | ||
72 | for line in ticket_dict: | 59 | for line in ticket_dict: |
73 | ticket.id = line['id'] | 60 | ticket.id = line['id'] |
74 | ticket.summary = line['summary'] | 61 | ticket.summary = line['summary'] |
@@ -82,11 +69,11 @@ class TracDataAPI(ProxyDataAPI): | @@ -82,11 +69,11 @@ class TracDataAPI(ProxyDataAPI): | ||
82 | ticket.status = line['status'] | 69 | ticket.status = line['status'] |
83 | ticket.tag = ticket.status | 70 | ticket.tag = ticket.status |
84 | ticket.keywords = line['keywords'] | 71 | ticket.keywords = line['keywords'] |
72 | + ticket.owner = line['owner'] | ||
73 | + ticket.resolution = line['resolution'] | ||
85 | ticket.author = ticket.reporter | 74 | ticket.author = ticket.reporter |
86 | - local_time = line['time']/1000000 | ||
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) | ||
89 | - ticket.modified = str(timezone.now()) | 75 | + ticket.created = self.get_ticket_created(cursor, line['id']) |
76 | + ticket.modified = self.get_ticket_modified(cursor, line['id']) | ||
90 | ticket.modified_by = ticket.author | 77 | ticket.modified_by = ticket.author |
91 | if line['reporter'] not in collaborators: | 78 | if line['reporter'] not in collaborators: |
92 | collaborators.append(line['reporter']) | 79 | collaborators.append(line['reporter']) |
@@ -97,7 +84,6 @@ class TracDataAPI(ProxyDataAPI): | @@ -97,7 +84,6 @@ class TracDataAPI(ProxyDataAPI): | ||
97 | cursor = self.wiki_cursor(empty_cursor) | 84 | cursor = self.wiki_cursor(empty_cursor) |
98 | wiki_dict = self.dictfetchall(cursor) | 85 | wiki_dict = self.dictfetchall(cursor) |
99 | collaborators = [] | 86 | collaborators = [] |
100 | - time_zone = pytz.timezone(get_current_timezone_name()) | ||
101 | for line in wiki_dict: | 87 | for line in wiki_dict: |
102 | wiki.update_user(line['author']) | 88 | wiki.update_user(line['author']) |
103 | wiki.title = line['name'] | 89 | wiki.title = line['name'] |
@@ -106,10 +92,9 @@ class TracDataAPI(ProxyDataAPI): | @@ -106,10 +92,9 @@ class TracDataAPI(ProxyDataAPI): | ||
106 | if line['author'] not in collaborators: | 92 | if line['author'] not in collaborators: |
107 | collaborators.append(line['author']) | 93 | collaborators.append(line['author']) |
108 | wiki.collaborators = collaborators | 94 | wiki.collaborators = collaborators |
109 | - local_time = line['time']/1000000 | ||
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) | ||
112 | - wiki.modified = str(timezone.now()) | 95 | + wiki.created =self.get_wiki_created(cursor, line['name']) |
96 | + wiki.modified = self.get_wiki_modified(cursor, line['name']) | ||
97 | + | ||
113 | wiki.save() | 98 | wiki.save() |
114 | 99 | ||
115 | def dictfetchall(self, cursor): | 100 | def dictfetchall(self, cursor): |
@@ -138,3 +123,39 @@ class TracDataAPI(ProxyDataAPI): | @@ -138,3 +123,39 @@ class TracDataAPI(ProxyDataAPI): | ||
138 | def repository_cursor(self, cursor): | 123 | def repository_cursor(self, cursor): |
139 | cursor.execute('''SELECT * FROM repository;''') | 124 | cursor.execute('''SELECT * FROM repository;''') |
140 | return cursor | 125 | return cursor |
126 | + | ||
127 | + def get_wiki_modified(self, cursor, wiki_name): | ||
128 | + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MAX(wiki.time)/1000000) * INTERVAL '1s', name from wiki where(name=\'"""+ wiki_name + """\') group by name; """) | ||
129 | + matriz_data_wiki = cursor.fetchall() | ||
130 | + modified_data = matriz_data_wiki[0][0] | ||
131 | + return modified_data | ||
132 | + | ||
133 | + def get_wiki_created(self, cursor, wiki_name): | ||
134 | + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(wiki.time)/1000000) * INTERVAL '1s', name from wiki where(name=\'"""+ wiki_name + """\') group by name; """) | ||
135 | + matrix_data_wiki = cursor.fetchall() | ||
136 | + modified_data = matrix_data_wiki[0][0] | ||
137 | + return modified_data | ||
138 | + | ||
139 | + def get_attachment_created(self, cursor, attachment_id): | ||
140 | + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(attachment.time)/1000000) * INTERVAL '1s', id from attachment where(id=\'"""+ attachment_id + """\') group by id; """) | ||
141 | + matriz_data_attachment = cursor.fetchall() | ||
142 | + modified_data = matriz_data_attachment[0][0] | ||
143 | + return modified_data | ||
144 | + | ||
145 | + def get_revision_created(self, cursor, revision): | ||
146 | + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(revision.time)/1000000) * INTERVAL '1s', rev from revision where(rev=\'"""+ revision + """\') group by rev; """) | ||
147 | + matriz_data_revision = cursor.fetchall() | ||
148 | + modified_data = matriz_data_revision[0][0] | ||
149 | + return modified_data | ||
150 | + | ||
151 | + def get_ticket_created(self, cursor, ticket_id): | ||
152 | + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(ticket.time)/1000000) * INTERVAL '1s', id from ticket where(id="""+ str(ticket_id) + """) group by id; """) | ||
153 | + matriz_data_ticket = cursor.fetchall() | ||
154 | + modified_data = matriz_data_ticket[0][0] | ||
155 | + return modified_data | ||
156 | + | ||
157 | + def get_ticket_modified(self, cursor, ticket_id): | ||
158 | + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MAX(ticket.time)/1000000) * INTERVAL '1s', id from ticket where(id="""+ str(ticket_id) + """) group by id; """) | ||
159 | + matriz_data_ticket = cursor.fetchall() | ||
160 | + modified_data = matriz_data_ticket[0][0] | ||
161 | + return modified_data |
colab/proxy/trac/migrations/0001_initial.py
@@ -27,6 +27,7 @@ class Migration(migrations.Migration): | @@ -27,6 +27,7 @@ class Migration(migrations.Migration): | ||
27 | ('modified', models.DateTimeField(blank=True)), | 27 | ('modified', models.DateTimeField(blank=True)), |
28 | ('mimetype', models.TextField(blank=True)), | 28 | ('mimetype', models.TextField(blank=True)), |
29 | ('size', models.IntegerField(blank=True)), | 29 | ('size', models.IntegerField(blank=True)), |
30 | + ('ipnr', models.TextField(blank=True)), | ||
30 | ], | 31 | ], |
31 | options={ | 32 | options={ |
32 | 'verbose_name': 'Attachment', | 33 | 'verbose_name': 'Attachment', |
@@ -72,6 +73,8 @@ class Migration(migrations.Migration): | @@ -72,6 +73,8 @@ class Migration(migrations.Migration): | ||
72 | ('created', models.DateTimeField(null=True, blank=True)), | 73 | ('created', models.DateTimeField(null=True, blank=True)), |
73 | ('modified', models.DateTimeField(null=True, blank=True)), | 74 | ('modified', models.DateTimeField(null=True, blank=True)), |
74 | ('modified_by', models.TextField(blank=True)), | 75 | ('modified_by', models.TextField(blank=True)), |
76 | + ('owner', models.TextField(blank=True)), | ||
77 | + ('resolution', models.TextField(blank=True)), | ||
75 | ], | 78 | ], |
76 | options={ | 79 | options={ |
77 | 'verbose_name': 'Ticket', | 80 | 'verbose_name': 'Ticket', |
@@ -88,6 +91,7 @@ class Migration(migrations.Migration): | @@ -88,6 +91,7 @@ class Migration(migrations.Migration): | ||
88 | ('collaborators', models.TextField(blank=True)), | 91 | ('collaborators', models.TextField(blank=True)), |
89 | ('created', models.DateTimeField(null=True, blank=True)), | 92 | ('created', models.DateTimeField(null=True, blank=True)), |
90 | ('modified', models.DateTimeField(null=True, blank=True)), | 93 | ('modified', models.DateTimeField(null=True, blank=True)), |
94 | + ('comment', models.TextField(blank=True)), | ||
91 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), | 95 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), |
92 | ], | 96 | ], |
93 | options={ | 97 | options={ |
colab/proxy/trac/models.py
@@ -22,9 +22,10 @@ class Attachment(models.Model, HitCounterModelMixin): | @@ -22,9 +22,10 @@ class Attachment(models.Model, HitCounterModelMixin): | ||
22 | author = models.TextField(blank=True) | 22 | author = models.TextField(blank=True) |
23 | title = models.TextField(blank=True) | 23 | title = models.TextField(blank=True) |
24 | description = models.TextField(blank=True) | 24 | description = models.TextField(blank=True) |
25 | - modified = models.DateTimeField(blank=True) | 25 | + created = models.DateTimeField(blank=True) |
26 | mimetype = models.TextField(blank=True) | 26 | mimetype = models.TextField(blank=True) |
27 | size = models.IntegerField(blank=True) | 27 | size = models.IntegerField(blank=True) |
28 | + ipnr = models.TextField(blank=True) | ||
28 | 29 | ||
29 | class Meta: | 30 | class Meta: |
30 | verbose_name = _('Attachment') | 31 | verbose_name = _('Attachment') |
@@ -58,7 +59,6 @@ class Revision(models.Model, HitCounterModelMixin): | @@ -58,7 +59,6 @@ class Revision(models.Model, HitCounterModelMixin): | ||
58 | description = models.TextField(blank=True) | 59 | description = models.TextField(blank=True) |
59 | repository_name = models.TextField(blank=True) | 60 | repository_name = models.TextField(blank=True) |
60 | created = models.DateTimeField(blank=True, null=True) | 61 | created = models.DateTimeField(blank=True, null=True) |
61 | - modified = models.DateTimeField(blank=True, null=True) | ||
62 | 62 | ||
63 | @property | 63 | @property |
64 | def title(self): | 64 | def title(self): |
@@ -97,6 +97,8 @@ class Ticket(models.Model, HitCounterModelMixin): | @@ -97,6 +97,8 @@ class Ticket(models.Model, HitCounterModelMixin): | ||
97 | created = models.DateTimeField(blank=True, null=True) | 97 | created = models.DateTimeField(blank=True, null=True) |
98 | modified = models.DateTimeField(blank=True, null=True) | 98 | modified = models.DateTimeField(blank=True, null=True) |
99 | modified_by = models.TextField(blank=True) | 99 | modified_by = models.TextField(blank=True) |
100 | + owner = models.TextField(blank=True) | ||
101 | + resolution = models.TextField(blank=True) | ||
100 | 102 | ||
101 | @property | 103 | @property |
102 | def title(self): | 104 | def title(self): |