~gtg-user/gtg/about_window_crash_fix

« back to all changes in this revision

Viewing changes to GTG/core/tagstore.py

  • Committer: Lionel Dricot
  • Date: 2009-10-07 12:17:46 UTC
  • mfrom: (342.1.9 gtg.local)
  • Revision ID: ploum@ploum.net-20091007121746-yrz20wwj8y72lc8h
This revision introduce a symetric relation between tasks and tags.

This allows a lot of optimizations (some are already done). If you find a
function where every task is parsed to check for a given tag, change it to
directly ask the tag for associated tasks

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
# and their attribute.
35
35
class TagStore :
36
36
    
37
 
    def __init__(self):
 
37
    def __init__(self,requester):
 
38
        self.req = requester
38
39
        self.tree = Tree()
39
40
        self.root = self.tree.get_root()
40
41
        self.filename = os.path.join(CoreConfig.DATA_DIR,XMLFILE)
74
75
        #we create a new tag from a name
75
76
        tname = tagname.encode("UTF-8")
76
77
        if tname not in self.root.get_children():
77
 
            tag = Tag(tname, save_cllbk=self.save)
 
78
            tag = Tag(tname, save_cllbk=self.save,req=self.req)
78
79
            self.root.add_child(tname, tag)
79
80
            tag.set_parent(self.root)
80
81
            return tag
170
171
    for tags is C{name}, which always matches L{Tag.get_name()}.
171
172
    """
172
173
 
173
 
    def __init__(self, name, save_cllbk=None):
 
174
    def __init__(self, name, save_cllbk=None,req=None):
174
175
        """Construct a tag.
175
176
 
176
177
        @param name: The name of the tag. Should be a string, generally a
180
181
        """
181
182
        TreeNode.__init__(self, name)
182
183
        self._name = str(name)
 
184
        self.req = req
183
185
        self._attributes = {'name': self._name}
184
186
        self._save = save_cllbk
 
187
        #list of tasks associated with this tag
 
188
        self.tasks = []
185
189
 
186
190
    def get_name(self):
187
191
        """Return the name of the tag."""
226
230
        if butname:
227
231
            attributes.remove('name')
228
232
        return attributes
 
233
        
 
234
    ### TASK relation ####      
 
235
    def add_task(self, tid):
 
236
        if tid not in self.tasks:
 
237
            self.tasks.append(tid)      
 
238
    def remove_task(self,tid):
 
239
        if tid in self.tasks:
 
240
            self.tasks.remove(tid)          
 
241
    def get_tasks(self):
 
242
        #return a copy of the list
 
243
        toreturn = self.tasks[:]
 
244
        return toreturn 
 
245
    def get_tasks_nbr(self,workview=False):
 
246
        if workview:
 
247
            if self.get_attribute("nonworkview") == "True":
 
248
                toreturn = 0
 
249
            else:
 
250
                temp_list = []
 
251
                for t in self.tasks:
 
252
                    ta = self.req.get_task(t)
 
253
                    if ta.get_status() == "Active" and ta.is_workable():
 
254
                        temp_list.append(t)
 
255
                toreturn = len(temp_list)
 
256
        else:
 
257
            toreturn = len(self.tasks)
 
258
        return toreturn
 
259
    def is_used(self):
 
260
        return len(self.tasks) > 0
 
261
    def is_actively_used(self):
 
262
        toreturn = False
 
263
        for task in self.tasks :
 
264
            if self.req.get_task(task).get_status() == "Active":
 
265
                toreturn = True
 
266
        return toreturn
229
267
 
230
268
    def __str__(self):
231
269
        return "Tag: %s" % self.get_name()