def journal(request,P,C,task):
    t = get_task(C,task)
    jitems = read_journal(t)
    return basevars(request,P,C,{'task':t,'j':{'%s existing entries'%t._id:jitems},'metastates':METASTATES})
Beispiel #2
0
def journal(request,task):
    t = get_task(task)
    jitems = read_journal(t)
    return {'task':t,'j':{'%s existing entries'%t._id:jitems},'metastates':METASTATES}
def queue(request,P,C,assignee=None,archive=False,metastate_group='merge'):
    #print('queue()')
    if assignee=='me':
        assignee=get_admin(request,'unknown')
    queue={}
    #print('get_journals()')
    gj = get_journals(P,C,
                      assignee=assignee,
                      metastate_group=metastate_group,
                    archive=archive
    )
    for tj in gj:
        t = tj['contents']
        tid = t['_id']
        #print('going over task',tid)
        cm,content = read_current_metastates(tj['contents'],True)

        #skip this task if has no metastates relevant to us
        relevant_metastates=False
        for cmk in cm:
            if cmk in cfg.METASTATES[metastate_group]:
                relevant_metastates=True
                break
        if not relevant_metastates: continue
        #print 'reading journal'
        jitems = read_journal(t)
        lupd = sorted(list(cm.values()),key=lambda x:x['updated'],reverse=True)
        if len(lupd): lupd=lupd[0]['updated']
        else: lupd=None
        #any journal update takes precedence
        if len(jitems):
            try:
                jlupd = jitems[-1]['created_at']
            except:
                raise Exception(jitems[-1])
            if not lupd or jlupd >=lupd:
                lupd = jlupd
        #assert t.get('total_hours')!='None'
        #print 'adding to queue'
        queue[tid]={'states':dict([(cmk,cmv['value']) for cmk,cmv in list(cm.items())]),
                    #'total_hours':t.get('total_hours',0),
                    'fullstates':cm,
                    'last updated':lupd,
                    'status':t['status'],
                    'summary':t['summary'],
                    'last entry':content,
                    'tags':t['tags'],
                    'assignee':t['assignee'],
                    'merge':[l['url'] for l in t['links'] if l['anchor']=='merge doc'],
                    'job':[l['url'] for l in t['links'] if l['anchor']=='job'],
                    'specs':[l['url'] for l in t['links'] if l['anchor']=='specs']}
    queue = list(queue.items())
    qsort = cmp_to_key(
        lambda x1,x2: 
        cmp((x1[1]['last updated'] and datetime.datetime.strptime(x1[1]['last updated'].split('.')[0],iso_dfmt) or datetime.datetime(year=1970,day=1,month=1)),
        (x2[1]['last updated'] and datetime.datetime.strptime(x2[1]['last updated'].split('.')[0],iso_dfmt) or datetime.datetime(year=1970,day=1,month=1))))
    queue.sort(key=qsort,reverse=True)


    metastate_url_prefix = dict (list(zip(list(cfg.METASTATE_URLS.values()),list(cfg.METASTATE_URLS.keys()))))[metastate_group]
    #print('rendering')
    return basevars(request,P,C,{'queue':queue,
            'metastate_group':metastate_group,
            'metastate_url_prefix':metastate_url_prefix,
            'metastates':METASTATES,
            'colors':cfg.METASTATES_COLORS,
            'overrides':cfg.METASTATES_OVERRIDES})
Beispiel #4
0
def queue(request,assignee=None,archive=False,metastate_group='merge'):
    if assignee=='me':
        assignee=get_admin(request,'unknown')
    queue={}
    print 'cycling journals'
    for t in get_journals():
        if assignee and t.assignee!=assignee: continue

        if metastate_group!='production':
            if not archive and t['status'] in cfg.DONESTATES: continue
            elif archive and t['status'] not in cfg.DONESTATES: continue

        tid = t._id
        #print t
        assert t.status,"could not get status for %s"%tid
        #print 'reading metastates'
        cm,content = read_current_metastates(t,True)

        #skip this task if has no metastates relevant to us
        relevant_metastates=False
        for cmk in cm:
            if cmk in cfg.METASTATES[metastate_group]:
                relevant_metastates=True
                break
        if not relevant_metastates: continue
        print 'reading journal'
        jitems = read_journal(t)
        lupd = sorted(cm.values(),lambda x1,x2: cmp(x1['updated'],x2['updated']),reverse=True)
        if len(lupd): lupd=lupd[0]['updated']
        else: lupd=None
        #any journal update takes precedence
        if len(jitems):
            try:
                jlupd = jitems[-1]['created_at']
            except:
                raise Exception(jitems[-1])
            if not lupd or jlupd >=lupd:
                lupd = jlupd
        #assert t.get('total_hours')!='None'
        print 'adding to queue'
        queue[tid]={'states':dict([(cmk,cmv['value']) for cmk,cmv in cm.items()]),
                    #'total_hours':t.get('total_hours',0),
                    'fullstates':cm,
                    'last updated':lupd,
                    'status':t['status'],
                    'summary':t['summary'],
                    'last entry':content,
                    'tags':t['tags'],
                    'assignee':t.assignee,
                    'merge':[l['url'] for l in t.links if l['anchor']=='merge doc'],
                    'job':[l['url'] for l in t.links if l['anchor']=='job'],
                    'specs':[l['url'] for l in t.links if l['anchor']=='specs']}
    print 'done. itemizing'
    queue = queue.items()
    print 'sorting'
    queue.sort(lambda x1,x2: cmp((x1[1]['last updated'] and x1[1]['last updated'] or datetime.datetime(year=1970,day=1,month=1)),(x2[1]['last updated'] and x2[1]['last updated'] or datetime.datetime(year=1970,day=1,month=1))),reverse=True)


    metastate_url_prefix = dict (zip(cfg.METASTATE_URLS.values(),cfg.METASTATE_URLS.keys()))[metastate_group]
    print 'rendering'
    return {'queue':queue,
            'metastate_group':metastate_group,
            'metastate_url_prefix':metastate_url_prefix,
            'metastates':METASTATES,
            'colors':cfg.METASTATES_COLORS,
            'overrides':cfg.METASTATES_OVERRIDES}