Commit 59419836854c6d82169e5483793e3657ef55d857
Committed by
Sergio Oliveira
1 parent
bba37984
Function for add trac_wiki in colab.
Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com>
Showing
1 changed file
with
37 additions
and
1 deletions
Show diff stats
colab/proxy/trac/data_api.py
| 1 | 1 | from colab.proxy.utils.proxy_data_api import ProxyDataAPI |
| 2 | +import time | |
| 3 | +from django.db import connections | |
| 4 | +from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki | |
| 5 | +from django.utils import timezone | |
| 2 | 6 | |
| 3 | 7 | |
| 4 | 8 | class TracDataAPI(ProxyDataAPI): |
| 5 | 9 | |
| 6 | 10 | def fetch_data(self): |
| 7 | - pass | |
| 11 | + attachment = Attachment() | |
| 12 | + revision = Revision() | |
| 13 | + ticket = Ticket() | |
| 14 | + connection = connections['trac'] | |
| 15 | + cursor = connection.cursor() | |
| 16 | + self.fetch_data_wiki(cursor) | |
| 17 | + | |
| 18 | + def fetch_data_wiki(self, cursor): | |
| 19 | + wiki = Wiki() | |
| 20 | + cursor.execute('''SELECT * FROM wiki;''') | |
| 21 | + wiki_dict = self.dictfetchall(cursor) | |
| 22 | + collaborators = [] | |
| 23 | + | |
| 24 | + for line in wiki_dict: | |
| 25 | + wiki.name = line['name'] | |
| 26 | + wiki.text = line['text'] | |
| 27 | + wiki.author = line['author'] | |
| 28 | + if line['author'] not in collaborators: | |
| 29 | + collaborators.append(line['author']) | |
| 30 | + wiki.collaborators = collaborators | |
| 31 | + local_time = line['time']/1000000 | |
| 32 | + wiki.created = time.strftime('%Y-%m-%d %H:%M:%S', | |
| 33 | + time.localtime(local_time)) | |
| 34 | + wiki.modified = str(timezone.now()) | |
| 35 | + wiki.modified_by = wiki.author | |
| 36 | + wiki.save() | |
| 37 | + | |
| 38 | + def dictfetchall(self, cursor): | |
| 39 | + desc = cursor.description | |
| 40 | + return [ | |
| 41 | + dict(zip([col[0] for col in desc], row)) | |
| 42 | + for row in cursor.fetchall() | |
| 43 | + ] | ... | ... |