def same_delete_url(request): # 判断请求方法为post if request.method == "POST": # 获取表单传过来的URL image_url = request.POST.get("URL") # 定义一个相同图对象 sp = SamePic() sp.url = image_url # 本地图片更新 data = sp.delete(1) # 判断是否是返回错误信息 if 'error_msg' in data.keys(): return render(request, "admin-same.html", { "error_msg": data['error_msg'], "sign": 0 }) else: return render(request, 'admin-same.html', {"sign": 1})
def same_delete(request): # 判断请求方法为post if request.method == "POST": # 获取表单传过来的图片 image = request.FILES.get("image") # 定义一个相同图对象 sp = SamePic() sp.image = image.file.getvalue() # 本地图片更新 data = sp.delete(0) # 判断是否是返回错误信息 if 'error_msg' in data.keys(): return render(request, "admin-same.html", { "error_msg": data['error_msg'], "sign": 0 }) else: return render(request, 'admin-same.html', {"sign": 1})
def same_put_in_url(request): if request.method == "POST": # 获取表单传过来的网络地址 image_url = request.POST.get("URL") # 获取表单传过来的图片类型 category = request.POST.get("category", None) if samePicCategoryDict.get(category): category_id = samePicCategoryDict[category] else: category_id = samePicCategoryDict["other"] # 获取图片名称 image_name = request.POST.get("name", None) # 定义一个相同图对象 sp = SamePic() sp.url = image_url # 给图片增加描述 sp.options[ "brief"] = "{\"name\":\"" + image_name + "\", \"url\":\"" + image_url + "\"}" # 给图片增加类型 sp.options["tags"] = category_id # 有图片描述的本地图片入库 data = sp.putIn(3) # 判断是否是返回错误信息 if 'error_msg' in data.keys(): return render(request, "admin-same-url.html", { "error_msg": data['error_msg'], "sign": 0 }) else: return render(request, 'admin-same-url.html', {"sign": 1})
def same_update_url(request): # 判断请求方法为post if request.method == "POST": # 获取表单传过来的URL image_url = request.POST.get("URL") # 获取表单传过来的图片类型 category = request.POST.get("category", None) if samePicCategoryDict.get(category): category_id = samePicCategoryDict[category] else: category_id = samePicCategoryDict["other"] if category: # 定义一个相同图对象 sp = SamePic() sp.url = image_url # 可选参数 # sp.options["brief"] = "{\"name\":\"周杰伦\", \"id\":\"666\"}" sp.options["tags"] = category_id # 本地图片更新 data = sp.update(3) # 判断是否是返回错误信息 if 'error_msg' in data.keys(): return render(request, "admin-same.html", { "error_msg": data['error_msg'], "sign": 0 }) else: return render(request, 'admin-same.html', {"sign": 1}) else: # 定义一个相同图对象 sp = SamePic() sp.url = image_url # 本地图片更新 data = sp.update(2) # 判断是否是返回错误信息 if 'error_msg' in data.keys(): return render(request, "admin-same.html", { "error_msg": data['error_msg'], "sign": 0 }) else: return render(request, 'admin-same.html', {"sign": 1})
def same_put_in(request): if request.method == "POST": # 获取表单传过来的图片 image = request.FILES.get("image") # 获取表单传过来的图片类型 category = request.POST.get("category", "other") if samePicCategoryDict.get(category): category_id = samePicCategoryDict[category] else: category_id = samePicCategoryDict["other"] filePath = '/assets/img/same/' + image.name # 将图片保存到img目录下面 filePath1 = 'assets/img/same/' + image.name f = open(filePath1, 'wb') f.write(image.file.getvalue()) f.close() # 定义一个相同图对象 sp = SamePic() sp.image = get_file_content(filePath1) # 文件名 (filename, extension) = os.path.splitext(image.name) # 给图片增加描述 sp.options[ "brief"] = "{\"name\":\"" + filename + "\", \"url\":\"" + filePath + "\"}" # 给图片增加类型 sp.options["tags"] = category_id # 有图片描述的本地图片入库 data = sp.putIn(1) # 判断是否是返回错误信息 if 'error_msg' in data.keys(): return render(request, "admin-same.html", { "error_msg": data['error_msg'], "sign": 0 }) else: return render(request, 'admin-same.html', {"sign": 1})
def same_check_url(request): # 判断请求方法为post if request.method == "POST": # 获取表单传过来的网络地址 image_url = request.POST.get("URL") # 获取表单传过来的图片类型 category = request.POST.get("category", None) if samePicCategoryDict.get(category): category_id = samePicCategoryDict[category] else: category_id = samePicCategoryDict["other"] if category: # 定义一个相同图对象 sp = SamePic() sp.url = image_url # 设置可选参数 sp.options["tags"] = category_id sp.options["tag_logic"] = "0" sp.options["pn"] = "0" sp.options["rn"] = "1000" # 本地图片检索 data = sp.check(3) # 将字符串转为字典 for image in data['result']: print(image['brief']) image['brief'] = json.loads(image['brief']) # 判断是否是返回错误信息 if 'error_msg' in data.keys(): return render(request, "admin-same.html", { "error_msg": data['error_msg'], "sign": 0 }) else: return render(request, "admin-gallery.html", {"data": data}) else: # 定义一个相同图对象 sp = SamePic() sp.url = image_url # 本地图片检索 data = sp.check(2) # 将字符串转为字典 for image in data['result']: print("hello", image['brief']) image['brief'] = json.loads(image['brief']) # 判断是否是返回错误信息 if 'error_msg' in data.keys(): return render(request, "admin-same.html", { "error_msg": data['error_msg'], "sign": 0 }) else: return render(request, "admin-gallery.html", {"data": data})