Beispiel #1
0
 def add_item(self, item_str):
     """exposed add item method, adds a new todo item to the todo file and reindexes
     
     :param item_str: the string representation of a :class:`TodoItem`
     :type item_str: str
     :returns: the parsed todo item
     :rtype: :class:`TodoItem` 
     """
     # append the item to the todo list
     item = self._append(item_str)
     # add done and created properties
     now = datetime.datetime.now()
     now_str = from_date(now)
     if item.is_report:
         # in case of report item, we need to store the "done" date for later sorting
         item.replace_or_add_prop(conf.DONE, now_str, now)
     else:
         item.replace_or_add_prop(conf.CREATED, now_str, now)
     # if item doesn't have an tid assigned, do it here automatically
     if conf.id_support and not item.tid:
         item_id = self.create_tid(item)
         item.replace_or_add_prop(conf.ID, item_id)
         self.tids[item_id] = item
     # add to dependencies
     if conf.id_support and item.tid and conf.BLOCKEDBY in item.properties:
         self.dependencies[item.tid] = item.properties[conf.BLOCKEDBY]
     # the new item is sorted into the list
     self.reindex()
     # something has changed
     self.dirty = True
     return item
Beispiel #2
0
 def add_item(self, item_str):
     """exposed add item method, adds a new todo item to the todo file and reindexes
     
     :param item_str: the string representation of a :class:`TodoItem`
     :type item_str: str
     :returns: the parsed todo item
     :rtype: :class:`TodoItem` 
     """
     # append the item to the todo list
     item = self._append(item_str)
     # add done and created properties
     now = datetime.datetime.now()
     now_str = from_date(now)
     if item.is_report:
         # in case of report item, we need to store the "done" date for later sorting
         item.replace_or_add_prop(conf.DONE, now_str, now)
     else:
         item.replace_or_add_prop(conf.CREATED, now_str, now)
     # if item doesn't have an tid assigned, do it here automatically
     if conf.id_support and not item.tid:
         item_id = self.create_tid(item)
         item.replace_or_add_prop(conf.ID, item_id)
         self.tids[item_id] = item
     # add to dependencies
     if conf.id_support and item.tid and conf.BLOCKEDBY in item.properties:
         self.dependencies[item.tid] = item.properties[conf.BLOCKEDBY]
     # the new item is sorted into the list
     self.reindex()
     # something has changed
     self.dirty = True
     return item
Beispiel #3
0
 def set_date(self, prop_name, date_or_str):
     if not date_or_str: 
         self.replace_or_add_prop(prop_name, None)
     elif isinstance(date_or_str, basestring):
         self.replace_or_add_prop(prop_name, date_or_str, to_date(date_or_str))
     elif isinstance(date_or_str, (datetime.date, datetime.datetime)):
         self.replace_or_add_prop(prop_name, from_date(date_or_str), date_or_str)
     else:
         logging.error(u"ERROR: setting non-date or non-string")
Beispiel #4
0
 def set_date(self, prop_name, date_or_str):
     if not date_or_str:
         self.replace_or_add_prop(prop_name, None)
     elif isinstance(date_or_str, basestring):
         self.replace_or_add_prop(prop_name, date_or_str,
                                  to_date(date_or_str))
     elif isinstance(date_or_str, (datetime.date, datetime.datetime)):
         self.replace_or_add_prop(prop_name, from_date(date_or_str),
                                  date_or_str)
     else:
         logging.error(u"ERROR: setting non-date or non-string")
Beispiel #5
0
 def set_to_done(self):
     """sets this item to status "done"
     
     This automatically adds a ``done:{datetime}`` property and prepends
     the item with ``x ``.
     """
     # set to done
     self.done = True
     # if necessary, create properties
     now = datetime.datetime.now()
     # add marker "x " at beginning
     if not self.text.startswith(conf.DONE_PREFIX):
         self.text = conf.DONE_PREFIX + self.text
     # replace ``done`` properties with current value (and add datetime object for properties)
     self.replace_or_add_prop(conf.DONE, from_date(now), now)
Beispiel #6
0
 def set_to_done(self):
     """sets this item to status "done"
     
     This automatically adds a ``done:{datetime}`` property and prepends
     the item with ``x ``.
     """
     # set to done
     self.done = True
     # if necessary, create properties
     now = datetime.datetime.now()
     # add marker "x " at beginning
     if not self.text.startswith(conf.DONE_PREFIX):
         self.text = conf.DONE_PREFIX + self.text
     # replace ``done`` properties with current value (and add datetime object for properties)
     self.replace_or_add_prop(conf.DONE, from_date(now), now)
Beispiel #7
0
 def _fix_properties_on_load(self):
     """normalizes property names and transforms date properties to a readable / managable form
     """
     props = self.properties
     # fix properties, if possible
     for prop_name in props:
         if "{prop_key}:".format(prop_key = prop_name) not in self.text:
             # we need to normalize this property name, make everything lowercase
             re_normalize_prop = re.compile("({prop_key}:)".format(prop_key = prop_name), re.IGNORECASE)
             self.text = re_normalize_prop.sub("{prop_key}:".format(prop_key = prop_name), self.text)
         if prop_name in conf.DATE_PROPS:
             # replace all date props with a "beautified" date string
             repl_date = to_date(props[prop_name])
             if repl_date:
                 self.text = self.text.replace(props[prop_name], from_date(repl_date))
                 props[prop_name] = repl_date
Beispiel #8
0
 def _fix_properties_on_load(self):
     """normalizes property names and transforms date properties to a readable / managable form
     """
     props = self.properties
     # fix properties, if possible
     for prop_name in props:
         if "{prop_key}:".format(prop_key=prop_name) not in self.text:
             # we need to normalize this property name, make everything lowercase
             re_normalize_prop = re.compile(
                 "({prop_key}:)".format(prop_key=prop_name), re.IGNORECASE)
             self.text = re_normalize_prop.sub(
                 "{prop_key}:".format(prop_key=prop_name), self.text)
         if prop_name in conf.DATE_PROPS:
             # replace all date props with a "beautified" date string
             repl_date = to_date(props[prop_name])
             if repl_date:
                 self.text = self.text.replace(props[prop_name],
                                               from_date(repl_date))
                 props[prop_name] = repl_date