Exemplo n.º 1
0
def addGoods(request):
    goods = Goods()
    goods.g_name = 'iphone-' + str(random.randrange(1, 20))
    goods.g_price = random.randrange(9999, 20000)
    goods.save()

    return HttpResponse('添加商品成功: ' + goods.g_name)
Exemplo n.º 2
0
def bianji(request):
    if request.method == 'POST':
        goods = Goods()
        str1 = str(time.time())
        time1 = str1.split('.')[0]


        goods.childcid = request.POST.get('childcid')

        goods.productname = request.POST.get('productname')
        goods.productlongname = request.POST.get('productlongname')
        goods.categoryid = request.POST.get('categoryid')
        goods.childcidname ='x'
        print()
        # 头像
        imgName = time1+'.png'
        imgPath = os.path.join(settings.IMG_ROOT, imgName)
        print(imgPath)
        file = request.FILES.get('file')
        print(file)


        if file == None:
            imgName = 'axf.png'
        else:
            with open(imgPath, 'wb') as fp:
                for data in file.chunks():
                    fp.write(data)
        goods.productimg = 'http://127.0.0.1:8000/static/market/img/'+imgName
        goods.save()
        # 重定向
        return redirect('axf:home')

    elif request.method == 'GET':
        return render(request, 'market/bianji.html')
Exemplo n.º 3
0
def index(request):

    for i in range(1,8):
        wheels=Wheel()
        wheels.name='goodsbanner-'+str(i)+'.jpg'
        wheels.img='img/'+wheels.name
        wheels.save()

        goods=Goods()
        goods.name='goodsbanner-'+str(i)+'.jpg'
        goods.img='img/'+goods.name
        goods.price=100*i
        goods.store_num=10*i
        goods.save()


    goods = Goods.objects.all()[1:5]
    wheels = Wheel.objects.all()
    tuijians = Tuijian.objects.all()
    token = request.session.get('token')

    userid = cache.get(token)

    if userid:

        user = User.objects.get(pk=userid)

        return render(request, 'index.html',
                      context={'wheels': wheels, 'tuijians': tuijians, 'user': user, 'token': token, 'goods': goods})
    else:
        return render(request, 'index.html', context={'wheels': wheels, 'tuijians': tuijians, 'goods': goods})
Exemplo n.º 4
0
def addgoods(request):
    goods = Goods()
    names = ['小米', '锤子', '红米', 'oppo', '华为', '魅族', '魅蓝']
    temp = random.randrange(0, len(names))
    goods.g_name = names[temp] + '-' + str(random.randrange(10, 100))
    goods.g_price = random.randrange(100, 1000)
    goods.save()
    return HttpResponse('添加商品成功')
Exemplo n.º 5
0
def addgoods(request):
    goods = Goods()
    arr = ['iPhone', 'iPad', 'iPod', 'MacBook Pro', 'MacBook Air']
    temp = random.randrange(0, len(arr))
    goods.g_name = arr[temp] + '-' + str(random.randrange(0, 10))
    goods.g_price = random.randrange(10000, 100000)
    goods.save()

    return HttpResponse('添加商品成功')
Exemplo n.º 6
0
 def post(self):
     # g_name = request.form.get('g_name')
     # g_price = request.form.get('g_price') # 使用request.form获取的参数无校验功能
     args = parser.parse_args()
     g_name = args.get('g_name')
     g_price = args.get('g_price')
     print(args.get('mu'))  # 当该参数设置了append的action后get到的就是一个list
     print(args.get('User-Agent'))
     goods = Goods()
     goods.g_name = g_name
     goods.g_price = g_price
     if not goods.save():
         abort(400)
     # data = {
     #     'status': 200,
     #     'msg': 'create success',
     #     'data': marshal(goods, good_fields),
     # }
     data = {
         'status': 200,
         'msg': 'create success',
         'data': goods,
         # 'test': 'haha' # 如果这个字段在fields中没有,则最后返回的结果会被忽略这个字段的内容
     }
     return data
    def post(self):
        # g_name=request.form.get('g_name')
        # g_price=request.form.get('g_price')
        args = parser.parse_args()
        g_name = args.get('g_name')
        g_price = args.get('g_price')

        goods = Goods()
        goods.g_name = g_name
        goods.g_price = g_price
        if not goods.save():
            abort(404)

        data = {"msg": "create success", "status": 201, "data": goods}
        return data
Exemplo n.º 8
0
def goodsup(request):
    token = request.session.get('token')
    userid = cache.get(token)
    if userid:
        user = User.objects.get(pk=userid)

        if request.method == 'GET':
            return render(request, 'mine/goodsup.html')
        elif request.method == 'POST':
            goods = Goods()
            goodsname = request.POST.get('goodsname')
            price = request.POST.get('price')
            title = request.POST.get('title')
            num = request.POST.get('num')
            type = request.POST.get('type')
            file = request.FILES['file']
            file.name = str(time.time()) + str(file.name)
            filepath = os.path.join(settings.GOODSIMG_ROOT, file.name)
            with open(filepath, 'wb') as fp:
                for info in file.chunks():
                    fp.write(info)
            goods.img = 'img/' + file.name
            goods.bigimg = 'img/' + file.name
            goods.name = goodsname
            goods.price = "¥" + price
            goods.num = num
            goods.title = title
            goods.fatherid = type
            goods.save()
            publish = Publish()
            publish.goods = goods
            publish.user = user
            publish.save()
            return redirect('app:index')
    else:
        return redirect('app:login')