def set_complex_title(self,text,tags=[]): if tags: assert(isinstance(tags[0], str)) due_date = no_date defer_date = no_date if text: # Get tags in the title #NOTE: the ?: tells regexp that the first one is # a non-capturing group, so it must not be returned # to findall. http://www.amk.ca/python/howto/regex/regex.html # ~~~~Invernizzi for match in re.findall(r'(?:^|[\s])(@\w+)', text): tags.append(match) # Remove the @ #text =text.replace(match,match[1:],1) # Get attributes regexp = r'([\s]*)([\w-]+):([^\s]+)' for spaces, attribute, args in re.findall(regexp, text): valid_attribute = True if attribute.lower() in ["tags", "tag"] or \ attribute.lower() in [_("tags"), _("tag")]: for tag in args.split(","): if not tag.startswith("@") : tag = "@"+tag tags.append(tag) elif attribute.lower() == "defer" or \ attribute.lower() == _("defer"): defer_date = get_canonical_date(args) if not defer_date: valid_attribute = False elif attribute.lower() == "due" or \ attribute.lower() == _("due"): due_date = get_canonical_date(args) if not due_date: valid_attribute = False else: # attribute is unknown valid_attribute = False if valid_attribute: # if the command is valid we have to remove it # from the task title text = \ text.replace("%s%s:%s" % (spaces, attribute, args), "") # # Create the new task # task = self.req.new_task(tags=[t.get_name() for t in tags], newtask=True) for t in tags: self.add_tag(t) if text != "": self.set_title(text.strip()) self.set_to_keep() self.set_due_date(due_date) self.set_start_date(defer_date)
def test_get_canonical_date(self): ''' Tests for "get_canonical_date" ''' known_values = (("1985-03-29", "1985-03-29"), ("now", _("now")), ("soon", _("soon")), ("later", _("later")), ("", "")) for value, result in known_values: date = get_canonical_date(value) self.assertEqual(date.__str__(), result)