1
# -*- coding: utf-8 -*-
2
# Copyright (c) 2009 - Luca Invernizzi <invernizzi.l@gmail.com>
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
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
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/>.
19
from GTG.tools.dates import NoDate, RealDate
20
from GTG.plugins.rtm_sync.genericTask import GenericTask
22
class GtgTask(GenericTask):
23
#GtgTask passes only datetime objects with the timezone loaded
24
# to talk about dates and times
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
32
return self._gtg_task.get_title()
34
def _set_title(self, title):
35
self._gtg_task.set_title(title)
38
return self._gtg_task.get_uuid()
41
return [t.get_name() for t in self._gtg_task.get_tags()]
43
def _set_tags(self, tags):
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])
53
for tag in gtg_tags_set.difference(other_tags_set):
54
self._gtg_task.remove_tag(tag)
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)
65
return self._gtg_task.get_excerpt(strip_tags = True, \
66
strip_subtasks = True)
67
def _set_text(self, text):
69
self._gtg_task.set_text(text)
71
def _set_status(self, status):
72
self._gtg_task.set_status(status)
74
def _get_status(self):
75
return self._gtg_task.get_status()
77
def _get_due_date(self):
78
due_date = self._gtg_task.get_due_date()
79
if due_date == NoDate():
81
return due_date.to_py_date()
83
def _set_due_date(self, due):
87
gtg_due = RealDate(due)
88
self._gtg_task.set_due_date(gtg_due)
90
def _get_modified(self):
91
modified = self._gtg_task.get_modified()
92
if modified == None or modified == "":
94
return self.__time_gtg_to_datetime(modified)
96
def get_gtg_task(self):
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], \