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 3 from django.db import connections
4 4 from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki
5 5 from django.utils import timezone
  6 +from re import match
6 7  
7 8  
8 9 class TracDataAPI(ProxyDataAPI):
9 10  
10 11 def fetch_data(self):
11   - attachment = Attachment()
12   - revision = Revision()
13   - ticket = Ticket()
14 12 connection = connections['trac']
15 13 cursor = connection.cursor()
16 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 43 def fetch_data_wiki(self, cursor):
19 44 wiki = Wiki()
20 45 cursor.execute('''SELECT * FROM wiki;''')
... ... @@ -32,7 +57,7 @@ class TracDataAPI(ProxyDataAPI):
32 57 wiki.created = time.strftime('%Y-%m-%d %H:%M:%S',
33 58 time.localtime(local_time))
34 59 wiki.modified = str(timezone.now())
35   - wiki.modified_by = wiki.author
  60 + wiki.modified_by = wiki.author
36 61 wiki.save()
37 62  
38 63 def dictfetchall(self, cursor):
... ... @@ -40,4 +65,4 @@ class TracDataAPI(ProxyDataAPI):
40 65 return [
41 66 dict(zip([col[0] for col in desc], row))
42 67 for row in cursor.fetchall()
43   - ]
  68 + ]
... ...