Пример #1
0
def journal_edit(request,task,jid):
    adm = get_admin(request,'unknown')
    t = get_task(task)
    if request.method=='POST':
        metastates={}
        for ms,msvals in METASTATES.items():
            msv = request.params.get(ms)
            if msv and msv in msvals:
                metastates[ms]=msv
       
        append_journal_entry(t,adm,request.params.get('content'),metastates)

        redir = '/'+URL_PREFIX+task+'/j'
        rd = Redirect(redir)
        return rd

    j = rpr(request,task,journal=True,render_only=True)

    return {'t':t,'j':j,'metastates':METASTATES}
Пример #2
0
def metastate_set(request,P,C):
    k = request.params.get('k')
    v = request.params.get('v')
    spl = k.split('-')
    tid = spl[1]
    msk = '-'.join(spl[2:])
    #_,tid,msk = 

    adm = get_admin(request,'unknown')
    #special case
    if msk=='work estimate':
        t = get_task(C,tid)
        #print '%s = %s + %s'%(msk,t['total_hours'],v)
        #v = "%4.2f"%(float(t.get('total_hours',0))+float(v))
    else:
        t =  get_task(C,tid)

    print('setting %s.%s = %s'%(tid,msk,v))
    append_journal_entry(P,C,t,adm,'',{msk:v})
    return {'status':'ok'}
Пример #3
0
def metastate_set(request):
    k = request.params.get('k')
    v = request.params.get('v')
    spl = k.split('-')
    tid = spl[1]
    msk = '-'.join(spl[2:])
    #_,tid,msk = 

    adm = get_admin(request,'unknown')
    #special case
    if msk=='work estimate':
        t = get_task(tid)
        #print '%s = %s + %s'%(msk,t['total_hours'],v)
        #v = "%4.2f"%(float(t.get('total_hours',0))+float(v))
    else:
        t =  get_task(tid)

    print 'setting %s.%s = %s'%(tid,msk,v)
    append_journal_entry(t,adm,'',{msk:v})
    return {'status':'ok'}
