Esempio n. 1
0
def outs():
    user_id = int(request.values.get('user_id', 0))
    page = int(request.values.get('p', 1))
    status = int(request.values.get('status', 0))
    start = request.values.get('start', '')
    end = request.values.get('end', '')
    outs = [
        k for k in Out.all() if k.status > 0]

    if start and end:
        start_time = datetime.datetime.strptime(start, "%Y-%m-%d %H:%M")
        end_time = datetime.datetime.strptime(end, "%Y-%m-%d %H:%M")
        outs = [k for k in outs if k.start_time >=
                start_time and k.start_time < end_time]
    if status:
        outs = [k for k in outs if k.status == status]
    if user_id:
        outs = [k for k in outs if k.creator.id == user_id]
    outs = sorted(outs, key=lambda x: x.start_time, reverse=True)
    if request.values.get('action') == 'excel':
        return write_outs_excel(outs)
    paginator = Paginator(outs, 50)
    try:
        outs = paginator.page(page)
    except:
        outs = paginator.page(paginator.num_pages)
    return tpl('/account/out/outs.html', outs=outs, user_id=user_id, start=start,
               title=u'所有外出报备列表', status=status,
               params="&user_id=%s&start=%s&end=%s&status=%s" % (
                   user_id, start, end, status), end=end, page=page,
               under_users=[{'uid': k.id, 'name': k.name} for k in User.all()])
Esempio n. 2
0
def meeting_s(oid):
    out = Out.get(oid)
    if request.method == 'POST':
        meeting_s = request.values.get('meeting_s', '')
        out.meeting_s = meeting_s
        if out.status == 1:
            o_status = 4
            out.status = o_status
            status = 13
        elif out.status == 2:
            o_status = 3
            out.status = o_status
            status = 4
        elif out.status == 3:
            o_status = 3
            status = 3
        elif out.status == 4:
            o_status = 4
            status = 13
        out.save()
        for out_report in OutReport.query.filter_by(out=out):
            out_report.status = o_status
            out_report.save()
        flash(u'会议纪要填写完毕', 'success')
        account_out_apply_signal.send(
            current_app._get_current_object(), out=out, status=status)
        return redirect(url_for('account_out.index'))
    return tpl('/account/out/meeting_s.html', out=out)
Esempio n. 3
0
def status(oid):
    status = int(request.values.get('status', 1))
    out = Out.get(oid)
    if status == 10:
        o_status = 0
        out.status = o_status
        msg = u'外出报备撤回'
    elif status == 11:
        o_status = 0
        out.status = o_status
        msg = u'外出报备被驳回'
    elif status == 1:
        o_status = 1
        out.status = o_status
        msg = u'外出报备,邮件已发出'
    elif status == 2:
        o_status = 2
        out.status = o_status
        msg = u'外出报备通过'
    elif status == 14:
        o_status = 3
        out.status = o_status
        msg = u'外出报备通过-会议纪要填写完毕'
    out.save()
    for out_report in OutReport.query.filter_by(out=out):
        out_report.status = o_status
        out_report.save()
    flash(msg, 'success')
    account_out_apply_signal.send(
        current_app._get_current_object(), out=out, status=status)
    if g.user == out.creator:
        return redirect(url_for('account_out.index'))
    else:
        return redirect(url_for('account_out.underling'))
Esempio n. 4
0
def underling():
    user_id = int(request.values.get('user_id', 0))
    page = int(request.values.get('p', 1))
    status = int(request.values.get('status', 0))
    start = request.values.get('start', '')
    end = request.values.get('end', '')

    if g.user.is_super_leader():
        outs = [k for k in Out.all() if k.status in [
            OUT_STATUS_APPLY, OUT_STATUS_PASS, OUT_STATUS_MEETED, OUT_STATUS_MEETED_NOT_PASS]]
        under_users = [{'uid': k.id, 'name': k.name} for k in User.all()]
    else:
        under_users = _get_all_under_users(g.user.id)
        if user_id:
            underling_user_ids = [user_id]
        else:
            underling_user_ids = list(set([k['uid'] for k in under_users]))
        outs = [k for k in Out.all() if k.creator.id in underling_user_ids and k.status in [
            OUT_STATUS_APPLY, OUT_STATUS_PASS, OUT_STATUS_MEETED, OUT_STATUS_MEETED_NOT_PASS]]

    if start and end:
        start_time = datetime.datetime.strptime(start, "%Y-%m-%d %H:%M")
        end_time = datetime.datetime.strptime(end, "%Y-%m-%d %H:%M")
        outs = [k for k in outs if k.start_time >=
                start_time and k.start_time < end_time]
    if status:
        outs = [k for k in outs if k.status == status]
    outs = sorted(outs, key=lambda x: x.start_time, reverse=True)
    paginator = Paginator(outs, 50)
    try:
        outs = paginator.page(page)
    except:
        outs = paginator.page(paginator.num_pages)
    return tpl('/account/out/outs.html', outs=outs, user_id=user_id, start=start,
               title=u'下属的外出报备列表', under_users=under_users, status=status,
               params="&user_id=%s&start=%s&end=%s&status=%s" % (
                   user_id, start, end, status),
               end=end, page=page)
