Esempio n. 1
0
def Message_add():
    form = OrganizationMessageForm()
    if request.method == 'POST':
        writer_id = form.writer_id.data
        # token = form.token.data
        temp = WxUser.query.filter_by(id=writer_id).first()  #
        rdSession = form.rdSession.data  #
        # if certify_token(writer_id, token):
        if certify_rdSession(temp.openid, temp.session_key, rdSession):  #
            title = form.title.data
            activeTime = form.activeTime.data
            content = form.content.data
            attachment = form.attachment.data
            createTime = local_time()
            image = form.images.data
            img_url = upload_image(image)
            if writer_id and content:
                try:
                    new_organizationMessage = OrganizationMessage(title=title, createTime=createTime, activeTime=activeTime,
                                                                  state=1, content=content, image=img_url, agreeNum=0,
                                                                  attachment=attachment, commentNum=0, writer_id=writer_id)
                    db.session.add(new_organizationMessage)
                    db.session.commit()
                    return '上传成功'
                except Exception as e:
                    print(e)
                    flash('添加组织发布信息失败')
                    db.session.rollback()
                    return '添加失败'
            else:
                return '参数出错'
        else:
            return '登录超时'

    return render_template('upload.html', form=form)
Esempio n. 2
0
def Comment_add():
    form = GoodsCommentForm()
    if request.method == 'POST':
        writer_id = form.writer_id.data
        # token = form.token.data
        temp = WxUser.query.filter_by(id=writer_id).first()  #
        rdSession = form.rdSession.data  #
        # if certify_token(writer_id, token):
        if certify_rdSession(temp.openid, temp.session_key, rdSession):  #
            createTime = local_time()
            content = form.content.data
            replied_id = form.replied_id.data
            goods_id = form.goods_id.data
            if content and replied_id and goods_id:
                try:
                    new_goodsComment = GoodsComment(state=1, createTime=createTime, content=content,
                                                              writer_id=writer_id, replied_id=replied_id,
                                                              goods_id=goods_id)
                    db.session.add(new_goodsComment)
                    db.session.commit()
                    goods = Goods.query.filter_by(id=goods_id).first()  # 评论数+1
                    goods.commentNum += 1
                    db.session.commit()
                    return '上传成功'
                except Exception as e:
                    print(e)
                    flash('添加物品评论失败')
                    db.session.rollback()
                    return '添加失败'
            else:
                return '参数出错'
        else:
            return '登录超时'

    return render_template('upload.html', form=form)
Esempio n. 3
0
def Wxupdate():
    form = WxUpdateForm()
    if request.method == 'POST':
        id = form.id.data
        temp = WxUser.query.filter_by(id=id).first()
        rdSession = form.rdSession.data  #
        if certify_rdSession(temp.openid, temp.session_key, rdSession):
            name = form.name.data
            image = form.image.data
            city = form.city.data
            country = form.country.data
            gender = form.gender.data
            language = form.language.data
            province = form.province.data
            try:
                userinfo = WxUser.query.filter_by(id=id).first()
                userinfo.name = name
                userinfo.image = image
                userinfo.city = city
                userinfo.country = country
                userinfo.gender = gender
                userinfo.language = language
                userinfo.province = province
                db.session.commit()
                return '更新成功'
            except Exception as e:
                print(e)
                return '更新失败'
        else:
            return '登录超时'
    return render_template('upload.html', form=form)
Esempio n. 4
0
def Add():
    form = GoodsForm()
    if request.method == 'POST':
        writer_id = form.writer_id.data
        # token = form.token.data
        temp = WxUser.query.filter_by(id=writer_id).first()  #
        rdSession = form.rdSession.data  #
        # if certify_token(writer_id, token):
        if certify_rdSession(temp.openid, temp.session_key, rdSession):  #
            name = form.name.data
            price = form.price.data
            content = form.content.data
            phone = form.phone.data
            wechat = form.wechat.data
            email = form.email.data
            type = form.type.data
            createTime = local_time()
            state = 1
            commentNum = 0
            image = form.images.data
            img_url = upload_image(image)
            if name and price and content and type:
                try:
                    new_goods = Goods(name=name, createTime=createTime, state=state, price=price, content=content,
                                      image=img_url, phone=phone, wechat=wechat, email=email, commentNum=commentNum,
                                      writer_id=writer_id, type=type)

                    db.session.add(new_goods)
                    db.session.commit()
                    return '上传成功'
                except Exception as e:
                    print(e)
                    flash('添加商品失败')
                    db.session.rollback()
                    return '添加失败'
            else:
                return '参数出错'
        else:
            return '登录超时'

    return render_template('upload.html', form=form)