예제 #1
0
def shopAddOK(request):
    if request.method == 'GET':
        return HttpResponse("参数非法")
    admintel = request.POST.get('admintel')
    if request.method == 'GET':
        return HttpResponse("no files for upload!")
    randomFileName = getRandomFileName() + '.jpg'
    name = request.POST.get('name')
    info = request.POST.get('info')
    addr = request.POST.get('addr')
    tel1 = request.POST.get('tel1')
    tel2 = request.POST.get('tel2')
    tel3 = request.POST.get('tel3')
    lng = request.POST.get('lng')
    lat = request.POST.get('lat')
    shop_type1_obj = shop_type1.objects.get(id=1)
    shop_type2_id = request.POST.get('shop_type2')
    shop_type2_obj = shop_type2.objects.get(id=shop_type2_id)
    shop_type3_id = request.POST.get('shop_type3')
    shop_type3_obj = shop_type3.objects.get(id=shop_type3_id)
    headimg = request.FILES.get("headimg", None)
    # print(name, info, addr, tel1, tel2, tel3, lng, lat, shop_type2_id, shop_type3_id)
    # 存入headimg
    fullName = "/home/rcproject/qypt/static/upload/shopimg/logo/" + randomFileName
    destination = open(
        os.path.join("/home/rcproject/qypt/static/upload/shopimg/logo/",
                     randomFileName), 'wb+')  # 打开特定的文件进行二进制的写操作

    for chunk in headimg.chunks():
        destination.write(chunk)
    destination.close()
    imgurl = "logo/" + randomFileName
    newshopimg = shopimg(imgurl=imgurl)
    newshopimg.save()
    headimgid = newshopimg.id
    print(11223)
    newshop = shop(name=name,
                   admintel=admintel,
                   info=info,
                   addr=addr,
                   tel1=tel1,
                   tel2=tel2,
                   tel3=tel3,
                   headimg=headimgid,
                   lng=lng,
                   lat=lat,
                   shop_type1=shop_type1_obj,
                   shop_type2=shop_type2_obj,
                   shop_type3=shop_type3_obj,
                   is_active=1)
    newshop.save()
    currentShopImg = shopimg.objects.get(id=headimgid)
    currentShopImg.shop = newshop
    currentShopImg.save()

    fnCompressPic("", fullName)
    # image_url = models.URLField()
    # return render(request, 'Xadmin/shop-list.html')
    return redirect('/qypt/closeSavePage')
예제 #2
0
def uploadOK(request):
    if request.method == 'GET':
        return HttpResponse("参数非法")
    myFile = request.FILES.get("myfile", None)  # 获取上传的文件,如果没有文件,则默认为None
    if not myFile:
        return HttpResponse("no files for upload!")
    randomFileName = getRandomFileName() + ".jpg"
    destination = open(os.path.join("/home/rcproject/upload/logo/", randomFileName), 'wb+')  # 打开特定的文件进行二进制的写操作
    for chunk in myFile.chunks():  # 分块写入文件
        destination.write(chunk)
    destination.close()
    imgurl = "logo/" + randomFileName
    newshopimg = shopimg(imgurl=imgurl)
    newshopimg.save()
    return HttpResponse(newshopimg.id)
