Commit 2dddb4ceb1a2f0ce499362bbbc80a1430e058caf

Authored by Thiago Ribeiro
Committed by Sergio Oliveira
1 parent 59419836

Add trac_attachment in colab.

Signed-off-by: Carolina Ramalho <carol15022@hotmail.com>
Showing 1 changed file with 31 additions and 6 deletions   Show diff stats
colab/proxy/trac/data_api.py
@@ -3,18 +3,43 @@ import time @@ -3,18 +3,43 @@ import time
3 from django.db import connections 3 from django.db import connections
4 from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki 4 from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki
5 from django.utils import timezone 5 from django.utils import timezone
  6 +from re import match
6 7
7 8
8 class TracDataAPI(ProxyDataAPI): 9 class TracDataAPI(ProxyDataAPI):
9 10
10 def fetch_data(self): 11 def fetch_data(self):
11 - attachment = Attachment()  
12 - revision = Revision()  
13 - ticket = Ticket()  
14 connection = connections['trac'] 12 connection = connections['trac']
15 cursor = connection.cursor() 13 cursor = connection.cursor()
16 self.fetch_data_wiki(cursor) 14 self.fetch_data_wiki(cursor)
17 - 15 + self.fetch_data_attachment(cursor)
  16 +
  17 + def fetch_data_attachment(self, cursor):
  18 + attachment = Attachment()
  19 + cursor.execute(''' SELECT * from attachment; ''')
  20 + attachment_dict = self.dictfetchall(cursor)
  21 + for line in attachment_dict:
  22 + attachment.description = line['description']
  23 + attachment.id = line['attach_id']
  24 + attachment.filename = line['filemame']
  25 + attachment.size = line['size']
  26 + attachment.author = line['author']
  27 + attachment.used_by = line['type']
  28 + attachment.url = attachment.user_by + "/" + attachment.id \
  29 + + "/" + attachment.filename
  30 + local_time = line['time']/1000000
  31 + attachment.created = time.strftime('%Y-%m-%d %H:%M:%S',
  32 + time.localtime(local_time))
  33 + if match("\.(\w+)$", attachment.filename):
  34 + attachment.mimetype = attachment.filename.lower()
  35 + attachment.save()
  36 +
  37 + #def fetch_data_ticket(self, cursor)
  38 + # ticket = Ticket()
  39 +
  40 + #def fetch_data_revision(self, cursor)
  41 + # revision = Revision()
  42 +
18 def fetch_data_wiki(self, cursor): 43 def fetch_data_wiki(self, cursor):
19 wiki = Wiki() 44 wiki = Wiki()
20 cursor.execute('''SELECT * FROM wiki;''') 45 cursor.execute('''SELECT * FROM wiki;''')
@@ -32,7 +57,7 @@ class TracDataAPI(ProxyDataAPI): @@ -32,7 +57,7 @@ class TracDataAPI(ProxyDataAPI):
32 wiki.created = time.strftime('%Y-%m-%d %H:%M:%S', 57 wiki.created = time.strftime('%Y-%m-%d %H:%M:%S',
33 time.localtime(local_time)) 58 time.localtime(local_time))
34 wiki.modified = str(timezone.now()) 59 wiki.modified = str(timezone.now())
35 - wiki.modified_by = wiki.author 60 + wiki.modified_by = wiki.author
36 wiki.save() 61 wiki.save()
37 62
38 def dictfetchall(self, cursor): 63 def dictfetchall(self, cursor):
@@ -40,4 +65,4 @@ class TracDataAPI(ProxyDataAPI): @@ -40,4 +65,4 @@ class TracDataAPI(ProxyDataAPI):
40 return [ 65 return [
41 dict(zip([col[0] for col in desc], row)) 66 dict(zip([col[0] for col in desc], row))
42 for row in cursor.fetchall() 67 for row in cursor.fetchall()
43 - ] 68 + ]