Esempio n. 5
0
# encoding: utf-8
import sys

sys.path.append('/Users/guoyu1/workspace/inad/braavos')
# sys.path.append('/home/inad/apps/braavos/releases/current')

from app import app

from models.user import Out, OutReport

if __name__ == '__main__':
    outs = Out.all()
    for k in outs:
        OutReport.add(start_time=k.start_time,
                      end_time=k.end_time,
                      address=k.address,
                      reason=k.reason,
                      meeting_s=k.meeting_s,
                      persions=k.persions,
                      m_persion=k.m_persion,
                      m_persion_type=k.m_persion_type,
                      creator_type=k.creator_type,
                      create_time=k.create_time,
                      status=k.status,
                      out=k,
                      creator=k.creator)
        for i in k.joiners:
            OutReport.add(start_time=k.start_time,
                          end_time=k.end_time,
                          address=k.address,
                          reason=k.reason,
Esempio n. 6
0
def update(oid):
    out = Out.get(oid)
    joiners_form = JoinersForm(request.form)
    joiners_form.joiners.data = [u.id for u in out.joiners]
    m_persions = []
    if g.user.is_out_saler:
        m_persions += [{'key': '1' + '-' +
                        str(k.id) + '-' + k.name, 'name': k.name} for k in Client.all()]
        m_persions += [{'key': '2' + '-' +
                        str(k.id) + '-' + k.name, 'name': k.name} for k in Agent.all()]
        m_persions += [{'key': '3' + '-' +
                        str(k.id) + '-' + k.name, 'name': k.name} for k in Medium.all()]
        m_persions.append({'key': 100, 'name': u'其他'})
    if request.method == 'POST':
        if g.user.is_out_saler:
            creator_type = 1
        else:
            creator_type = 2
        start_time = request.values.get('start_time', '')
        end_time = request.values.get('end_time', '')
        # m_person有两种类型,一种是其他所以填写,一种是代理+客户+媒体组合而成,例如:1-1,2-1,3-1(具体请查看m_persions)
        m_persion = request.values.get('m_persion', '')
        m_persion_type = int(request.values.get('m_persion_type', 1))
        reason = request.values.get('reason', '')
        persions = request.values.get('persions', '')
        address = request.values.get('address', '')
        joiners = User.gets(request.values.getlist('joiners'))
        out.start_time = datetime.datetime.strptime(
            start_time, '%Y-%m-%d %H:%M')
        out.end_time = datetime.datetime.strptime(end_time, '%Y-%m-%d %H:%M')
        out.reason = reason
        out.joiners = joiners
        out.persions = persions
        out.address = address
        out.m_persion = m_persion
        out.m_persion_type = m_persion_type
        out.creator_type = creator_type
        out.status = int(request.values.get('action', 0))
        out.create_time = datetime.datetime.now()
        out.save()
        # 先删除外出报表,在从新添加
        OutReport.query.filter_by(out_id=oid).delete()
        for k in list(set(joiners + [out.creator])):
            OutReport.add(
                start_time=datetime.datetime.strptime(
                    start_time, '%Y-%m-%d %H:%M'),
                end_time=datetime.datetime.strptime(
                    end_time, '%Y-%m-%d %H:%M'),
                reason=reason,
                out=out,
                meeting_s='',
                persions=persions,
                address=address,
                m_persion=m_persion,
                m_persion_type=m_persion_type,
                creator_type=creator_type,
                status=int(request.values.get('action', 0)),
                creator=k,
                create_time=datetime.datetime.now()
            )

        if int(int(request.values.get('action', 0))) == OUT_STATUS_APPLY:
            flash(u'已发送申请', 'success')
            account_out_apply_signal.send(
                current_app._get_current_object(), out=out, status=1)
        else:
            flash(u'添加成功,请及时申请外出报备', 'success')
        return redirect(url_for('account_out.index'))
    return tpl('/account/out/update.html', out=out, m_persions=m_persions, joiners_form=joiners_form)
Esempio n. 7
0
def info(oid):
    out = Out.get(oid)
    return tpl('/account/out/info.html', out=out)
Esempio n. 8
0
def delete(oid):
    OutReport.query.filter_by(out_id=oid).delete()
    Out.get(oid).delete()
    flash(u'删除成功', 'success')
    return redirect(url_for('account_out.index'))
Esempio n. 9
0
# encoding: utf-8
import sys
sys.path.append('/Users/guoyu1/workspace/inad/braavos')
# sys.path.append('/home/inad/apps/braavos/releases/current')

from app import app

from models.user import Out, OutReport


if __name__ == '__main__':
    outs = Out.all()
    for k in outs:
        OutReport.add(start_time=k.start_time,
                      end_time=k.end_time,
                      address=k.address,
                      reason=k.reason,
                      meeting_s=k.meeting_s,
                      persions=k.persions,
                      m_persion=k.m_persion,
                      m_persion_type=k.m_persion_type,
                      creator_type=k.creator_type,
                      create_time=k.create_time,
                      status=k.status,
                      out=k,
                      creator=k.creator)
        for i in k.joiners:
            OutReport.add(start_time=k.start_time,
                          end_time=k.end_time,
                          address=k.address,
                          reason=k.reason,