示例#1
0
文件: views.py 项目: qutlyk/xlhw
def add_goods(request):
    if request.method == 'GET':
        return render_to_response('add_goods.html', {
            'request': request,
            'title': '添加商品',
            'header': '添加商品'
        })
    elif request.method == 'POST':
        user = request.user
        goodsname = request.POST['goodsname']
        price = request.POST['price']
        goodstype = request.POST['goodstype']
        goods = Goods(name=goodsname,
                      price=price,
                      goods_type=goodstype,
                      add_people=user)
        goods.save()
        shops = Shop.objects.all()
        for shop in shops:
            goodsshop = GoodsShop(goods=goods,
                                  shop=shop,
                                  remain=0,
                                  last_updater=user)
            goodsshop.save()
        return HttpResponseRedirect(reverse('addsuccess'))
示例#2
0
def db_add(request):
    goods = Goods(name="pumeloes")
    goods.price = '12.3'
    goods.barcode = '123456789'
    goods.package = 'box'
    goods.level = 'one'
    goods.origin = 'china'
    goods.unit = '500g'
    goods.save()
    return HttpResponse("success")
示例#3
0
def save_model():
    for supplier in supplier_list:
        supplier_obj = Supplier()
        supplier_obj.name = supplier["name"]
        supplier_obj.address = supplier["address"]
        supplier_obj.phone = supplier["phone"]
        supplier_obj.save()

    for record in goods_list:
        good = Goods(**record)
        good.save()

    pass
    def addGoods(self):
        # image = self.image
        image_filename = 'user' + self.image.filename
        image_path = 'http://' + ip_address + 'img/' + image_filename

        newGood = Goods(
            category=self.formDict.get('category'),
            name=self.formDict.get('name'),
            word_description=self.formDict.get('word_description'),
            image=image_path,
            price=self.formDict.get('price'),
            remaining=self.formDict.get('remaining')
        )
        db.session.add(newGood)
        db.session.commit()
        # 提交后没问题再进行保存图片
        self.image.save('./static/img/' + image_filename)
        result = {'code':200}
        return jsonify(result)
示例#5
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)
示例#6
0
def goods_insert():
    """Goods Insert"""

    products = (
        ('제품1', 30000, 'wenyang-x700.jpg', 10, 3, '제품1에 대한 설명이 여기에 들어옵니다'),
        ('제품2', 33000, 'tamara-bellis-x700.jpg', 10, 5, '제품2에 대한 설명이 여기에 들어옵니다'),
        ('제품3', 35000, 'roland-denes-x700.jpg', 10, 1, '제품3에 대한 설명이 여기에 들어옵니다'),
        ('제품4', 33000, 'raamin-ka-x700.jpg', 10, 2, '제품4에 대한 설명이 여기에 들어옵니다'),
        ('제품5', 31000, 'oliver-johnson-x700.jpg', 10, 5, '제품5에 대한 설명이 여기에 들어옵니다'),
        ('제품6', 36000, 'taisiia-stupak-x700.jpg', 10, 4, '제품6에 대한 설명이 여기에 들어옵니다')
    )

    for item in products:
        goods = Goods()
        goods.goods_name = item[0]
        goods.price = item[1]
        goods.goods_photo = item[2]
        goods.goods_cnt = item[3]
        goods.goods_ranking = item[4]
        goods.goods_description = item[5]

        db_session.add(goods)
    
    db_session.commit()
示例#7
0
 def get_goods_by_type(self, type):
     url = self.goods_list_url.format(cids=type, page=1)
     for page in range(1, self.get_max_page(url) + 1):
         html = self.get(self.goods_list_url.format(cids=type, page=page))
         html.encoding = 'utf-8'
         html = html.text
         soup = BeautifulSoup(html, parser)
         items = soup.find_all('li', class_='item')
         goods = []
         for i in items:
             count = int(re.search(r'提供([0-9]*)份', i.text).group(1))
             cid = int(i.attrs['activity_id'])
             endt = int(i.attrs['end_time'])
             skuid = i.attrs['sku_id']
             name = i.find('div', class_='p-name').text
             good = Goods(cid=cid,
                          name=name,
                          count=count,
                          endt=endt,
                          skuid=skuid)
             goods.append(good)
         self.get_money_by_skuids(goods)
         yield goods
         time.sleep(0.3)
