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 | 1 | from re import match |
3 | 2 | from time import mktime |
4 | -import time | |
5 | -import pytz | |
3 | +import datetime | |
6 | 4 | |
7 | 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 | 7 | from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki |
12 | 8 | from colab.proxy.utils.proxy_data_api import ProxyDataAPI |
... | ... | @@ -25,23 +21,18 @@ class TracDataAPI(ProxyDataAPI): |
25 | 21 | attachment = Attachment() |
26 | 22 | cursor = self.attachment_cursor(empty_cursor) |
27 | 23 | attachment_dict = self.dictfetchall(cursor) |
28 | - time_zone = pytz.timezone(get_current_timezone_name()) | |
29 | 24 | for line in attachment_dict: |
30 | 25 | attachment.description = line['description'] |
31 | - attachment.id = attachment.attach_id | |
26 | + attachment.id = line['id'] | |
32 | 27 | attachment.filename = line['filename'] |
33 | 28 | attachment.title = attachment.filename |
34 | 29 | attachment.size = line['size'] |
35 | 30 | attachment.author = line['author'] |
36 | 31 | attachment.used_by = line['type'] |
32 | + attachment.ipnr = line['ipnr'] | |
37 | 33 | attachment.url = attachment.used_by + "/" + attachment.id \ |
38 | 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 | 36 | if match("\.(\w+)$", attachment.filename): |
46 | 37 | attachment.mimetype = attachment.filename.lower() |
47 | 38 | attachment.save() |
... | ... | @@ -52,15 +43,12 @@ class TracDataAPI(ProxyDataAPI): |
52 | 43 | revision_dict = self.dictfetchall(cursor) |
53 | 44 | cursor = self.repository_cursor(empty_cursor) |
54 | 45 | repository_dict = self.dictfetchall(cursor) |
55 | - time_zone = pytz.timezone(get_current_timezone_name()) | |
56 | 46 | for line in revision_dict: |
57 | 47 | revision.author = line['author'] |
58 | 48 | revision.rev = line['rev'] |
59 | 49 | revision.message = line['message'] |
60 | 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 | 52 | revision.repository_name = repository_dict[line['repos']] |
65 | 53 | |
66 | 54 | def fetch_data_ticket(self, empty_cursor): |
... | ... | @@ -68,7 +56,6 @@ class TracDataAPI(ProxyDataAPI): |
68 | 56 | collaborators = [] |
69 | 57 | cursor = self.ticket_cursor(empty_cursor) |
70 | 58 | ticket_dict = self.dictfetchall(cursor) |
71 | - time_zone = pytz.timezone(get_current_timezone_name()) | |
72 | 59 | for line in ticket_dict: |
73 | 60 | ticket.id = line['id'] |
74 | 61 | ticket.summary = line['summary'] |
... | ... | @@ -82,11 +69,11 @@ class TracDataAPI(ProxyDataAPI): |
82 | 69 | ticket.status = line['status'] |
83 | 70 | ticket.tag = ticket.status |
84 | 71 | ticket.keywords = line['keywords'] |
72 | + ticket.owner = line['owner'] | |
73 | + ticket.resolution = line['resolution'] | |
85 | 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 | 77 | ticket.modified_by = ticket.author |
91 | 78 | if line['reporter'] not in collaborators: |
92 | 79 | collaborators.append(line['reporter']) |
... | ... | @@ -97,7 +84,6 @@ class TracDataAPI(ProxyDataAPI): |
97 | 84 | cursor = self.wiki_cursor(empty_cursor) |
98 | 85 | wiki_dict = self.dictfetchall(cursor) |
99 | 86 | collaborators = [] |
100 | - time_zone = pytz.timezone(get_current_timezone_name()) | |
101 | 87 | for line in wiki_dict: |
102 | 88 | wiki.update_user(line['author']) |
103 | 89 | wiki.title = line['name'] |
... | ... | @@ -106,10 +92,9 @@ class TracDataAPI(ProxyDataAPI): |
106 | 92 | if line['author'] not in collaborators: |
107 | 93 | collaborators.append(line['author']) |
108 | 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 | 98 | wiki.save() |
114 | 99 | |
115 | 100 | def dictfetchall(self, cursor): |
... | ... | @@ -138,3 +123,39 @@ class TracDataAPI(ProxyDataAPI): |
138 | 123 | def repository_cursor(self, cursor): |
139 | 124 | cursor.execute('''SELECT * FROM repository;''') |
140 | 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 | 27 | ('modified', models.DateTimeField(blank=True)), |
28 | 28 | ('mimetype', models.TextField(blank=True)), |
29 | 29 | ('size', models.IntegerField(blank=True)), |
30 | + ('ipnr', models.TextField(blank=True)), | |
30 | 31 | ], |
31 | 32 | options={ |
32 | 33 | 'verbose_name': 'Attachment', |
... | ... | @@ -72,6 +73,8 @@ class Migration(migrations.Migration): |
72 | 73 | ('created', models.DateTimeField(null=True, blank=True)), |
73 | 74 | ('modified', models.DateTimeField(null=True, blank=True)), |
74 | 75 | ('modified_by', models.TextField(blank=True)), |
76 | + ('owner', models.TextField(blank=True)), | |
77 | + ('resolution', models.TextField(blank=True)), | |
75 | 78 | ], |
76 | 79 | options={ |
77 | 80 | 'verbose_name': 'Ticket', |
... | ... | @@ -88,6 +91,7 @@ class Migration(migrations.Migration): |
88 | 91 | ('collaborators', models.TextField(blank=True)), |
89 | 92 | ('created', models.DateTimeField(null=True, blank=True)), |
90 | 93 | ('modified', models.DateTimeField(null=True, blank=True)), |
94 | + ('comment', models.TextField(blank=True)), | |
91 | 95 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), |
92 | 96 | ], |
93 | 97 | options={ | ... | ... |
colab/proxy/trac/models.py
... | ... | @@ -22,9 +22,10 @@ class Attachment(models.Model, HitCounterModelMixin): |
22 | 22 | author = models.TextField(blank=True) |
23 | 23 | title = models.TextField(blank=True) |
24 | 24 | description = models.TextField(blank=True) |
25 | - modified = models.DateTimeField(blank=True) | |
25 | + created = models.DateTimeField(blank=True) | |
26 | 26 | mimetype = models.TextField(blank=True) |
27 | 27 | size = models.IntegerField(blank=True) |
28 | + ipnr = models.TextField(blank=True) | |
28 | 29 | |
29 | 30 | class Meta: |
30 | 31 | verbose_name = _('Attachment') |
... | ... | @@ -58,7 +59,6 @@ class Revision(models.Model, HitCounterModelMixin): |
58 | 59 | description = models.TextField(blank=True) |
59 | 60 | repository_name = models.TextField(blank=True) |
60 | 61 | created = models.DateTimeField(blank=True, null=True) |
61 | - modified = models.DateTimeField(blank=True, null=True) | |
62 | 62 | |
63 | 63 | @property |
64 | 64 | def title(self): |
... | ... | @@ -97,6 +97,8 @@ class Ticket(models.Model, HitCounterModelMixin): |
97 | 97 | created = models.DateTimeField(blank=True, null=True) |
98 | 98 | modified = models.DateTimeField(blank=True, null=True) |
99 | 99 | modified_by = models.TextField(blank=True) |
100 | + owner = models.TextField(blank=True) | |
101 | + resolution = models.TextField(blank=True) | |
100 | 102 | |
101 | 103 | @property |
102 | 104 | def title(self): | ... | ... |