Esempio n. 1
0
File: state.py Progetto: Tobbe/cog
    def children(self, master_id, type='PARENT'):
        result = []

        for data in self.get_all():
            for link_id in dm.get_links(data, type):
                if link_id == master_id:
                    result.append(data)
                    break

        return result
Esempio n. 2
0
def _generate_item_page(state, data):
    name = dm.get(data, 'NAME', '?')
    logging.debug('Generating "%s"', name)
    root, tag = _make_page_base(name)

    # basic
    tag.h2('Basics')
    tbl = tag.table()
    for key in ['NAME', 'ID', 'PRIORITY']:
        title = key[0] + key[1:].lower()
        tr = tbl.tr()
        tr.th(title)
        tr.td(dm.get(data, key, '?'))
    tr = tbl.tr()
    tr.th('Status')
    tr.td(dm.get_status(data))
    tr = tbl.tr()
    tr.th('Assigned')
    tr.td(', '.join(filter(len, data.get('ASSIGNED', []))))

    # links
    tag.h2('Links')
    tbl = tag.table()
    tr = tbl.tr()
    for header in ['Parent', 'Child', 'Related']:
        tr.th(header, width='33%')

    parents = [state.get(key)
               for key in dm.get_links(data, 'PARENT')]
    children = state.children(dm.get(data, 'ID'))
    related = [state.get(key)
               for key in dm.get_links(data, 'LINK')]

    for i in range(max(map(len, [parents, children, related]))):
        tr = tbl.tr()
        for items in [parents, children, related]:
            if len(items) > i:
                _add_link(tr.td(), items[i])
            else:
                tr.td()

    # description
    tag.h2('Description')
    if not dm.null(data, 'DESCRIPTION'):
        div = tag.div(klass='description')
        for line in data.get('DESCRIPTION', []):
            div.text(line)
            div.br()

    # time
    tag.h2('Time')

    tbl = tag.table(klass='small')
    for key, value in [('Original estimate', dm.get_estimate(data)),
                       ('Total time spent', dm.get_time_spent(data)),
                       ('Current remaining time', dm.get_remaining_time(data))]:
        tr = tbl.tr()
        tr.th(key)
        tr.td(str(value))
    tr = tbl.tr()
    tr.th('Status')
    _make_relative_meter(tr.td(),
                         -dm.get_projected_time_diff(data),
                         dm.get_estimate(data))

    tag.br()

    tbl = tag.table()
    tr = tbl.tr()
    for header in ['Reported', 'User', 'Spent', 'Remaining']:
        tr.th(header)
    for rep in dm.get_time_reports(data):
        tr = tbl.tr()
        for key in ['time', 'user', 'spent', 'remaining']:
            tr.td(rep[key])

    return root