示例#8
0
def modifyInfo():
    if request.method == 'GET':
        status = 0
        return render_template('user_page.html', status=status)
    else:
        user_account = session.get('user_account')
        user = Users.query.filter(Users.account == user_account).first()
        way = request.form.get('way')
        if way == 'password':
            password = request.form.get('password').strip()
            password1 = request.form.get('password1').strip()
            password2 = request.form.get('password2').strip()
            if (password == '') or (password1 == '') or (password2 == ''):
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='Somthing empty',
                                       message='Please input password again!')
            elif user.password != password:
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='old password wrong',
                                       message='Please input it again!')
            elif password1 != password2:
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='passwords doesn\'t match',
                                       message='Please input it again!')
            else:
                user.password = password1
                db.session.commit()
                session.clear()
                status = 1
                return render_template('user_page.html',
                                       color='success',
                                       status=status,
                                       alert='Modify seccussfully',
                                       message='Please login again!')
        elif way == 'address':
            address = request.form.get('address').strip()
            if address == '':
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='New address is empty',
                                       message='Please input it again!')
            else:
                user.address = address
                db.session.commit()
                status = 1
                return render_template('user_page.html',
                                       color='success',
                                       status=status,
                                       alert='Modify address successfully')
        elif way == 'Alia':
            alia = request.form.get('alia')
            alia1 = request.form.get('alia1')
            if (alia == '') or (alia1 == ''):
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='Something empty!')
            elif alia != user.name:
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='Old name is wrong!!',
                                       message='Please input it again.')
            else:
                check_user = Users.query.filter(Users.name == alia1).first()
                # check whether the name has already in the database
                if check_user:
                    status = 1
                    return render_template('user_page.html',
                                           status=status,
                                           alert='The name already existed!!',
                                           message='Please change a name.')
                else:
                    user.name = alia1
                    db.session.commit()
                    status = 1
                    return render_template(
                        'user_page.html',
                        status=status,
                        color='success',
                        alert='name modify successfully',
                        message='Please check it in the user info tab.')
        elif way == 'class':
            selected_good = request.form.get('good_name')
            class_name = request.form.get('good_class')
            # print(selected_good + '   ' + class_name)
            # Firstly, we add a new class if it didn't exist
            check_exist = Goods_class.query.filter(
                Goods_class.class_name == class_name).first()
            # Then get the data of the selected good
            good = Goods.query.filter(Goods.id == selected_good).first()
            if check_exist:
                class_id = check_exist.class_id
                good.class_id = class_id
                db.session.commit()
            else:
                # Add new class
                new_class = Goods_class(class_name=class_name)
                db.session.add(new_class)
                db.session.commit()
                # Modify the good's class
                good.class_id = Goods_class.query.filter(
                    Goods_class.class_name == class_name).first().class_id
                db.session.commit()
            return render_template('user_page.html',
                                   status=1,
                                   color='success',
                                   alert='Add class successfully。')
        elif way == 'add_good':
            good_name = request.form.get('good_name')
            good_desc = request.form.get('good_desc')
            good_price = request.form.get('good_price')
            picture_url = request.form.get('picture_url')
            new_good = Goods(good_name=good_name,
                             good_desc=good_desc,
                             good_price=good_price,
                             picture_url=picture_url)
            db.session.add(new_good)
            db.session.commit()
            return render_template('user_page.html',
                                   status=1,
                                   color='success',
                                   alert='Add good successfully。')
示例#9
0
    def regSupplierCotrl(self, request):
        try:
            supplier_name = request.form['supplier_name']
            supplier_companyname = request.form['supplier_companyname']
            supplier_cin = request.form['supplier_cin']
            supplier_address = request.form['supplier_address']
            supplier_country = request.form.get('country')
            country = supplier_country.split("_")[0]
            isd = supplier_country.split("_")[1]
            #print supplier_country
            supplier_state = request.form.get('state')
            supplier_city = request.form.get('city')
            supplier_town = request.form['supplier_town']
            supplier_pin = request.form['supplier_pin']
            supplier_phone = request.form['supplier_phone']
            supplier_mail = request.form['supplier_mail']
            supplier_gstin = request.form['supplier_gstin']
            supplier_pan = request.form['supplier_pan']
            supplier_brand = request.form.getlist('brand')
            supplier_tm = request.form.getlist('supplier_tm')
            supplier_contactname = request.form['supplier_contactname']
            supplier_mobile = request.form['supplier_mobile']
            supplier_email = request.form['supplier_email']
            #iscompanyExist=Reg_Supplier.objects(supplier_companyname=supplier_companyname)
            #iscinExist=Reg_Supplier.objects(supplier_cin=supplier_cin)
            #isgstinExist=Reg_Supplier.objects(supplier_gstin=supplier_gstin)
            #ispanExist=Reg_Supplier.objects(supplier_pan=supplier_pan)
            '''if iscompanyExist.count()>0:
                return  'Fail'
            elif iscinExist.count()>0:
                 return  'Fail'
            elif isgstinExist.count()>0:
                 return  'Fail'
            elif ispanExist.count()>0:
                 return  'Fail'''
            #return isd
            supplierUser = Reg_Supplier(
                user_id=str(current_user.id),
                supplier_name=supplier_name,
                supplier_companyname=supplier_companyname,
                supplier_cin=supplier_cin,
                supplier_address=supplier_address,
                supplier_country=country,
                supplier_state=supplier_state,
                supplier_city=supplier_city,
                supplier_town=supplier_town,
                supplier_pin=supplier_pin,
                supplier_isd=isd,
                supplier_phone=supplier_phone,
                supplier_mail=supplier_mail.lower(),
                supplier_gstin=supplier_gstin,
                supplier_pan=supplier_pan,
                supplier_contactname=supplier_contactname,
                supplier_mobile=supplier_mobile,
                supplier_email=supplier_email.lower(),
                supplier_id='0')  # Insert form data in collection

            supplierUser.save()
            for x in range(len(supplier_brand)):
                goods = Goods(supplier_brand[x], supplier_tm[x])
                supplierUser.supplier_brands.append(goods)
                supplierUser.save()

            user = UserSignup.objects.get(id=current_user.id)
            user.status = 'Review'
            user.save()
            return str("Success")
        except Exception as e:
            return str("Fail")
示例#10
0
    db.session.commit()

    # 7.二手交易
    # 物品分类
    GC1 = GoodsC(name='生活用品')
    GC2 = GoodsC(name='学习用品')
    GC3 = GoodsC(name='饮食用品')
    GC4 = GoodsC(name='娱乐用品')
    db.session.add_all([GC1, GC2, GC3, GC4])
    db.session.commit()
    # 物品
    goods1 = Goods(name='音响',
                   createTime=local_time(),
                   state=1,
                   price=999,
                   content='音响',
                   phone='10086',
                   commentNum=1,
                   type='生活用品',
                   writer_id=UI1.id)
    goods2 = Goods(name='高数',
                   createTime=local_time(),
                   state=1,
                   price=999,
                   content='高数',
                   phone='10086',
                   commentNum=1,
                   type='学习用品',
                   writer_id=UI2.id)
    goods3 = Goods(name='筷子',
                   createTime=local_time(),