Пример #4
0
def task(request,P,C,task,rev=None):
    # fetch_stamp is a hidden form input used to protect task updates against overwrite by older forms of the task submitted
    fstamp = request.params.get('changed_at')
    if fstamp and fstamp!='None': fstamp = datetime.datetime.strptime( fstamp, "%Y-%m-%d %H:%M:%S.%f" )
    else: fstamp=None

    now = datetime.datetime.now()
    if task.endswith('/'): task=task[0:-1]
    gwu = cfg.GITWEB_URL
    if task.startswith('new/'):
        under='/'.join(task.split('/')[1:])
        task='new'
    else:
        under=None
    msg=None
    adm = get_admin(request,'unknown')
    repos = get_repos(C)
    usernames = get_usernames(C)

    tags=[] ; links=[] ; informed=[] ; branches=[] ;
    cross_links_raw = get_cross_links(C,task)
    cross_links=[]
    dependencies=[]
    for k,v in list(request.params.items()):
        if k.startswith('tag-'):
            tn = k.replace('tag-','')
            if tn=='new':
                for nt in [nt.strip() for nt in v.split(',') if nt.strip()!='']:
                    tags.append(nt)
            else:
                tags.append(tn)
        if k.startswith('link-'):
            tn = k.replace('link-','')
            if tn in ['new-url','new-anchor']:
                continue #raise Exception('newlink')
            else:
                links.append({'url':v,'anchor':tn})
        if k.startswith('informed-'):
            tn = k.replace('informed-','')
            if tn=='new': continue
            informed.append(tn)
        if k.startswith('branches-'):
            tn = k.replace('branches-','')
            if tn in ['new-repo','new-branch']: continue
            branches.append(tn)
        if k.startswith('cross_link-'):
            cln = k.replace('cross_link-','')
            cross_links.append(cln)
            #print('adding cross_link',cln,'due to',k,v)
        if k.startswith('dependency-'):
            dln = k.replace('dependency-','')
            dependencies.append(dln)
    lna = request.params.get('link-new-anchor')
    lnu = request.params.get('link-new-url')
    ncl = request.params.get('add-cross_link')
    ndl = request.params.get('add-dependency')

    if task and task!='new':
        karma = getattr(get_task(C,task),'karma',{})
    else:
        karma = {}

    nkarma = request.params.get('karma-new')
    if nkarma:
        kdt = datetime.datetime.now().date().strftime('%Y-%m-%d')
        nkarmaval = request.params.get('karma-plus') and 1 or -1
        # find out what's our expense for today
        mykarma = sum([k['value'][1] for k in get_karma(C,kdt,adm)])
        if (nkarmaval>0 and mykarma<cfg.KARMA_POINTS_PER_DAY) or nkarmaval<0:
            if kdt not in karma: karma[kdt]={}
            if adm not in karma[kdt]: karma[kdt][adm]={}
            if nkarma not in karma[kdt][adm]: karma[kdt][adm][nkarma]=0
            newval = karma[kdt][adm][nkarma]+nkarmaval
            if newval>=0: karma[kdt][adm][nkarma]=newval

    if ncl:
        for ncli in ncl.split(','):
            cross_links.append(ncli)
    if ndl:
        for ndli in ndl.split(','):
            dependencies.append(ndli)

    if lna and lnu:
        links.append({'anchor':lna,'url':lnu})

    inn = request.params.get('informed-new')
    if inn and inn not in informed:
        informed.append(inn)

    nrb = request.params.get('branches-new-branch','')
    assert '/' not in nrb,"branch name may not contain '/'"
    if nrb: branches.append(request.params.get('branches-new-repo')+'/'+nrb)


    tags = list(set([tag for tag in tags if tag!='']))

    uns = request.params.get('unstructured','').strip()
    if len(uns) and not uns.startswith('**'):
        uns='** Details\n'+uns
    assignees=[request.params.get('assignee')]

    if request.params.get('id') and request.params.get('id')!='None':
        t = get_task(C,request.params.get('id'))
        assignees.append(t.assignee)
        tid = request.params.get('id')
        o_params = {'summary':request.params.get('summary'),
                    'karma':dict(karma),
                    'tags':tags,
                    'status':request.params.get('status'),
                    'assignee':request.params.get('assignee'),
                    'handled_by':request.params.get('handled_by'),
                    'unstructured':uns,
                    'links':links,
                    'cross_links_raw':request.params.get('cross_links'),
                    'cross_links':cross_links,
                    'dependencies':dependencies,
                    'informed':informed,
                    'branches':branches}
        print(o_params)
        rewrite(P,C,tid,o_params,safe=False,user=adm,fetch_stamp=fstamp)
        t = get_task(C,tid)
        cross_links_raw = get_cross_links(C,tid)
        if request.params.get('content-journal'):
            tj = get_task(C,task)
            metastates={}
            append_journal_entry(P,C,tj,adm,request.params.get('content-journal'),metastates)
        assert request.params.get('id')



    if request.params.get('create'):
        o_params = {'summary':request.params.get('summary'),
                    'status':request.params.get('status'),
                    'assignee':request.params.get('assignee'),
                    'creator':get_admin(request,'unknown'),
                    'handled_by':request.params.get('handled_by'),
                    'unstructured':uns,
                    'links':links,
                    'informed':informed,
                    'branches':branches}
        if request.params.get('under'):
            parent = request.params.get('under')
        else:
            parent=None
        rt = add_task(P,C,parent=parent,params=o_params,tags=tags,user=adm)
        redir = '/'+URL_PREFIX+rt._id
        print('redircting to %s'%redir)
        rd = Redirect(redir)
        return rd
    if task=='new':
        ch=[]
    else:
        #raise Exception('eff off',task)
        #print('getting children')
        ch = get_children(C,task)
        sortmode = request.params.get('sortby','default')
        ch.sort(key=cmp_to_key(sortmodes[sortmode]),reverse=True)
        print(('got',len(ch),'kids'))

    if task=='new':
        t = Task(created_at=None,
                 summary='',
                 unstructured='',
                 status='TODO',
                 assignee=adm,
                 creator=adm,
                 tags=[],
                 links=[],
                 branches=[],
                 karma={},
                 journal=[])
        opar=[]
        gantt_labels={} ; gantt={}
        changed_at=None
    else:
        gantt_labels,gantt = gantt_info(C,task)
        C.execute("select changed_at from tasks where id=%s",(task,))
        fo = C.fetchone()
        if fo:
            changed_at = fo['changed_at']
        else:
            changed_at = None
        if rev:
            t = Task.get_rev(C,task,rev)
        else:
            t = get_task(C,task)
        par = task ; parents=[]
        parents = task.split('/')
        opar = []
        for i in range(len(parents)-1):
            opar.append('/'.join(parents[:i+1]))
    parents = [(pid,get_task(C,pid)['summary']) for pid in opar]
    prt = get_usernames(C)
    metastates,content = read_current_metastates(t,True)
    zerodelta = datetime.timedelta(seconds=0)
    if gantt.get('t') and gantt.get('we'):
        remaining_hours = gantt.get('we')-gantt.get('t')
    else:
        remaining_hours=zerodelta
    #journal
    jitems = t.journal
    dependencies = getattr(t,'dependencies',[])
    branchtargets=[(re.compile("pre"),"preproduction"),
                   (re.compile("prod"),"production"),
                   (re.compile(".*"),"staging")]
    btgts={}
    for br in t.branches:
        for ptn,tgt in branchtargets:
            ptnres = ptn.search(br.split("/")[1])
            #print 'ptnres of',br,'in',tgt,'is',ptnres
            if ptnres: 
                if tgt not in btgts: btgts[tgt]=[]
                btgts[tgt].append(br)
                break

    C.execute("select * from tasks_pri_comb_lean where id=%s",(task,))
    pri = C.fetchall()
    if len(pri):
        pr = pri[0]
        pri = pr['tot_pri']
        dep_pri = pr['dep_pri']
    else:
        pri=0
        dep_pri=0

    C.execute("select depid,path_info from tasks_deps_hierarchy where tid=%s",(t._id,))
    fulldeps = [d for d in C.fetchall() if d['depid'] not in dependencies]
    C.execute("select tid,path_info from tasks_deps_hierarchy where depid=%s",(t._id,))
    dependants = [d for d in C.fetchall()]
    tup = tuple(cross_links_raw+
                [d['tid'] for d in dependants]+
                [d for d in dependencies]+
                [fd['depid'] for fd in fulldeps])
    if len(tup):
        C.execute("select id id,contents->>'summary' summary from tasks where id in %s",(tup,))
        summaries = dict([(r['id'],r['summary']) for r in C.fetchall()])
    else:
        summaries={}

    return basevars(request,P,C,{'task':t,
                                 'rev':rev,
                                 'changed_at':changed_at,
                                 'pri':pri,
                                 'dep_pri':dep_pri,
                                 'gantt':gantt,
                                 'gantt_labels':gantt_labels,
                                 'zerodelta':zerodelta,
                                 'branches_by_target':btgts,
                                 'summaries':summaries,
                                 'cross_links':cross_links_raw,
                                 'dependencies':dependencies,
                                 'fulldeps':fulldeps,
                                 'dependants':dependants,
                                 'remaining_hours':remaining_hours,
                                 'total_hours':0,
                                 'j':{'%s existing entries'%t._id:jitems},
                                 'gwu':gwu,
                                 'url':RENDER_URL,
                                 'statuses':STATUSES,
                                 'participants':prt,
                                 'usernames':usernames,
                                 'msg':msg,
                                 'children':ch,
                                 'repos':repos,
                                 'parents':parents,
                                 'request':request,
                                 'metastates':metastates,
                                 'possible_metastates':cfg.METASTATES,
                                 'colors':cfg.METASTATES_COLORS,
                                 'overrides':cfg.METASTATES_OVERRIDES,
                                 'karma_per_day':cfg.KARMA_POINTS_PER_DAY,
                                 'diff_branches':cfg.DIFF_BRANCHES,
                                 'under':under,
                                 'humanize':humanize,
                                 'now':now,
                                 'reduce':reduce,
    })
                        'content': md['content'],
                        'created_at': j_cr_dt,
                        'creator': j_creator,
                        'attrs': {
                            'unq_key': j_unq_key
                        }
                    }

                    if j_unq_key in jattrs:
                        if jentry != t.journal[myei]:
                            t.journal[myei] = jentry
                            t.save(sys.argv[0])
                            j_rw_cnt += 1
                        else:
                            j_noop_cnt += 1
                    else:
                        with P as p:
                            C = p.cursor()
                            append_journal_entry(P, C, t, jentry['creator'],
                                                 jentry['content'],
                                                 jentry['attrs'],
                                                 jentry['created_at'])
                            j_nw_cnt += 1

        #print threads
        print('=' * 20)
        print(nw_cnt, ' added ;', rw_cnt, 'rewritten ;', noop_cnt,
              'tasks unchanged')
        print(j_nw_cnt, ' journal entries added ;', j_rw_cnt,
              'journals rewritten ;', j_noop_cnt, 'journals unchanged')
