Example #1
0
    def _notify(self,user):
        print 'in notify'
        import sendgrid
        from docs import D,get_participants
        participants = get_participants(disabled=True)
        lc = last_change(self,D)
        if not lc: return
        rev,html,text,changes = lc
        if not hasattr(self,'notifications'): self.notifications={}
        if rev in self.notifications: return
        import config as cfg
        sg = sendgrid.SendGridClient(cfg.SENDGRID_USERNAME,cfg.SENDGRID_PASSWORD,secure=True)
        subj = '%s - %s ch.'%(self._id,','.join(changes))+(user and ' by %s'%user or '')
        snd = cfg.SENDER
        rcpts = set(self.informed+[self.creator,self.assignee] )-(user and set([user]) or set())
        rems = [participants[r]['E-Mail'] for r in rcpts]
        to = ', '.join(rems)
        print 'sending mail to %s'%to
        for rcpt in rems:
            msg = sendgrid.Mail(to=rcpt,
                                subject = subj,
                                html=html,
                                text=text,
                                from_email=snd)

            status,res = sg.send(msg)
            assert status==200,Exception(status,res)
        notif = {'notified_at':datetime.datetime.now(),
                 'user':user,
                 'informed':rcpts}
        self.notifications[rev]=notif
        print 'saving notification'
        self.save(user='******',notify=False)
        print 'done'
Example #2
0
def participants(request):
    pts = get_participants(sort=True)
    return {'pts':pts,'request':request}
    P, C = pg.connect()
    print('querying couch')

    if 'tasks' in sys.argv:
        #tds = [Task.get('1003/1')]
        tds = Task.view('task/all')
        print('walking tasks')
        for t in tds:
            pg.migrate_one(t, C)
        print('committing')
        P.commit()
        print('done')

    if 'participants' in sys.argv:
        # -- create table participants (username varchar primary key, name varchar unique,email varchar unique,active boolean default true, skype varchar unique, informed varchar[]);
        ps = get_participants(cfg.DATADIR, disabled=True, force=True)
        for p, vs in list(ps.items()):
            keys = [
                k for k in list(vs.keys()) if k.lower() not in
                ['ops', 'server', 'client', 'qa', 'art', '']
            ]
            fnames = [
                k.replace('-', '_').lower().replace('e_mail', 'email')
                for k in keys
            ]
            values = [vs[k] and vs[k] or None for k in keys]
            values[keys.index('Informed')] = values[keys.index(
                'Informed')] and '{%s}' % ",".join(
                    values[keys.index('Informed')].split(',')) or None
            qry = "insert into participants (%s) values (%s)" % (",".join([
                k for k in fnames
Example #4
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,
    }