Commit 0c48b4b529dc60eab3bfd525903f1b02725ff743

Authored by Thiago Ribeiro
Committed by Sergio Oliveira
1 parent e2cae250

Refactor data_api

Signed-off-by: Carolina Ramalho <carol15022@hotmail.com>
colab/proxy/trac/data_api.py
@@ -16,9 +16,9 @@ class TracDataAPI(ProxyDataAPI): @@ -16,9 +16,9 @@ class TracDataAPI(ProxyDataAPI):
16 self.fetch_data_ticket(cursor) 16 self.fetch_data_ticket(cursor)
17 self.fetch_data_revision(cursor) 17 self.fetch_data_revision(cursor)
18 18
19 - def fetch_data_attachment(self, cursor): 19 + def fetch_data_attachment(self, empty_cursor):
20 attachment = Attachment() 20 attachment = Attachment()
21 - cursor.execute(''' SELECT * from attachment; ''') 21 + cursor = self.attachment_cursor(empty_cursor)
22 attachment_dict = self.dictfetchall(cursor) 22 attachment_dict = self.dictfetchall(cursor)
23 for line in attachment_dict: 23 for line in attachment_dict:
24 attachment.description = line['description'] 24 attachment.description = line['description']
@@ -37,11 +37,11 @@ class TracDataAPI(ProxyDataAPI): @@ -37,11 +37,11 @@ class TracDataAPI(ProxyDataAPI):
37 attachment.mimetype = attachment.filename.lower() 37 attachment.mimetype = attachment.filename.lower()
38 attachment.save() 38 attachment.save()
39 39
40 - def fetch_data_revision(self, cursor): 40 + def fetch_data_revision(self, empty_cursor):
41 revision = Revision() 41 revision = Revision()
42 - cursor.execute('''SELECT * FROM revision;''') 42 + cursor = self.revision_cursor(empty_cursor)
43 revision_dict = self.dictfetchall(cursor) 43 revision_dict = self.dictfetchall(cursor)
44 - cursor.execute('''SELECT * FROM repository;''') 44 + cursor = self.repository_cursor(empty_cursor)
45 repository_dict = self.dictfetchall(cursor) 45 repository_dict = self.dictfetchall(cursor)
46 for line in revision_dict: 46 for line in revision_dict:
47 revision.author = line['author'] 47 revision.author = line['author']
@@ -53,10 +53,10 @@ class TracDataAPI(ProxyDataAPI): @@ -53,10 +53,10 @@ class TracDataAPI(ProxyDataAPI):
53 time.localtime(local_time)) 53 time.localtime(local_time))
54 revision.repository_name = repository_dict[line['value']] 54 revision.repository_name = repository_dict[line['value']]
55 55
56 - def fetch_data_ticket(self, cursor): 56 + def fetch_data_ticket(self, empty_cursor):
57 ticket = Ticket() 57 ticket = Ticket()
58 collaborators = [] 58 collaborators = []
59 - cursor.execute('''SELECT * FROM ticket;''') 59 + cursor = self.ticket_cursor(empty_cursor)
60 ticket_dict = self.dictfetchall(cursor) 60 ticket_dict = self.dictfetchall(cursor)
61 for line in ticket_dict: 61 for line in ticket_dict:
62 ticket.id = line['id'] 62 ticket.id = line['id']
@@ -81,9 +81,9 @@ class TracDataAPI(ProxyDataAPI): @@ -81,9 +81,9 @@ class TracDataAPI(ProxyDataAPI):
81 collaborators.append(line['report']) 81 collaborators.append(line['report'])
82 ticket.collaborators = collaborators 82 ticket.collaborators = collaborators
83 83
84 - def fetch_data_wiki(self, cursor): 84 + def fetch_data_wiki(self, empty_cursor):
85 wiki = Wiki() 85 wiki = Wiki()
86 - cursor.execute('''SELECT * FROM wiki;''') 86 + cursor = self.wiki_cursor(empty_cursor)
87 wiki_dict = self.dictfetchall(cursor) 87 wiki_dict = self.dictfetchall(cursor)
88 collaborators = [] 88 collaborators = []
89 89
@@ -107,3 +107,23 @@ class TracDataAPI(ProxyDataAPI): @@ -107,3 +107,23 @@ class TracDataAPI(ProxyDataAPI):
107 dict(zip([col[0] for col in desc], row)) 107 dict(zip([col[0] for col in desc], row))
108 for row in cursor.fetchall() 108 for row in cursor.fetchall()
109 ] 109 ]
  110 +
  111 + def wiki_cursor(self, cursor):
  112 + cursor.execute('''SELECT * FROM wiki;''')
  113 + return cursor
  114 +
  115 + def attachment_cursor(self, cursor):
  116 + cursor.execute('''SELECT * FROM attachment;''')
  117 + return cursor
  118 +
  119 + def ticket_cursor(self, cursor):
  120 + cursor.execute('''SELECT * FROM ticket;''')
  121 + return cursor
  122 +
  123 + def revision_cursor(self, cursor):
  124 + cursor.execute('''SELECT * FROM revision;''')
  125 + return cursor
  126 +
  127 + def repository_cursor(self, cursor):
  128 + cursor.execute('''SELECT * FROM repository;''')
  129 + return cursor
colab/proxy/trac/models.py
@@ -105,8 +105,8 @@ class Ticket(models.Model, HitCounterModelMixin): @@ -105,8 +105,8 @@ class Ticket(models.Model, HitCounterModelMixin):
105 @property 105 @property
106 def description(self): 106 def description(self):
107 return u'{}\n{}\n{}\n{}\n{}\n{}\n{}'.format( 107 return u'{}\n{}\n{}\n{}\n{}\n{}\n{}'.format(
108 - self.description_ticket, self.milestone, self.component, self.severity,  
109 - self.reporter, self.keywords, self.collaborators 108 + self.description_ticket, self.milestone, self.component,
  109 + self.severity, self.reporter, self.keywords, self.collaborators
110 ) 110 )
111 111
112 class Meta: 112 class Meta:
@@ -161,4 +161,3 @@ class Wiki(Collaboration, HitCounterModelMixin): @@ -161,4 +161,3 @@ class Wiki(Collaboration, HitCounterModelMixin):
161 return User.objects.get(username=self.author) 161 return User.objects.get(username=self.author)
162 except User.DoesNotExist: 162 except User.DoesNotExist:
163 return None 163 return None
164 -