def node_label(p_todo): """ Prints an HTML table for a node label with some todo details. """ def escape_dot_label(p_string): """ HTML like labels in Dot may not have raw ampersands, quotes or angle brackets. These should be properly replaced with the escaped character notation. """ return p_string.replace('&', '&').replace('"', '"').replace( '<', '<').replace('>', '>') node_result = '<<TABLE CELLBORDER="0" CELLSPACING="1" VALIGN="top">' def print_row(p_value1, p_value2): return '<TR><TD ALIGN="RIGHT">{}</TD><TD ALIGN="LEFT">{}</TD></TR>'.format(p_value1, p_value2) node_result += '<TR><TD><B>{}</B></TD><TD BALIGN="LEFT"><B>{}{}{}</B></TD></TR>'.format( self.todolist.number(p_todo), "<S>" if todo.is_completed() else "", "<BR />".join(map(escape_dot_label, wrap(p_todo.text(), 35))), "</S>" if todo.is_completed() else "", ) priority = p_todo.priority() start_date = p_todo.start_date() due_date = p_todo.due_date() if priority or start_date or due_date: node_result += '<HR/>' if priority: node_result += print_row('Prio:', p_todo.priority()) if start_date: node_result += print_row('Starts:', "{} ({})".format( start_date.isoformat(), humanize_date(start_date) )) if due_date: node_result += print_row('Due:', "{} ({})".format( due_date.isoformat(), humanize_date(due_date) )) node_result += '</TABLE>>' return node_result
def node_label(p_todo): """ Prints an HTML table for a node label with some todo details. """ def escape_dot_label(p_string): """ HTML like labels in Dot may not have raw ampersands, quotes or angle brackets. These should be properly replaced with the escaped character notation. """ return p_string.replace('&', '&').replace( '"', '"').replace('<', '<').replace('>', '>') node_result = '<<TABLE CELLBORDER="0" CELLSPACING="1" VALIGN="top">' def print_row(p_value1, p_value2): return '<TR><TD ALIGN="RIGHT">{}</TD><TD ALIGN="LEFT">{}</TD></TR>'.format( p_value1, p_value2) node_result += '<TR><TD><B>{}</B></TD><TD BALIGN="LEFT"><B>{}{}{}</B></TD></TR>'.format( self.todolist.number(p_todo), "<S>" if todo.is_completed() else "", "<BR />".join(map(escape_dot_label, wrap(p_todo.text(), 35))), "</S>" if todo.is_completed() else "", ) priority = p_todo.priority() start_date = p_todo.start_date() due_date = p_todo.due_date() if priority or start_date or due_date: node_result += '<HR/>' if priority: node_result += print_row('Prio:', p_todo.priority()) if start_date: node_result += print_row( 'Starts:', "{} ({})".format(start_date.isoformat(), humanize_date(start_date))) if due_date: node_result += print_row( 'Due:', "{} ({})".format(due_date.isoformat(), humanize_date(due_date))) node_result += '</TABLE>>' return node_result
def group_value(p_todo): """ Returns a value to assign the given todo to a group. Date tags are grouped according to the relative date (1 day, 1 month, ...) """ result = 'No value' if p_todo.has_tag(p_field): if p_field == config().tag_due(): result = humanize_date(p_todo.due_date()) elif p_field == config().tag_start(): result = humanize_date(p_todo.start_date()) else: result = p_todo.tag_value(p_field) return result
def humanize_dates(p_due=None, p_start=None, p_creation=None): """ Returns string with humanized versions of p_due, p_start and p_creation. Examples: - all dates: "16 days ago, due in a month, started 2 days ago" - p_due and p_start: "due in a month, started 2 days ago" - p_creation and p_due: "16 days ago, due in a month" """ dates_list = [] if p_creation: dates_list.append(humanize_date(p_creation)) if p_due: dates_list.append('due ' + humanize_date(p_due)) if p_start: now = arrow.now().date() dates_list.append('{} {}'.format( 'started' if p_start <= now else 'starts', humanize_date(p_start) )) return ', '.join(dates_list)
def group_value(p_todo): """ Returns a value to assign the given todo to a group. Date tags are grouped according to the relative date (1 day, 1 month, ...) """ result = 'No value' if p_todo.has_tag(p_field): if p_field == config().tag_due(): result = humanize_date(p_todo.due_date()) elif p_field == config().tag_start(): result = humanize_date(p_todo.start_date()) else: result = p_todo.tag_value(p_field) try: result = humanize_date(date_string_to_date(result)) except ValueError: pass return result
def __init__(self, p_todolist, p_format=None): self.format_string = re.sub(r'\\t', '\t', p_format or config().list_format()) self.todolist = p_todolist self.one_line = False self.placeholders = { # absolute creation date 'c': lambda t: t.creation_date().isoformat() if t.creation_date() else '', # relative creation date 'C': lambda t: humanize_date(t.creation_date()) if t.creation_date() else '', # absolute due date 'd': lambda t: t.due_date().isoformat() if t.due_date() else '', # relative due date 'D': lambda t: humanize_date(t.due_date()) if t.due_date() else '', # relative dates: due, start 'h': lambda t: humanize_dates(t.due_date(), t.start_date()), # relative dates in form: creation, due, start 'H': lambda t: humanize_dates(t.due_date(), t.start_date(), t.creation_date()), # todo ID 'i': lambda t: str(self.todolist.number(t)), # todo ID, padded with spaces 'I': lambda t: _filler(str(self.todolist.number(t)), self.todolist.max_id_length()), # list of tags (spaces) without hidden ones and due: and t: 'k': lambda t: ' '.join([u'{}:{}'.format(tag, value) for tag, value in sorted(t.tags()) if tag not in config().hidden_tags() + [config().tag_start(), config().tag_due()]]), # list of all tags (spaces) 'K': lambda t: ' '.join([u'{}:{}'.format(tag, value) for tag, value in sorted(t.tags())]), # line number 'n': lambda t: str(self.todolist.linenumber(t)), # line number, padded with spaces 'N': lambda t: _filler(str(self.todolist.linenumber(t)), self.todolist.max_id_length()), # priority 'p': lambda t: t.priority() if t.priority() else '', # priority (or placeholder space) 'P': lambda t: t.priority() if t.priority() else ' ', # raw text 'r': lambda t: t.source(), # text 's': lambda t: t.text(), # text (truncated if necessary) 'S': lambda t: t.text(), # absolute start date 't': lambda t: t.start_date().isoformat() if t.start_date() else '', # relative start date 'T': lambda t: humanize_date(t.start_date()) if t.start_date() else '', # unique text ID 'u': self.todolist.uid if self.todolist else lambda _ : '', # unique text ID, padded with spaces 'U': lambda t: _filler(self.todolist.uid(t), self.todolist.max_id_length()), # absolute completion date 'x': lambda t: 'x ' + t.completion_date().isoformat() if t.is_completed() else '', # relative completion date 'X': lambda t: 'x ' + humanize_date(t.completion_date()) if t.is_completed() else '', 'z': lambda t: color_block(t) if config().colors() else ' ', } self.format_list = self._preprocess_format()
from collections import OrderedDict, namedtuple from datetime import date from itertools import groupby from topydo.lib.Config import config from topydo.lib.Importance import average_importance, importance from topydo.lib.Utils import date_string_to_date, humanize_date Field = namedtuple('Field', ['sort', 'group', 'label']) FIELDS = { 'completed': Field( # when a task has no completion date, push it to the end by assigning it # the maximum possible date. sort=(lambda t: t.completion_date() if t.completion_date() else date.max), group=(lambda t: humanize_date(t.completion_date()) if t.completion_date() else 'None'), label='Completed', ), 'context': Field( sort=lambda t: sorted(c.lower() for c in t.contexts()) or ['zz'], group=lambda t: sorted(t.contexts()) or ['None'], label='Context' ), 'created': Field( # when a task has no creation date, push it to the end by assigning it # the maximum possible date. sort=(lambda t: t.creation_date() if t.creation_date() else date.max), group=(lambda t: humanize_date(t.creation_date()) if t.creation_date() else 'None'), label='Created', ), 'importance': Field(
from datetime import date from topydo.lib.Config import config from topydo.lib.Importance import average_importance, importance from topydo.lib.Utils import date_string_to_date, humanize_date Field = namedtuple('Field', ['sort', 'group', 'label']) FIELDS = { 'completed': Field( # when a task has no completion date, push it to the end by assigning it # the maximum possible date. sort=(lambda t: t.completion_date() if t.completion_date() else date.max), group=(lambda t: humanize_date(t.completion_date()) if t.completion_date() else 'None'), label='Completed', ), 'context': Field(sort=lambda t: sorted(c.lower() for c in t.contexts()) or ['zz'], group=lambda t: sorted(t.contexts()) or ['None'], label='Context'), 'created': Field( # when a task has no creation date, push it to the end by assigning it # the maximum possible date. sort=(lambda t: t.creation_date() if t.creation_date() else date.max), group=(lambda t: humanize_date(t.creation_date()) if t.creation_date() else 'None'), label='Created',
def __init__(self, p_todolist, p_format=None): self.format_string = re.sub(r'\\t', '\t', p_format or config().list_format()) self.todolist = p_todolist self.one_line = False self.placeholders = { # absolute creation date 'c': lambda t: t.creation_date().isoformat() if t.creation_date() else '', # relative creation date 'C': lambda t: humanize_date(t.creation_date()) if t.creation_date() else '', # absolute due date 'd': lambda t: t.due_date().isoformat() if t.due_date() else '', # relative due date 'D': lambda t: humanize_date(t.due_date()) if t.due_date() else '', # relative dates: due, start 'h': lambda t: humanize_dates(t.due_date(), t.start_date()), # relative dates in form: creation, due, start 'H': lambda t: humanize_dates(t.due_date(), t.start_date(), t.creation_date()), # todo ID 'i': lambda t: str(self.todolist.number(t)), # todo ID, padded with spaces 'I': lambda t: _filler(str(self.todolist.number(t)), self.todolist.max_id_length()), # list of tags (spaces) without hidden ones and due: and t: 'k': lambda t: ' '.join([u'{}:{}'.format(tag, value) for tag, value in sorted(t.tags()) if tag not in config().hidden_tags() + [config().tag_start(), config().tag_due()]]), # list of all tags (spaces) 'K': lambda t: ' '.join([u'{}:{}'.format(tag, value) for tag, value in sorted(t.tags())]), # line number 'n': lambda t: str(self.todolist.linenumber(t)), # line number, padded with spaces 'N': lambda t: _filler(str(self.todolist.linenumber(t)), self.todolist.max_id_length()), # priority 'p': lambda t: t.priority() if t.priority() else '', # priority (or placeholder space) 'P': lambda t: t.priority() if t.priority() else ' ', # raw text 'r': lambda t: t.source(), # text 's': lambda t: t.text(), # text (truncated if necessary) 'S': lambda t: t.text(), # absolute start date 't': lambda t: t.start_date().isoformat() if t.start_date() else '', # relative start date 'T': lambda t: humanize_date(t.start_date()) if t.start_date() else '', # unique text ID 'u': lambda t: self.todolist.uid(t), # unique text ID, padded with spaces 'U': lambda t: _filler(self.todolist.uid(t), self.todolist.max_id_length()), # absolute completion date 'x': lambda t: 'x ' + t.completion_date().isoformat() if t.is_completed() else '', # relative completion date 'X': lambda t: 'x ' + humanize_date(t.completion_date()) if t.is_completed() else '', 'z': lambda t: color_block(t) if config().colors() else ' ', } self.format_list = self._preprocess_format()