51
50
self.set_uuid(uuid.uuid4())
52
51
self.remote_ids = {}
55
# "<content>Press Escape or close this task to save it</content>"
56
53
self.title = _("My new task")
57
54
#available status are: Active - Done - Dismiss - Note
58
55
self.status = self.STA_ACTIVE
147
144
due_date = Date.no_date()
148
145
defer_date = Date.no_date()
151
147
# Get tags in the title
152
#NOTE: the ?: tells regexp that the first one is
153
# a non-capturing group, so it must not be returned
154
# to findall. http://www.amk.ca/python/howto/regex/regex.html
156
148
for match in re.findall(r'(?:^|[\s])(@\w+)', text, re.UNICODE):
157
149
tags.append(match)
159
#text =text.replace(match,match[1:],1)
161
regexp = r'([\s]*)([\w-]+):([^\s]+)'
151
regexp = r'([\s]*)([\w-]+):\s*([^\s]+)'
162
152
for spaces, attribute, args in re.findall(regexp, text, re.UNICODE):
163
153
valid_attribute = True
164
if attribute.lower() in ["tags", "tag"] or \
165
attribute.lower() in [_("tags"), _("tag")]:
154
if attribute.lower() in ["tags", _("tags"), "tag", _("tag")]:
166
155
for tag in args.split(","):
167
156
if not tag.startswith("@"):
170
elif attribute.lower() == "defer" or \
171
attribute.lower() == _("defer"):
159
elif attribute.lower() in ["defer", _("defer"), "start", _("start")]:
173
161
defer_date = Date.parse(args)
174
162
except ValueError:
183
171
# attribute is unknown
184
172
valid_attribute = False
185
174
if valid_attribute:
186
# if the command is valid we have to remove it
187
# from the task title
175
# remove valid attribute from the task title
189
177
text.replace("%s%s:%s" % (spaces, attribute, args), "")
190
# # Create the new task
191
# task = self.req.new_task(tags=[t.get_name() for t in tags], newtask=True)
195
183
self.set_title(text.strip())
196
184
self.set_to_keep()
197
186
self.set_due_date(due_date)
198
187
self.set_start_date(defer_date)
256
245
self.due_date = Date(fulldate)
259
#Due date return the most urgent date of all parents
260
248
def get_due_date(self):
249
""" Due date return the most urgent date of all parents """
261
250
zedate = self.due_date
263
252
for par in self.get_parents():
264
#Here we compare with the parent's due date
253
# compare with the parent's due date
265
254
pardate = self.req.get_task(par).get_due_date()
266
255
if pardate and zedate > pardate:
488
477
priority = "medium"
491
# the following is not currently needed
492
# def modified(self):
493
# TreeNode.modified(self)
494
# for t in self.get_tags():
495
# gobject.idle_add(t.modified)
497
480
def _modified_update(self):
499
482
Updates the modified timestamp
532
515
Adds a tag. Does not add '@tag' to the contents. See add_tag
534
# print "tag %s added to task %s" %(tagname,self.get_title())
535
517
t = tagname.encode("UTF-8")
536
518
#Do not add the same tag twice
537
519
if not t in self.tags:
538
520
self.tags.append(t)
539
#we notify the backends
540
#self.req.tag_was_added_to_task(self, tagname)
541
521
if self.is_loaded():
542
522
for child in self.get_subtasks():
543
523
if child.can_be_deleted:
552
532
def add_tag(self, tagname):
553
533
"Add a tag to the task and insert '@tag' into the task's content"
554
# print "add tag %s to task %s" %(tagname,self.get_title())
555
534
if self.tag_added(tagname):
609
588
.replace('<tag>%s</tag>\n\n' % (tagname), newtag) #trail \n
610
589
.replace('<tag>%s</tag>, ' % (tagname), newtag) #trail comma
590
.replace('<tag>%s</tag>,' % (tagname), newtag)
611
591
.replace('<tag>%s</tag>' % (tagname), newtag)
612
592
#in case XML is missing (bug #504899)
613
593
.replace('%s\n\n' % (tagname), newtag)
614
594
.replace('%s, ' % (tagname), newtag)
595
.replace('%s,' % (tagname), newtag)
615
596
#don't forget a space a the end
616
597
.replace('%s ' % (tagname), newtag)
647
628
#Well, if we don't filter on tags or notag, it's true, of course
649
# print "task %s has tag %s : %s" %(self.get_id(),tag_list,toreturn)
652
#return the color of one tag that have a color defined
653
#Yes, the choosen color is a bit random in case of multiple colored tags
656
for t in self.get_tags():
657
c = t.get_attribute("color")
662
632
def __str__(self):
664
634
s = s + "Task Object\n"