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'}
def history(request,task): t = get_task(C,task) st,op = gso('git log --follow -- %s'%(os.path.join(cfg.DATADIR,task,'task.org'))) ; assert st==0 commitsi = cre.finditer(op) for c in commitsi: cid = c.group(1) url = '%(gitweb_url)s/?p=%(docs_reponame)s;a=commitdiff;h=%(cid)s'%{'cid':cid,'gitweb_url':cfg.GITWEB_URL,'docs_reponame':cfg.DOCS_REPONAME} op = op.replace(cid,"<a href='%(url)s'>%(cid)s</a>"%{'cid':cid,'url':url}) t['summary'] = '' rt = basevars(request,P,C,{'op':op,'task':t,'request':request}) return rt
def global_journal(request,P,C,creator=None,day=None,groupby=None,state=None): adm = get_admin(request,'unknown') ai = [] if day=='current': daya=datetime.datetime.now().date() #strftime('%Y-%m-%d') day = [daya,daya] elif day: if ':' in day: days = day.split(':') daya = datetime.datetime.strptime(days[0],'%Y-%m-%d').date() dayb = datetime.datetime.strptime(days[1],'%Y-%m-%d').date() day = [daya,dayb] else: daya = datetime.datetime.strptime(day,'%Y-%m-%d').date() day = [daya,daya] print('obtaining journals') gaj = get_all_journals(C,day=day,creator=creator) print('obtained; reading %s journals'%len(gaj)) for jt in gaj: jtd = jt jt = get_task(C,jt['tid']) ji = [jtd] if creator: ji = [i for i in ji if i['creator']==creator] if state: sk,sv = state.split('=') ji = [i for i in ji if dict(i)['attrs'].get(sk)==sv] #print('ji=',ji,type(ji)) for jii in ji: jii['tid']=jt._id #print('appending entry',ji,'to list') ai+=ji print('finished reading. sorting') ai.sort(key=lambda x:x['created_at']) print('sorted') if groupby: rt={} for i in ai: assert groupby in i k = 'entries for %s'%i[groupby] if k not in rt: rt[k]=[] rt[k].append(i) return basevars(request,P,C,{'j':rt,'task':None,'groupby':groupby}) else: return basevars(request,P,C,{'j':{'all':ai},'task':None,'grouby':None})
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, })
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})