示例#1
0
def approval_edit(id):
    """编辑发票
    
    和添加类似,参加 Person 的实现
    """
    approval = Approval.query.get(id)
    form = ApprovalForm(request.form, obj=approval)
    form.status.choices = Approval.get_status()
    form.approval_type.choices = Approval.get_approval_type()
    if request.method == 'POST' and form.validate():
        form.populate_obj(approval)
        
        if request.files[form.picture.name]:
            try:
                pic = Picture.query.get(approval.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()
                    approval.picture_id = pic.id
            except:
                flash(u'图片保存失败', 'error')
示例#2
0
文件: invoice.py 项目: kooksee/tobari
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"编辑发票")
示例#3
0
def approval_edit(id):
    """编辑发票
    
    和添加类似,参加 Person 的实现
    """
    approval = Approval.query.get(id)
    form = ApprovalForm(request.form, obj=approval)
    form.status.choices = Approval.get_status()
    form.approval_type.choices = Approval.get_approval_type()
    if request.method == 'POST' and form.validate():
        form.populate_obj(approval)
        
        if request.files[form.picture.name]:
            try:
                pic = Picture.query.get(approval.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()
                    approval.picture_id = pic.id
            except:
                flash(u'图片保存失败', 'error')
        approval.save()
        flash(u'成功更新审批单信息')
        return redirect('/approval/%d' % id)
    
    return render_template('/approval/edit.html', form = form, title=u'编辑审批单')
示例#4
0
文件: invoice.py 项目: kooksee/tobari
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"添加发票")
示例#5
0
def img_upload():
    req_args = request.form
    print(req_args)
    if not req_args:
        return jsonReturn.falseReturn(request.path, '请传必要参数')
    open_id = req_args.get('openId')
    if open_id is None:
        return jsonReturn.falseReturn(request.path, '请传必要参数')
    if 'img' not in request.files:
        return jsonReturn.falseReturn(request.path, '请上传file文件')
    img_obj = request.files.get("img")
    filename = img_obj.filename
    if not filename:
        return jsonReturn.falseReturn(request.path, '请上传file文件')
    img_type = filename[filename.rfind(".") + 1:].lower()
    # print(img_type)
    # pic = Picture(image=img_obj)
    if img_type in Config.ALLOWED_IMAGE:
        try:
            file_MD5 = hashlib.md5(img_obj.read()).hexdigest()
            img_url = Config.SITE + file_MD5
            pic = Picture.objects(img_md5=file_MD5).first()
            if pic:
                return jsonReturn.trueReturn({'imgId': str(pic.id)},
                                             '该文件已经存在了')
            img_obj.seek(0)  # 前面计算 md5 的时候已经 read() 一次了,这里要再读取一次,需要把游标归 0
            # 保存图片到 mongodb 的 picture 中
            pic = Picture(img_md5=file_MD5, url=img_url, openid=open_id)
            pic.image.put(img_obj)
            pic.save()
            return jsonReturn.trueReturn({'imgId': str(pic.id)}, '上传成功')
        except CosServiceError as e:
            return jsonReturn.falseReturn(e.get_error_msg(), '上传失败')
        except Exception as e:
            return jsonReturn.falseReturn('', '上传失败 ' + str(e))
    else:
        return jsonReturn.falseReturn(request.path,
                                      '格式不对,仅支持: ' + str(Config.ALLOWED_IMAGE))
示例#6
0
def get_double_fold():
    req_json = request.json
    if not req_json:
        return jsonReturn.falseReturn(request.path, '请传必要参数')
    origin_img_id = req_json.get('originImgId')
    open_id = req_json.get('openId')
    if not all([origin_img_id is not None, open_id is not None]):
        return jsonReturn.falseReturn(request.path, '请传必要参数')
    pic = Picture.objects(openid=open_id,
                          origin_image_id=origin_img_id).first()
    if pic:
        return jsonReturn.trueReturn({'imgId': str(pic.id)}, 'ok')
    else:
        return jsonReturn.falseReturn('', '还没搞好')
示例#7
0
            db.session.commit()
        approval = Approval.query.get(id)
        approval.invoice_count = invoices[1]+invoices_list.length
        approval.save()
        return redirect('/approval/%d' % id)
    
    return render_template('/approval/chioce.html',
                           approvals=invoices[2].offset(offset).limit(per_page),
                           pagination=pagination, content_list = [invoices[0],invoices[1]]
                           )
    
=======
        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'添加审批单')

>>>>>>> 797deb1d9a238a9098207cfc01bab6963414987f
@approval.route('/<int:id>/edit', methods=['POST', 'GET'])
def approval_edit(id):