Пример #6
0
def task(request,task):
    if task.endswith('/'): task=task[0:-1]
    gwu = cfg.GITWEB_URL
    if task.startswith('new/'):
        under='/'.join(task.split('/')[1:])
        task='new'
    else:
        under=None
    msg=None
    adm = get_admin(request,'unknown')
    repos = [r['Name'] for r in get_table_contents(os.path.join(cfg.DATADIR,'repos.org')) if r.get('Name')]

    tags=[] ; links=[] ; informed=[] ; branches=[]
    for k,v in request.params.items():
        if k.startswith('tag-'):
            tn = k.replace('tag-','')
            if tn=='new':
                for nt in [nt.strip() for nt in v.split(',') if nt.strip()!='']:
                    tags.append(nt)
            else:
                tags.append(tn)
        if k.startswith('link-'):
            tn = k.replace('link-','')
            if tn in ['new-url','new-anchor']:
                continue #raise Exception('newlink')
            else:
                links.append({'url':v,'anchor':unicode(tn,'utf-8')})
        if k.startswith('informed-'):
            tn = k.replace('informed-','')
            if tn=='new': continue
            informed.append(tn)
        if k.startswith('branches-'):
            tn = k.replace('branches-','')
            if tn in ['new-repo','new-branch']: continue
            branches.append(tn)
    lna = request.params.get('link-new-anchor')
    lnu = request.params.get('link-new-url')

    if lna and lnu:
        links.append({'anchor':lna,'url':lnu})

    inn = request.params.get('informed-new')
    if inn and inn not in informed:
        informed.append(inn)

    nrb = request.params.get('branches-new-branch','')
    assert '/' not in nrb,"branch name may not contain '/'"
    if nrb: branches.append(request.params.get('branches-new-repo')+'/'+nrb)


    tags = list(set([tag for tag in tags if tag!='']))

    uns = request.params.get('unstructured','').strip()
    if len(uns) and not uns.startswith('**'):
        uns='** Details\n'+uns
    assignees=[request.params.get('assignee')]

    if request.params.get('id') and request.params.get('id')!='None':
        t = get_task(request.params.get('id'))
        assignees.append(t.assignee)
        tid = request.params.get('id')
        o_params = {'summary':request.params.get('summary'),
                    'tags':tags,
                    'status':request.params.get('status'),
                    'assignee':request.params.get('assignee'),
                    'unstructured':uns,
                    'links':links,
                    'informed':informed,
                    'branches':branches}
        print o_params
        rewrite(tid,o_params,safe=False,user=adm)
        t = get_task(tid)
        if request.params.get('content-journal'):
            tj = get_task(task)
            metastates={}
            append_journal_entry(tj,adm,request.params.get('content-journal'),metastates)
        assert request.params.get('id')



    if request.params.get('create'):
        o_params = {'summary':request.params.get('summary'),
                    'status':request.params.get('status'),
                    'assignee':request.params.get('assignee'),
                    'creator':get_admin(request,'unknown'),
                    'unstructured':uns,
                    'links':links,
                    'informed':informed,
                    'branches':branches}
        if request.params.get('under'):
            parent = request.params.get('under')
        else:
            parent=None
        rt = add_task(parent=parent,params=o_params,tags=tags,user=adm)
        redir = '/'+URL_PREFIX+rt._id
        print 'redircting to %s'%redir
        rd = Redirect(redir)
        return rd
    if task=='new':
        ch=[]
    else:
        ch = get_children(task)

    if task=='new':
        t = Task(created_at=None,
                 summary='',
                 unstructured='',
                 status='TODO',
                 assignee=adm,
                 creator=adm,
                 tags=[],
                 links=[],
                 branches=[],
                 journal=[])
        opar=[]
    else:
        t = get_task(task)
        par = task ; parents=[]
        parents = task.split('/')
        opar = []
        for i in xrange(len(parents)-1):
            opar.append('/'.join(parents[:i+1]))
    parents = [(pid,get_task(pid)['summary']) for pid in opar]
    prt = [r[0] for r in get_participants(sort=True)]
    metastates,content = read_current_metastates(t,True)

    # if t.get('total_hours') and metastates.get('work estimate'):
    #     remaining_hours = float(metastates.get('work estimate')['value']) - float(t.get('total_hours'))
    # elif t.get('total_hours'):
    #     remaining_hours = -1 * float(t.get('total_hours'))
    # else:
    #     remaining_hours = None
    remaining_hours=None

    #journal
    jitems = t.journal
    return {'task':t,
            'remaining_hours':remaining_hours,
            'total_hours':0,
            'j':{'%s existing entries'%t._id:jitems},
            'gwu':gwu,
            'url':RENDER_URL,
            'statuses':STATUSES,
            'participants':prt,
            'msg':msg,
            'children':ch,
            'repos':repos,
            'parents':parents,
            'request':request,
            'metastates':metastates,
            'possible_metastates':cfg.METASTATES,
            'colors':cfg.METASTATES_COLORS,
            'overrides':cfg.METASTATES_OVERRIDES,
            'diff_branches':cfg.DIFF_BRANCHES,
            'under':under,
    }