~saurabhanandiit/gtg/exportFixed

« back to all changes in this revision

Viewing changes to GTG/plugins/rtm_sync/gtgTask.py

Merge of my work on liblarch newbase and all the backends ported to liblarch
(which mainly means porting the datastore).
One failing test, will check it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
# Copyright (c) 2009 - Luca Invernizzi <invernizzi.l@gmail.com>
3
 
#
4
 
# This program is free software: you can redistribute it and/or modify it under
5
 
# the terms of the GNU General Public License as published by the Free Software
6
 
# Foundation, either version 3 of the License, or (at your option) any later
7
 
# version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful, but WITHOUT
10
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
 
# details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License along with
15
 
# this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
import datetime
18
 
 
19
 
from GTG.tools.dates import NoDate, RealDate
20
 
from GTG.plugins.rtm_sync.genericTask import GenericTask
21
 
 
22
 
class GtgTask(GenericTask):
23
 
    #GtgTask passes only datetime objects with the timezone loaded 
24
 
    # to talk about dates and times
25
 
 
26
 
    def __init__(self, gtg_task, plugin_api, gtg_proxy):
27
 
        super(GtgTask, self).__init__(gtg_proxy)
28
 
        self._gtg_task = gtg_task
29
 
        self.plugin_api = plugin_api
30
 
 
31
 
    def _get_title(self):
32
 
        return self._gtg_task.get_title()
33
 
 
34
 
    def _set_title(self, title):
35
 
        self._gtg_task.set_title(title)
36
 
 
37
 
    def _get_id(self):
38
 
        return self._gtg_task.get_uuid()
39
 
 
40
 
    def _get_tags(self):
41
 
        return [t.get_name() for t in self._gtg_task.get_tags()]
42
 
 
43
 
    def _set_tags(self, tags):
44
 
        other_tags = []
45
 
        for tag in tags:
46
 
            tag = '@' + tag
47
 
            other_tags.append(tag)
48
 
        gtg_tags = self._gtg_task.get_tags()
49
 
        gtg_tags_lower = [t.get_name().lower() for t in gtg_tags]
50
 
        gtg_tags_set = set(gtg_tags_lower)
51
 
        other_tags_set = set([t.lower() for t in other_tags])
52
 
        #tags to remove
53
 
        for tag in gtg_tags_set.difference(other_tags_set):
54
 
            self._gtg_task.remove_tag(tag)
55
 
        #tags to add
56
 
        for tag in other_tags_set.difference(gtg_tags_set):
57
 
            gtg_all_tags = [t.get_name() for t in \
58
 
                            self.plugin_api.get_requester().get_all_tags()]
59
 
            matching_tags = filter(lambda t: t.lower() == tag, gtg_all_tags)
60
 
            if len(matching_tags) !=  0:
61
 
                tag = matching_tags[0]
62
 
            self._gtg_task.add_tag(tag)
63
 
 
64
 
    def _get_text(self):
65
 
        return self._gtg_task.get_excerpt(strip_tags = True, \
66
 
                                          strip_subtasks = True)
67
 
    def _set_text(self, text):
68
 
        #fill in subtasks
69
 
        self._gtg_task.set_text(text)
70
 
 
71
 
    def _set_status(self, status):
72
 
        self._gtg_task.set_status(status)
73
 
 
74
 
    def _get_status(self):
75
 
        return self._gtg_task.get_status()
76
 
 
77
 
    def _get_due_date(self):
78
 
        due_date = self._gtg_task.get_due_date()
79
 
        if due_date == NoDate():
80
 
                return None
81
 
        return due_date.to_py_date()
82
 
 
83
 
    def _set_due_date(self, due):
84
 
        if due == None:
85
 
            gtg_due = NoDate()
86
 
        else:
87
 
            gtg_due = RealDate(due)
88
 
        self._gtg_task.set_due_date(gtg_due)
89
 
 
90
 
    def _get_modified(self):
91
 
        modified = self._gtg_task.get_modified()
92
 
        if modified == None or modified == "":
93
 
            return None
94
 
        return self.__time_gtg_to_datetime(modified)
95
 
 
96
 
    def get_gtg_task(self):
97
 
        return self._gtg_task
98
 
 
99
 
    def __time_gtg_to_datetime(self, string):
100
 
        #FIXME: need to handle time with TIMEZONES!
101
 
        string = string.split('.')[0].split('Z')[0]
102
 
        if string.find('T') == -1:
103
 
            return datetime.datetime.strptime(string.split(".")[0], "%Y-%m-%d")
104
 
        return datetime.datetime.strptime(string.split(".")[0], \
105
 
                                          "%Y-%m-%dT%H:%M:%S")