~saurabhanandiit/gtg/exportFixed

« back to all changes in this revision

Viewing changes to GTG/plugins/evolution_sync/evolutionTask.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 time
18
 
import datetime
19
 
 
20
 
from GTG.plugins.evolution_sync.genericTask import GenericTask
21
 
 
22
 
 
23
 
class EvolutionTask(GenericTask):
24
 
 
25
 
    def __init__(self, evo_task, evolution_proxy):
26
 
        super(EvolutionTask, self).__init__(evolution_proxy)
27
 
        self._evo_task = evo_task
28
 
 
29
 
    def _get_title(self):
30
 
        return self._evo_task.get_summary()
31
 
 
32
 
    def _set_title(self, title):
33
 
        self._evo_task.set_summary(title)
34
 
        self.get_proxy().update_task(self)
35
 
 
36
 
    def _get_id(self):
37
 
        return self._evo_task.get_uid()
38
 
 
39
 
    def _get_tags(self):
40
 
        #We could use Evolution's "Categories" as tags
41
 
        raise NotImplementedError()
42
 
 
43
 
    def _set_tags(self, tags):
44
 
        raise NotImplementedError()
45
 
        self.get_proxy().update_task(self)
46
 
 
47
 
    def _get_text(self):
48
 
        desc = self._evo_task.get_description()
49
 
        if desc == None:
50
 
            return ""
51
 
        return desc
52
 
 
53
 
    def _set_text(self, text):
54
 
        self._evo_task.set_description(text)
55
 
        self.get_proxy().update_task(self)
56
 
 
57
 
    def _set_status(self, status):
58
 
        #Since Evolution's statuses are fare more than GTG's,
59
 
        # we need to check that the current status is not one of the various
60
 
        # statuses translated in the same gtg status, passed by argument.
61
 
        # This way, we avoid to force a status change when it's not needed 
62
 
        # (and not wanted)
63
 
        current_status_in_gtg_terms = self.get_proxy()._evo_to_gtg_status[\
64
 
                                                   self._evo_task.get_status()]
65
 
        if current_status_in_gtg_terms != status:
66
 
            new_evo_status = self.get_proxy()._gtg_to_evo_status[status]
67
 
            self._evo_task.set_status(new_evo_status)
68
 
            self.get_proxy().update_task(self)
69
 
 
70
 
    def _get_status(self):
71
 
        status = self._evo_task.get_status()
72
 
        return self.get_proxy()._evo_to_gtg_status[status]
73
 
 
74
 
    def _get_due_date(self):
75
 
        due = self._evo_task.get_due()
76
 
        if isinstance(due, (int, float)):
77
 
            return self.__time_evo_to_date(due)
78
 
 
79
 
    def _set_due_date(self, due):
80
 
        if due == None:
81
 
            #TODO: I haven't find a way to reset the due date
82
 
            # We could copy the task, but that would lose all the attributes
83
 
            # currently not supported by the library used (and they're a lot)
84
 
            pass
85
 
        else:
86
 
            self._evo_task.set_due(self.__time_date_to_evo(due))
87
 
        self.get_proxy().update_task(self)
88
 
 
89
 
    def _get_modified(self):
90
 
        return self.__time_evo_to_datetime(self._evo_task.get_modified())
91
 
 
92
 
    def __time_evo_to_date(self, timestamp):
93
 
        return datetime.datetime.fromtimestamp(timestamp + time.timezone).date()
94
 
 
95
 
    def __time_evo_to_datetime(self, timestamp):
96
 
        return datetime.datetime.fromtimestamp(timestamp)
97
 
 
98
 
    def __time_datetime_to_evo(self, timeobject):
99
 
        return int(time.mktime(timeobject.timetuple()))
100
 
 
101
 
    def __time_date_to_evo(self, timeobject):
102
 
        #NOTE: need to substract the timezone to avoid the "one day before bug
103
 
        # (at the airport => no internet now, need to fill bug number in)
104
 
        #Explanation: gtg date format is converted to datetime in date/00:00 in 
105
 
        # local time, and time.mktime considers that when converting to UNIX
106
 
        # time. Evolution, however, doesn't convert back to local time.
107
 
        return self.__time_datetime_to_evo(timeobject) - time.timezone
108
 
 
109
 
    def get_evolution_task(self):
110
 
        return self._evo_task