|
@@ -1,7 +1,7 @@
|
|
# -*-coding:utf-8 -*-
|
|
# -*-coding:utf-8 -*-
|
|
import traceback
|
|
import traceback
|
|
from common.common import (get_user_from_request, login_required,
|
|
from common.common import (get_user_from_request, login_required,
|
|
- params,JsonResponse)
|
|
|
|
|
|
+ params,JsonResponse,save_bs64img_local)
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from models import *
|
|
from models import *
|
|
# Create your views here.
|
|
# Create your views here.
|
|
@@ -27,9 +27,9 @@ def content_show(request,offset):
|
|
dict_data["img_url"]=content_data.img_url
|
|
dict_data["img_url"]=content_data.img_url
|
|
dict_data["type"]=content_data.type
|
|
dict_data["type"]=content_data.type
|
|
dict_data["content"]=content_data.content
|
|
dict_data["content"]=content_data.content
|
|
- res = {"code":0,"page_type":offset,"msg":"show sucess!","content_data":dict_data}
|
|
|
|
|
|
+ res = {"code":0,"msg":"show sucess!","content_data":dict_data}
|
|
else:
|
|
else:
|
|
- res = {"code":-1,"page_type":offset,"msg":"show false!",}
|
|
|
|
|
|
+ res = {"code":-1,"msg":"get empty data!",}
|
|
|
|
|
|
return JsonResponse(res)
|
|
return JsonResponse(res)
|
|
|
|
|
|
@@ -76,9 +76,17 @@ def banner_show(request):
|
|
for obj_banner in objs:
|
|
for obj_banner in objs:
|
|
dict_data={}
|
|
dict_data={}
|
|
dict_data["bid"] = obj_banner.id
|
|
dict_data["bid"] = obj_banner.id
|
|
|
|
+ dict_data["position"] = obj_banner.position
|
|
|
|
+ dict_data["img_url"] = obj_banner.img_url
|
|
dict_data["display_title"] = obj_banner.display_title
|
|
dict_data["display_title"] = obj_banner.display_title
|
|
|
|
+ dict_data["article_title"] = obj_banner.article_title
|
|
|
|
+ dict_data["article_url"] = obj_banner.article_url
|
|
|
|
+
|
|
|
|
+ dict_data["author"] = obj_banner.author
|
|
|
|
+ dict_data["content"] = obj_banner.content
|
|
dict_data["create_time"] = obj_banner.create_time
|
|
dict_data["create_time"] = obj_banner.create_time
|
|
- dict_data["position"] = obj_banner.position
|
|
|
|
|
|
+
|
|
|
|
+ # print(obj_banner.img_url)
|
|
data_list.append(dict_data)
|
|
data_list.append(dict_data)
|
|
res = {"code":0,"msg":"get data sucess!","content_data":data_list}
|
|
res = {"code":0,"msg":"get data sucess!","content_data":data_list}
|
|
else:
|
|
else:
|
|
@@ -95,7 +103,7 @@ def banner_add(request):
|
|
req_params = request.PARAMS
|
|
req_params = request.PARAMS
|
|
if req_params:
|
|
if req_params:
|
|
try:
|
|
try:
|
|
- position = req_params.get("position",None)
|
|
|
|
|
|
+ position = req_params.get("position")
|
|
img_url = req_params.get("img_url",None)
|
|
img_url = req_params.get("img_url",None)
|
|
display_title = req_params.get("display_title",None)
|
|
display_title = req_params.get("display_title",None)
|
|
article_url = req_params.get("article_url",None)
|
|
article_url = req_params.get("article_url",None)
|
|
@@ -103,9 +111,18 @@ def banner_add(request):
|
|
author = req_params.get("author",None)
|
|
author = req_params.get("author",None)
|
|
content = req_params.get("content",None)
|
|
content = req_params.get("content",None)
|
|
|
|
|
|
|
|
+ # img_path = save_bs64img_local(img_url)
|
|
|
|
+ # print("banner_edit*****_img_",img_path)
|
|
|
|
+
|
|
|
|
+ if position!=0 and Banner.objects.filter(position=position):
|
|
|
|
+ return JsonResponse({"code": -1, "msg": "横幅位置重复!"})
|
|
|
|
+
|
|
obj= Banner.objects.create(position=position,img_url=img_url,display_title=display_title,
|
|
obj= Banner.objects.create(position=position,img_url=img_url,display_title=display_title,
|
|
article_url=article_url,article_title=article_title,author=author,content=content)
|
|
article_url=article_url,article_title=article_title,author=author,content=content)
|
|
- res = res={"code": 0, "msg": "banner add sucess"}
|
|
|
|
|
|
+ if obj:
|
|
|
|
+ res = {"code": 0, "msg": "banner add sucess"}
|
|
|
|
+ else:
|
|
|
|
+ res = {"code": -1, "msg": "添加失败"}
|
|
except:
|
|
except:
|
|
traceback.print_exc()
|
|
traceback.print_exc()
|
|
else:
|
|
else:
|
|
@@ -123,7 +140,7 @@ def banner_edit(request):
|
|
if req_params:
|
|
if req_params:
|
|
try:
|
|
try:
|
|
bid = req_params.get("bid")
|
|
bid = req_params.get("bid")
|
|
- position = req_params.get("position",None)
|
|
|
|
|
|
+ position = int(req_params.get("position",None))
|
|
img_url = req_params.get("img_url",None)
|
|
img_url = req_params.get("img_url",None)
|
|
display_title = req_params.get("display_title",None)
|
|
display_title = req_params.get("display_title",None)
|
|
article_url = req_params.get("article_url",None)
|
|
article_url = req_params.get("article_url",None)
|
|
@@ -131,9 +148,27 @@ def banner_edit(request):
|
|
author = req_params.get("author",None)
|
|
author = req_params.get("author",None)
|
|
content = req_params.get("content",None)
|
|
content = req_params.get("content",None)
|
|
|
|
|
|
- obj= Banner.objects.filter(id=bid)
|
|
|
|
|
|
+ print("banner_edit*****_img_url",img_url)
|
|
|
|
+ # img_path = save_bs64img_local(img_url)
|
|
|
|
+ # print("banner_edit*****_img_",img_path)
|
|
|
|
+
|
|
|
|
+ # if position!=0 and Banner.objects.filter(position=position):
|
|
|
|
+ # return JsonResponse({"code": -1, "msg": "横幅位置重复!"})
|
|
|
|
+
|
|
|
|
+ obj= Banner.objects.filter(id=bid).first()
|
|
if obj:
|
|
if obj:
|
|
- obj.id = bid
|
|
|
|
|
|
+ # 处理横幅位置重复,0 表示未展示
|
|
|
|
+ if position!=0 and obj.position!=position:
|
|
|
|
+ obj_postions=Banner.objects.all()
|
|
|
|
+ list_postion =[]
|
|
|
|
+ for ob in obj_postions:
|
|
|
|
+ list_postion.append(int(ob.position))
|
|
|
|
+ print("00000000",position)
|
|
|
|
+ print("11111111",list_postion)
|
|
|
|
+ if position in list_postion:
|
|
|
|
+ print("333333")
|
|
|
|
+ return JsonResponse({"code": -1, "msg": "横幅位置重复!"})
|
|
|
|
+
|
|
obj.position = position
|
|
obj.position = position
|
|
obj.img_url = img_url
|
|
obj.img_url = img_url
|
|
obj.display_title = display_title
|
|
obj.display_title = display_title
|
|
@@ -141,9 +176,9 @@ def banner_edit(request):
|
|
obj.author = author
|
|
obj.author = author
|
|
obj.content = content
|
|
obj.content = content
|
|
obj.save()
|
|
obj.save()
|
|
- res = {"code": 0, "msg": "banner add sucess"}
|
|
|
|
|
|
+ res = {"code": 0, "msg": "banner edit sucess"}
|
|
else:
|
|
else:
|
|
- res = {"code": -1, "msg": "banner add fail"}
|
|
|
|
|
|
+ res = {"code": -1, "msg": "banner edit fail"}
|
|
except:
|
|
except:
|
|
traceback.print_exc()
|
|
traceback.print_exc()
|
|
else:
|
|
else:
|
|
@@ -194,7 +229,7 @@ def news_show(request):
|
|
data_list.append(dict_data)
|
|
data_list.append(dict_data)
|
|
res = {"code":0,"msg":"show sucess!","content_data":data_list}
|
|
res = {"code":0,"msg":"show sucess!","content_data":data_list}
|
|
else:
|
|
else:
|
|
- res = {"code":-1,"msg":"no data",}
|
|
|
|
|
|
+ res = {"code":-1,"msg":"no data"}
|
|
|
|
|
|
return JsonResponse(res)
|
|
return JsonResponse(res)
|
|
|
|
|
|
@@ -209,12 +244,14 @@ def news_add(request):
|
|
if req_params:
|
|
if req_params:
|
|
try:
|
|
try:
|
|
img_url = req_params.get("img_url",None)
|
|
img_url = req_params.get("img_url",None)
|
|
- title = req_params.get("title",None)
|
|
|
|
- author = req_params.get("author",None)
|
|
|
|
- content = req_params.get("content",None)
|
|
|
|
|
|
+ title = req_params.get("title")
|
|
|
|
+ author = req_params.get("author")
|
|
|
|
+ content = req_params.get("content")
|
|
obj= News.objects.create(title=title,img_url=img_url,author=author,content=content)
|
|
obj= News.objects.create(title=title,img_url=img_url,author=author,content=content)
|
|
-
|
|
|
|
- res = res={"code": 0, "msg": "banner add sucess"}
|
|
|
|
|
|
+ if obj:
|
|
|
|
+ res = {"code": 0, "msg": "news add sucess"}
|
|
|
|
+ else:
|
|
|
|
+ res = {"code": -1, "msg": "news add fail"}
|
|
except:
|
|
except:
|
|
traceback.print_exc()
|
|
traceback.print_exc()
|
|
else:
|
|
else:
|
|
@@ -241,6 +278,7 @@ def news_look(request):
|
|
dict_data["create_time"] = obj.create_time
|
|
dict_data["create_time"] = obj.create_time
|
|
dict_data["author"] = obj.author
|
|
dict_data["author"] = obj.author
|
|
dict_data["content"] = obj.content
|
|
dict_data["content"] = obj.content
|
|
|
|
+ dict_data["img_url"] = obj.img_url
|
|
print("news_look-----",dict_data)
|
|
print("news_look-----",dict_data)
|
|
res={"code": 0, "msg": "sucess","look_data":dict_data}
|
|
res={"code": 0, "msg": "sucess","look_data":dict_data}
|
|
else:
|
|
else:
|