Beispiel #1
0
def approval_new():
    """添加审批单
    
    使用 WTForm 来创建表单并验证和获取表单内容
    """
    print('nimei')
    form = ApprovalForm()
    list_subject = [(1, u'公务卡消费'), (2, u'非公务卡消费')]
    form.cost_type.choices = list_subject
    form.subject.choices = Subject.get_subjects()
    print 'nimeimei'
    if request.method == 'POST' and form.validate():
        approval = Approval()
        approval.agent_id = Person.judge(form.agent.data)
        approval.payee_id = Person.judge(form.payee.data)
        approval.subject_list = dict(Subject.get_subjects())[form.subject]
        db.session.add(approval)
        approval.save()
        
        form_list = [form.cost_type, approval.agent_id, form.max_money, approval.id, form.subject]
        invoices = Invoice.find_relation(form_list)
        if invoices[1] == None:
            approval_index = Approval.query.get(approval.id)
            approval_index.invoice_count = invoices[0]
            approval_index.subject_list += (' '+dict(Subject.get_subjects())[form.subject])
            approval_index.status = 'Printed'
            approval.save()
            flash(u'组合成功')
            return redirect('/approval/%d' % int(approval.id))
        return redirect('/approval/%d/chioce' % int(approval.id), incoices) 
    
        
#     if request.method == 'POST' and form.validate():
#         approval = Approval()
#         approval.agent_id = Person.judge(form.agent.data)
#         approval.payee_id = Person.judge(form.payee.data)
#         form.populate_obj(approval)
#         if request.files[form.picture.name]:
#             try:
#                 pic = Picture(request.files[form.picture.name])
#                 db.session.add(pic)
#                 pic.save()
#                 approval.picture_id = pic.id
#             except:
#                 flash(u'图片保存失败', 'error')
#         db.session.add(approval)
#         approval.save()
#         print 'nimei',approval.id
#         flash(u'成功添加审批单')
#         return redirect('/approval/%d' % int(approval.id))
    return render_template('/approval/edit.html', form = form, title=u'添加审批单')
Beispiel #2
0
def invoice_edit(id):
    """编辑发票
    
    和添加类似,参加 Person 的实现
    """
    inv = Invoice.query.get(id)
    form = InvoiceForm(request.form, obj=inv)
    form.subject_id.choices = Subject.get_subjects()
    if request.method == "POST" and form.validate():
        form.populate_obj(inv)
        if request.files[form.picture.name]:
            try:
                pic = Picture.query.get(inv.picture_id)
                if pic:
                    pic.restore(request.files[form.picture.name])
                    pic.save()
                else:
                    pic = Picture(request.files[form.picture.name])
                    db.session.add(pic)
                    pic.save()
                    inv.picture_id = pic.id
            except:
                flash(u"图片保存失败", "error")
        inv.save()
        flash(u"成功更新个人信息")
        return redirect("/invoice/%d/%d" % (id, id))
    return render_template("/invoice/edit.html", form=form, title=u"编辑发票")
Beispiel #3
0
def add_subject(row,group,data_from):
    img_buff = StringIO(row[5].read())
    district, name, cert_id = '', row[1], row[0]
    img_uri = save_stream(img_buff)
    core_ = Core.query.filter(Core.id == group.core_id).first()
    ip,port = core_.ip,core_.port
    basic_group_name = 'basic' + str(group.id)
    try:
            ret = add_image(ip,port,basic_group_name,img_buff,'',True)
            group_index = ret['id']
    except Exception  as e:
        log.error('过core失败:{}'.format(e))
        group_index = -1

    # subject = Subject.query.filter(Subject.cert_id == cert_id).first()
    # if not subject:
    subject = Subject(
        group_id = group.id,
        category = group.category,
        district = district,
        gender = group.gender,
        name = name,
        cert_id = cert_id,
        remark = data_from,
        timestamp = time.time()
    )
    db.session.add(subject)
    try:
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        log.error('{}存入subject表失败:{}'.format(name,e))
        return 0
    # else:
    #     subject.remark = data_from
    #     try:
    #         db.session.commit()
    #     except Exception as e:
    #         db.session.rollback()
    #         log.error('{}存入subject表失败:{}'.format(name,e))
    #         return 0

         
         
    photo = Photo(
            group_id = group.id,
            subject_id = subject.id,
            group_index = group_index,
            path = img_uri,
            rect = '',
            tag = '',
    )
    db.session.add(photo)
    try:
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        log.error('{}存入photo表失败:{}'.format(name,e))
        return 0
Beispiel #4
0
def subject_new():
    """添加个人
    
#     """
    form = SubjectForm(request.form)
    print ('nimei')
    
    if request.method == 'POST' and form.validate():
        ren = Subject()
        """新建一个对象"""
        form.populate_obj(ren)
        """用 WTForm 自带的方法把表单数据转换成对象里面的属性"""
        db.session.add(ren)
        """对于新建操作,需要调用 add() 来添加这个对象"""
        ren.save()
        """用对象本身实现的 save() 方法来实际写入数据库"""
        flash(u'成功添加个人 %s' % ren.name)
        return redirect('/subject/%d' % int(ren.id))
    return render_template('/subject/edit.html', form=form, title=u'添加个人')
Beispiel #5
0
def subject_index():
    """个人列表
    """
    rank = request.args.get('rank', 'id')
    search = request.args.get('search', '')
    order = request.args.get('order', 'asc')
    page, per_page, offset = get_page_items()
  
    subjects = Subject.find(search=search, order=order, rank=rank)
     
    pagination = get_pagination(page=page, total=subjects.count())
    
    return render_template('/subject/index.html',
                           subjects=subjects.offset(offset).limit(per_page), 
                           pagination=pagination ,
                           search=search,order=order)
Beispiel #6
0
def invoice_new():
    """添加发票
     
        添加发票时会让用户选择关联帐目,若未选择则自动添加一条帐目
    """
    form = InvoiceForm(request.form)
    form.subject_id.choices = Subject.get_subjects()
    if request.method == "POST" and form.validate():
        inv = Invoice()
        form.populate_obj(inv)
        if request.files[form.picture.name]:
            try:
                pic = Picture(request.files[form.picture.name])
                db.session.add(pic)
                pic.save()
                inv.picture_id = pic.id
            except:
                flash(u"图片保存失败", "error")
        db.session.add(inv)
        inv.save()
        return redirect("/invoice/%d/chioce" % int(inv.id))
    return render_template("/invoice/edit.html", form=form, title=u"添加发票")
Beispiel #7
0
    
=======

>>>>>>> 797deb1d9a238a9098207cfc01bab6963414987f
@approval.route('/new', methods=['POST', 'GET'])
def approval_new():
    """添加审批单
    
    使用 WTForm 来创建表单并验证和获取表单内容
    """
<<<<<<< HEAD
    print('nimei')
    form = ApprovalForm()
    list_subject = [(1, u'公务卡消费'), (2, u'非公务卡消费')]
    form.cost_type.choices = list_subject
    form.subject.choices = Subject.get_subjects()
    print 'nimeimei'
=======
    form = ApprovalForm(request.form)
    form.status.choices = Approval.get_status()
    form.approval_type.choices = Approval.get_approval_type()
>>>>>>> 797deb1d9a238a9098207cfc01bab6963414987f
    if request.method == 'POST' and form.validate():
        approval = Approval()
        approval.agent_id = Person.judge(form.agent.data)
        approval.payee_id = Person.judge(form.payee.data)
<<<<<<< HEAD
        approval.subject_list = dict(Subject.get_subjects())[form.subject]
        db.session.add(approval)
        approval.save()