Example #1
0
def applying_designer(request):
    """
    * description : goods,user,customer的保存 customer的状态变为A
    * param       :
    * return      : 提交成功/提交失败  字段
    """
    user = request.user
    if request.method == "POST":
        # POST ICON
        img_path = ""
        img_file = None
        sys_info = platform.system()
        icon_data = request.POST["icon_data"]
        icon_data = icon_data[icon_data.find(",") + 1 :]
        # Mac OS
        if sys_info == "Darwin":
            if os.path.isdir(r"/tmp/jk_temp") == False:
                os.makedirs(r"/tmp/jk_temp")
            img_path = r"/tmp/jk_temp/tem_img.png"
            if os.path.isfile(img_path):
                os.remove(img_path)
            img_file = open(img_path, "wb")
        # Windows
        elif sys_info == "Windows":
            if os.path.isdir(r"c:/jk_temp") == False:
                os.makedirs(r"c:/jk_temp")
            img_path = r"c:/jk_temp/tem_img.png"
            if os.path.isfile(img_path):
                os.remove(img_path)
            img_file = open(img_path, "wb")
        elif sys_info == "Linux":
            if os.path.isdir(r"/tmp/jk_temp") == False:
                os.makedirs(r"/tmp/jk_temp")
            img_path = r"/tmp/jk_temp/tem_img.png"
            if os.path.isfile(img_path):
                os.remove(img_path)
            img_file = open(img_path, "wb")

        try:
            imgData = base64.b64decode(icon_data)
            img_file.write(imgData)
            img_file.close()
        except Exception, e:
            img_file.close()
            print "error applying"

        tmp_file = open(img_path, "rb")
        file_data = {"type": "icon", "rename": "yes"}
        files = {"filedata": tmp_file}
        r = requests.post(adminer_website.upload_file_url, data=file_data, files=files)
        tmp_file.close()
        rs = json.loads(r.text)
        icon = rs.get("src")
        icon = add_str("icon/", icon)
        customer = None
        if icon != None:
            try:
                customer = Customer.objects.get(user_id=request.user.id)
            except ObjectDoesNotExist:
                return HttpResponse(json.dumps({"state": "FAIL"}))
        else:
            return HttpResponse(json.dumps({"state": "FAIL"}))
        # set param
        realname = request.POST.get("realname", None)
        identify_no = request.POST.get("identify_no", None)
        photo = request.POST.get("photo", None)
        photo = add_str("icon/", photo)
        stl_file = request.POST.get("stl_file", None)
        stl_file = add_str("stl/", stl_file)
        preview_1 = request.POST.get("preview_1", None)
        preview_1 = add_str("goods/", preview_1)
        thumbnail_1 = add_str("goods/", request.POST.get("thumbnail_1", None))
        preview_2 = request.POST.get("preview_2", None)
        preview_2 = add_str("goods/", preview_2)
        thumbnail_2 = add_str("goods/", request.POST.get("thumbnail_2", None))
        preview_3 = request.POST.get("preview_3", None)
        preview_3 = add_str("goods/", preview_3)
        thumbnail_3 = add_str("goods/", request.POST.get("thumbnail_3", None))
        customer.nickname = realname  # change set real name to nickname @minchiuan
        customer.photo = photo
        customer.icon = icon
        customer.identity_tag = identity.applying_designer
        goods = Goods()
        goods.stl_file_url = stl_file
        goods.preview_1 = preview_1
        goods.preview_2 = preview_2
        goods.preview_3 = preview_3
        goods.thumbnail_1 = thumbnail_1
        goods.thumbnail_2 = thumbnail_2
        goods.thumbnail_3 = thumbnail_3
        goods.designer_id = customer.id
        goods.is_published = 0
        goods.name = realname + "APP1214"
        goods.add_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        goods.modified_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        goods.scan_count = 0
        goods.marked_count = 0
        goods.collected_count = 0
        goods.purchased_count = 0
        goods.price = 8
        goods.is_applied = 0
        goods.tags = request.POST["Ptags"]
        goods.material = request.POST["Ctags"]
        goods.type = request.POST["Ztags"]

        if not customer.nickname or not customer.icon:
            return render(request, website.apply_failed)

        try:
            goods.save()
            user.save()
            customer.save()
        except Exception, e:
            print e
            return render(request, website.apply_failed)
Example #2
0
def upload_works(request):
    """
    * description : 上传作品页面
    * param       :
    * return      : upload_work.html
    """
    # 作者信息
    user = request.user
    designer = Customer.objects.get(user_id=user.id)

    context_dict = {}
    # 静态服务器地址
    context_dict["static_server_url"] = adminer_website.upload_file_url
    # 商品图片存放地址
    context_dict["goods_server_path"] = adminer_website.goods_server_path
    if request.method == "POST":
        # 获取参数
        goods = Goods()
        goods.designer_id = designer.id
        goods.name = request.POST.get("title", None)
        goods.tags = request.POST.get("Ptags", None)
        goods.material = request.POST.get("Ctags", None)
        goods.type = request.POST.get("Ztags", None)
        try:
            goods.price = float(request.POST.get("price", 0))
        except Exception as e:
            print e
            goods.price = 0.0

        goods.stl_file_url = add_str("stl/", request.POST.get("stl_file", None))
        goods.preview_1 = add_str("goods/", request.POST.get("preview_1", None))
        goods.thumbnail_1 = add_str("goods/", request.POST.get("thumbnail_1", None))
        goods.preview_2 = add_str("goods/", request.POST.get("preview_2", None))
        goods.thumbnail_2 = add_str("goods/", request.POST.get("thumbnail_2", None))
        goods.preview_3 = add_str("goods/", request.POST.get("preview_3", None))
        goods.thumbnail_3 = add_str("goods/", request.POST.get("thumbnail_3", None))
        goods.describe = request.POST.get("description", None)
        operation = request.POST.get("operate", None)
        if operation == "save":
            goods.is_published = False
        elif operation == "publish":
            goods.is_published = True

        goods.scan_count = 0
        goods.marked_count = 0
        goods.collected_count = 0
        goods.purchased_count = 0
        goods.add_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        goods.modified_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        try:
            goods.save()
            context_dict["result"] = "SUCCESS"
            context_dict["desc"] = "上传作品成功"
        except Exception, e:
            print e
            context_dict["result"] = "ERROR"
            context_dict["desc"] = "上传作品失败"
            return render(request, website.upload_work, context_dict)

        return render(request, website.upload_work, context_dict)