예제 #3
0
def shopEditOK(request):
    if request.method == 'GET':
        return HttpResponse("参数非法")
    admintel = request.POST.get('admintel')
    shopid = request.POST.get('shopid')
    # 如果isImgChanged=0,则代表店铺头图没有变化
    isImgChanged = request.POST.get('isImgChanged')
    if request.method == 'GET':
        return HttpResponse("no files for upload!")
    name = request.POST.get('name')
    info = request.POST.get('info')
    addr = request.POST.get('addr')
    tel1 = request.POST.get('tel1')
    tel2 = request.POST.get('tel2')
    tel3 = request.POST.get('tel3')
    lat = request.POST.get('lat')
    lng = request.POST.get('lng')
    shop_type1_obj = shop_type1.objects.get(id=1)
    shop_type2_id = request.POST.get('shop_type2')
    shop_type2_obj = shop_type2.objects.get(id=shop_type2_id)
    shop_type3_id = request.POST.get('shop_type3')
    shop_type3_obj = shop_type3.objects.get(id=shop_type3_id)
    headimg = request.FILES.get("headimg", None)
    #如果头图有变化则更新图片
    if int(isImgChanged) > 0:
        # 存入headimg
        filePath = "/home/rcproject/qypt/static/upload/shopimg/logo/"
        randomFileName = getRandomFileName() + '.jpg'
        destination = open(os.path.join(filePath, randomFileName),
                           'wb+')  # 打开特定的文件进行二进制的写操作
        for chunk in headimg.chunks():
            destination.write(chunk)
        destination.close()
        imgurl = "logo/" + randomFileName
        newshopimg = shopimg(imgurl=imgurl)
        newshopimg.save()
        headimg = newshopimg.id
        # 存入完成
        shop.objects.filter(id=shopid).update(name=name,
                                              admintel=admintel,
                                              info=info,
                                              addr=addr,
                                              tel1=tel1,
                                              tel2=tel2,
                                              tel3=tel3,
                                              headimg=headimg,
                                              lng=lng,
                                              lat=lat,
                                              shop_type1=shop_type1_obj,
                                              shop_type2=shop_type2_obj,
                                              shop_type3=shop_type3_obj)
        fnCompressPic(filePath, randomFileName)
    #否则不更新头图
    else:
        shop.objects.filter(id=shopid).update(name=name,
                                              admintel=admintel,
                                              info=info,
                                              addr=addr,
                                              tel1=tel1,
                                              tel2=tel2,
                                              tel3=tel3,
                                              lng=lng,
                                              lat=lat,
                                              shop_type1=shop_type1_obj,
                                              shop_type2=shop_type2_obj,
                                              shop_type3=shop_type3_obj)
    return redirect('/qypt/closeUpdatePage')
예제 #4
0
def shopAddOK(request):
    if request.method == 'GET':
        return HttpResponse("参数非法")
    admintel = request.POST.get('admintel')
    if request.method == 'GET':
        return HttpResponse("no files for upload!")
    # 随机文件名
    randomFileName = getRandomFileName() + '.jpg'
    name = request.POST.get('name')
    info = request.POST.get('info')
    addr = request.POST.get('addr')
    tel1 = request.POST.get('tel1')
    tel2 = request.POST.get('tel2')
    tel3 = request.POST.get('tel3')
    lng = request.POST.get('lng')
    lat = request.POST.get('lat')
    shop_type1_obj = shop_type1.objects.get(id=1)
    shop_type2_id = request.POST.get('shop_type2')
    shop_type2_obj = shop_type2.objects.get(id=shop_type2_id)
    shop_type3_id = request.POST.get('shop_type3')
    shop_type3_obj = shop_type3.objects.get(id=shop_type3_id)
    headimg = request.FILES.get("headimg", None)
    # 存入headimg
    cloudPath = 'shopimg/logo/"+randomFileName'
    fullName = filePath = "/home/rcproject/qypt/static/upload/shopimg/logo/" + randomFileName
    destination = open(
        os.path.join("/home/rcproject/qypt/static/upload/shopimg/logo/",
                     randomFileName), 'wb+')  # 打开特定的文件进行二进制的写操作

    for chunk in headimg.chunks():
        destination.write(chunk)
    destination.close()
    imgurl = "logo/" + randomFileName
    newshopimg = shopimg(imgurl=imgurl)
    newshopimg.save()
    headimgid = newshopimg.id
    newshop = shop(name=name,
                   admintel=admintel,
                   info=info,
                   addr=addr,
                   tel1=tel1,
                   tel2=tel2,
                   tel3=tel3,
                   headimg=headimgid,
                   lng=lng,
                   lat=lat,
                   shop_type1=shop_type1_obj,
                   shop_type2=shop_type2_obj,
                   shop_type3=shop_type3_obj,
                   is_active=1)
    newshop.save()
    shopid = newshop.id
    currentShopImg = shopimg.objects.get(id=headimgid)
    currentShopImg.shop = newshop
    currentShopImg.save()
    # 压缩图片
    fnCompressPic("", fullName)

    query = '''
        db.collection("qypt_shop").add({
            data:{
                name:'%s',
                info:'%s',
                addr:'%s',
                tel1:'%s',
                tel2:'%s',
                tel3:'%s',
                location: new db.Geo.Point(%f, %f),
                shop_type1:%d,
                shop_type2:%d,
                shop_type3:%d,
                randomFileName:'%s',
                is_active:1
            }
        })
    ''' % (name, info, addr, tel1, tel2, tel3, float(lng), float(lat), 1,
           int(shop_type2_id), int(shop_type3_id), randomFileName)
    operation = {"env": 'qypt-test-p2p0k', "query": query}
    #获取云数据库的id
    cloud_id = fnWxCloundDbAddData(operation)
    shop.objects.filter(id=shopid).update(cloud_id=cloud_id)
    return redirect('/qypt/closeSavePage')