删除工程

master
robert 2 years ago
parent 06469c598e
commit bdabcbff19

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import cheweileixing
from util.codes import *
from util.auth import Auth
import util.message as mes
def cheweileixing_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = cheweileixing.createbyreq(cheweileixing, cheweileixing, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def cheweileixing_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = cheweileixing.getbyparams(cheweileixing, cheweileixing, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= cheweileixing.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, cheweileixing, req_dict)
def cheweileixing_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def cheweileixing_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = cheweileixing.updatebyparams(cheweileixing,cheweileixing, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweileixing_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = cheweileixing.getbyparams(cheweileixing, cheweileixing, req_dict)[0]
return JsonResponse(msg)
def cheweileixing_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=cheweileixing.getbyparams(cheweileixing, cheweileixing, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def cheweileixing_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweileixing.getallcolumn( cheweileixing, cheweileixing)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=cheweileixing.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=cheweileixing.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in cheweileixing.getallcolumn(cheweileixing,cheweileixing):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=cheweileixing.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =cheweileixing.page(cheweileixing, cheweileixing, req_dict)
return JsonResponse(msg)
def cheweileixing_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in cheweileixing.getallcolumn(cheweileixing,cheweileixing):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = cheweileixing.page(cheweileixing,cheweileixing, req_dict)
return JsonResponse(msg)
def cheweileixing_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweileixing.getallcolumn( cheweileixing, cheweileixing)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=cheweileixing.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=cheweileixing.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=cheweileixing.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=cheweileixing.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if cheweileixing.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = cheweileixing.page(cheweileixing, cheweileixing, req_dict)
return JsonResponse(msg)
def cheweileixing_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= cheweileixing.getallcolumn( cheweileixing, cheweileixing)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= cheweileixing.createbyreq(cheweileixing,cheweileixing, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweileixing_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweileixing.getallcolumn( cheweileixing, cheweileixing)
try:
__authSeparate__=cheweileixing.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=cheweileixing.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= cheweileixing.createbyreq(cheweileixing,cheweileixing, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweileixing_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=cheweileixing.getbyid(cheweileixing,cheweileixing,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = cheweileixing.updatebyparams(cheweileixing,cheweileixing, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweileixing_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = cheweileixing.getbyid(cheweileixing,cheweileixing, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= cheweileixing.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in cheweileixing.getallcolumn(cheweileixing,cheweileixing):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=cheweileixing.updatebyparams(cheweileixing,cheweileixing,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def cheweileixing_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =cheweileixing.getbyid(cheweileixing,cheweileixing, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= cheweileixing.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in cheweileixing.getallcolumn(cheweileixing,cheweileixing):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=cheweileixing.updatebyparams(cheweileixing,cheweileixing,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def cheweileixing_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in cheweileixing.getallcolumn(cheweileixing,cheweileixing) :
del req_dict["mima"]
if "password" not in cheweileixing.getallcolumn(cheweileixing,cheweileixing) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = cheweileixing.updatebyparams(cheweileixing, cheweileixing, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweileixing_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=cheweileixing.deletes(cheweileixing,
cheweileixing,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweileixing_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= cheweileixing.getbyid(cheweileixing, cheweileixing, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=cheweileixing.updatebyparams(cheweileixing,cheweileixing,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import cheweiweihu
from util.codes import *
from util.auth import Auth
import util.message as mes
def cheweiweihu_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = cheweiweihu.createbyreq(cheweiweihu, cheweiweihu, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def cheweiweihu_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = cheweiweihu.getbyparams(cheweiweihu, cheweiweihu, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= cheweiweihu.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, cheweiweihu, req_dict)
def cheweiweihu_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def cheweiweihu_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = cheweiweihu.updatebyparams(cheweiweihu,cheweiweihu, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweiweihu_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = cheweiweihu.getbyparams(cheweiweihu, cheweiweihu, req_dict)[0]
return JsonResponse(msg)
def cheweiweihu_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=cheweiweihu.getbyparams(cheweiweihu, cheweiweihu, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def cheweiweihu_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweiweihu.getallcolumn( cheweiweihu, cheweiweihu)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=cheweiweihu.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=cheweiweihu.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in cheweiweihu.getallcolumn(cheweiweihu,cheweiweihu):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=cheweiweihu.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =cheweiweihu.page(cheweiweihu, cheweiweihu, req_dict)
return JsonResponse(msg)
def cheweiweihu_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in cheweiweihu.getallcolumn(cheweiweihu,cheweiweihu):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = cheweiweihu.page(cheweiweihu,cheweiweihu, req_dict)
return JsonResponse(msg)
def cheweiweihu_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweiweihu.getallcolumn( cheweiweihu, cheweiweihu)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=cheweiweihu.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=cheweiweihu.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=cheweiweihu.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=cheweiweihu.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if cheweiweihu.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = cheweiweihu.page(cheweiweihu, cheweiweihu, req_dict)
return JsonResponse(msg)
def cheweiweihu_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= cheweiweihu.getallcolumn( cheweiweihu, cheweiweihu)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= cheweiweihu.createbyreq(cheweiweihu,cheweiweihu, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweiweihu_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweiweihu.getallcolumn( cheweiweihu, cheweiweihu)
try:
__authSeparate__=cheweiweihu.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=cheweiweihu.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= cheweiweihu.createbyreq(cheweiweihu,cheweiweihu, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweiweihu_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=cheweiweihu.getbyid(cheweiweihu,cheweiweihu,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = cheweiweihu.updatebyparams(cheweiweihu,cheweiweihu, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweiweihu_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = cheweiweihu.getbyid(cheweiweihu,cheweiweihu, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= cheweiweihu.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in cheweiweihu.getallcolumn(cheweiweihu,cheweiweihu):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=cheweiweihu.updatebyparams(cheweiweihu,cheweiweihu,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def cheweiweihu_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =cheweiweihu.getbyid(cheweiweihu,cheweiweihu, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= cheweiweihu.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in cheweiweihu.getallcolumn(cheweiweihu,cheweiweihu):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=cheweiweihu.updatebyparams(cheweiweihu,cheweiweihu,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def cheweiweihu_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in cheweiweihu.getallcolumn(cheweiweihu,cheweiweihu) :
del req_dict["mima"]
if "password" not in cheweiweihu.getallcolumn(cheweiweihu,cheweiweihu) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = cheweiweihu.updatebyparams(cheweiweihu, cheweiweihu, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweiweihu_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=cheweiweihu.deletes(cheweiweihu,
cheweiweihu,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweiweihu_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= cheweiweihu.getbyid(cheweiweihu, cheweiweihu, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=cheweiweihu.updatebyparams(cheweiweihu,cheweiweihu,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import cheweixinxi
from util.codes import *
from util.auth import Auth
import util.message as mes
def cheweixinxi_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = cheweixinxi.createbyreq(cheweixinxi, cheweixinxi, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def cheweixinxi_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = cheweixinxi.getbyparams(cheweixinxi, cheweixinxi, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= cheweixinxi.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, cheweixinxi, req_dict)
def cheweixinxi_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def cheweixinxi_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = cheweixinxi.updatebyparams(cheweixinxi,cheweixinxi, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweixinxi_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = cheweixinxi.getbyparams(cheweixinxi, cheweixinxi, req_dict)[0]
return JsonResponse(msg)
def cheweixinxi_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=cheweixinxi.getbyparams(cheweixinxi, cheweixinxi, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def cheweixinxi_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweixinxi.getallcolumn( cheweixinxi, cheweixinxi)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=cheweixinxi.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=cheweixinxi.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in cheweixinxi.getallcolumn(cheweixinxi,cheweixinxi):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=cheweixinxi.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =cheweixinxi.page(cheweixinxi, cheweixinxi, req_dict)
return JsonResponse(msg)
def cheweixinxi_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in cheweixinxi.getallcolumn(cheweixinxi,cheweixinxi):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = cheweixinxi.page(cheweixinxi,cheweixinxi, req_dict)
return JsonResponse(msg)
def cheweixinxi_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweixinxi.getallcolumn( cheweixinxi, cheweixinxi)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=cheweixinxi.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=cheweixinxi.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=cheweixinxi.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=cheweixinxi.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if cheweixinxi.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = cheweixinxi.page(cheweixinxi, cheweixinxi, req_dict)
return JsonResponse(msg)
def cheweixinxi_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= cheweixinxi.getallcolumn( cheweixinxi, cheweixinxi)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= cheweixinxi.createbyreq(cheweixinxi,cheweixinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweixinxi_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= cheweixinxi.getallcolumn( cheweixinxi, cheweixinxi)
try:
__authSeparate__=cheweixinxi.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=cheweixinxi.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= cheweixinxi.createbyreq(cheweixinxi,cheweixinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweixinxi_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=cheweixinxi.getbyid(cheweixinxi,cheweixinxi,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = cheweixinxi.updatebyparams(cheweixinxi,cheweixinxi, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweixinxi_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = cheweixinxi.getbyid(cheweixinxi,cheweixinxi, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= cheweixinxi.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in cheweixinxi.getallcolumn(cheweixinxi,cheweixinxi):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=cheweixinxi.updatebyparams(cheweixinxi,cheweixinxi,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def cheweixinxi_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =cheweixinxi.getbyid(cheweixinxi,cheweixinxi, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= cheweixinxi.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in cheweixinxi.getallcolumn(cheweixinxi,cheweixinxi):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=cheweixinxi.updatebyparams(cheweixinxi,cheweixinxi,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def cheweixinxi_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in cheweixinxi.getallcolumn(cheweixinxi,cheweixinxi) :
del req_dict["mima"]
if "password" not in cheweixinxi.getallcolumn(cheweixinxi,cheweixinxi) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = cheweixinxi.updatebyparams(cheweixinxi, cheweixinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweixinxi_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=cheweixinxi.deletes(cheweixinxi,
cheweixinxi,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def cheweixinxi_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= cheweixinxi.getbyid(cheweixinxi, cheweixinxi, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=cheweixinxi.updatebyparams(cheweixinxi,cheweixinxi,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import chuchangjiaofei
from util.codes import *
from util.auth import Auth
import util.message as mes
def chuchangjiaofei_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = chuchangjiaofei.createbyreq(chuchangjiaofei, chuchangjiaofei, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def chuchangjiaofei_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = chuchangjiaofei.getbyparams(chuchangjiaofei, chuchangjiaofei, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= chuchangjiaofei.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, chuchangjiaofei, req_dict)
def chuchangjiaofei_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def chuchangjiaofei_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = chuchangjiaofei.updatebyparams(chuchangjiaofei,chuchangjiaofei, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def chuchangjiaofei_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = chuchangjiaofei.getbyparams(chuchangjiaofei, chuchangjiaofei, req_dict)[0]
return JsonResponse(msg)
def chuchangjiaofei_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=chuchangjiaofei.getbyparams(chuchangjiaofei, chuchangjiaofei, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def chuchangjiaofei_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= chuchangjiaofei.getallcolumn( chuchangjiaofei, chuchangjiaofei)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=chuchangjiaofei.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=chuchangjiaofei.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in chuchangjiaofei.getallcolumn(chuchangjiaofei,chuchangjiaofei):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=chuchangjiaofei.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =chuchangjiaofei.page(chuchangjiaofei, chuchangjiaofei, req_dict)
return JsonResponse(msg)
def chuchangjiaofei_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in chuchangjiaofei.getallcolumn(chuchangjiaofei,chuchangjiaofei):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = chuchangjiaofei.page(chuchangjiaofei,chuchangjiaofei, req_dict)
return JsonResponse(msg)
def chuchangjiaofei_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= chuchangjiaofei.getallcolumn( chuchangjiaofei, chuchangjiaofei)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=chuchangjiaofei.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=chuchangjiaofei.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=chuchangjiaofei.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=chuchangjiaofei.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if chuchangjiaofei.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = chuchangjiaofei.page(chuchangjiaofei, chuchangjiaofei, req_dict)
return JsonResponse(msg)
def chuchangjiaofei_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= chuchangjiaofei.getallcolumn( chuchangjiaofei, chuchangjiaofei)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= chuchangjiaofei.createbyreq(chuchangjiaofei,chuchangjiaofei, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def chuchangjiaofei_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= chuchangjiaofei.getallcolumn( chuchangjiaofei, chuchangjiaofei)
try:
__authSeparate__=chuchangjiaofei.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=chuchangjiaofei.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= chuchangjiaofei.createbyreq(chuchangjiaofei,chuchangjiaofei, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def chuchangjiaofei_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=chuchangjiaofei.getbyid(chuchangjiaofei,chuchangjiaofei,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = chuchangjiaofei.updatebyparams(chuchangjiaofei,chuchangjiaofei, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def chuchangjiaofei_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = chuchangjiaofei.getbyid(chuchangjiaofei,chuchangjiaofei, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= chuchangjiaofei.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in chuchangjiaofei.getallcolumn(chuchangjiaofei,chuchangjiaofei):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=chuchangjiaofei.updatebyparams(chuchangjiaofei,chuchangjiaofei,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def chuchangjiaofei_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =chuchangjiaofei.getbyid(chuchangjiaofei,chuchangjiaofei, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= chuchangjiaofei.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in chuchangjiaofei.getallcolumn(chuchangjiaofei,chuchangjiaofei):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=chuchangjiaofei.updatebyparams(chuchangjiaofei,chuchangjiaofei,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def chuchangjiaofei_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in chuchangjiaofei.getallcolumn(chuchangjiaofei,chuchangjiaofei) :
del req_dict["mima"]
if "password" not in chuchangjiaofei.getallcolumn(chuchangjiaofei,chuchangjiaofei) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = chuchangjiaofei.updatebyparams(chuchangjiaofei, chuchangjiaofei, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def chuchangjiaofei_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=chuchangjiaofei.deletes(chuchangjiaofei,
chuchangjiaofei,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def chuchangjiaofei_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= chuchangjiaofei.getbyid(chuchangjiaofei, chuchangjiaofei, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=chuchangjiaofei.updatebyparams(chuchangjiaofei,chuchangjiaofei,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import huiyuan
from util.codes import *
from util.auth import Auth
import util.message as mes
def huiyuan_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = huiyuan.createbyreq(huiyuan, huiyuan, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def huiyuan_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = huiyuan.getbyparams(huiyuan, huiyuan, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= huiyuan.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, huiyuan, req_dict)
def huiyuan_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def huiyuan_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = huiyuan.updatebyparams(huiyuan,huiyuan, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def huiyuan_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = huiyuan.getbyparams(huiyuan, huiyuan, req_dict)[0]
return JsonResponse(msg)
def huiyuan_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=huiyuan.getbyparams(huiyuan, huiyuan, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def huiyuan_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= huiyuan.getallcolumn( huiyuan, huiyuan)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=huiyuan.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=huiyuan.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in huiyuan.getallcolumn(huiyuan,huiyuan):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=huiyuan.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =huiyuan.page(huiyuan, huiyuan, req_dict)
return JsonResponse(msg)
def huiyuan_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in huiyuan.getallcolumn(huiyuan,huiyuan):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = huiyuan.page(huiyuan,huiyuan, req_dict)
return JsonResponse(msg)
def huiyuan_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= huiyuan.getallcolumn( huiyuan, huiyuan)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=huiyuan.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=huiyuan.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=huiyuan.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=huiyuan.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if huiyuan.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = huiyuan.page(huiyuan, huiyuan, req_dict)
return JsonResponse(msg)
def huiyuan_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= huiyuan.getallcolumn( huiyuan, huiyuan)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= huiyuan.createbyreq(huiyuan,huiyuan, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def huiyuan_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= huiyuan.getallcolumn( huiyuan, huiyuan)
try:
__authSeparate__=huiyuan.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=huiyuan.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= huiyuan.createbyreq(huiyuan,huiyuan, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def huiyuan_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=huiyuan.getbyid(huiyuan,huiyuan,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = huiyuan.updatebyparams(huiyuan,huiyuan, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def huiyuan_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = huiyuan.getbyid(huiyuan,huiyuan, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= huiyuan.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in huiyuan.getallcolumn(huiyuan,huiyuan):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=huiyuan.updatebyparams(huiyuan,huiyuan,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def huiyuan_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =huiyuan.getbyid(huiyuan,huiyuan, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= huiyuan.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in huiyuan.getallcolumn(huiyuan,huiyuan):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=huiyuan.updatebyparams(huiyuan,huiyuan,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def huiyuan_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in huiyuan.getallcolumn(huiyuan,huiyuan) :
del req_dict["mima"]
if "password" not in huiyuan.getallcolumn(huiyuan,huiyuan) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = huiyuan.updatebyparams(huiyuan, huiyuan, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def huiyuan_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=huiyuan.deletes(huiyuan,
huiyuan,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def huiyuan_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= huiyuan.getbyid(huiyuan, huiyuan, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=huiyuan.updatebyparams(huiyuan,huiyuan,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import messages
from util.codes import *
from util.auth import Auth
import util.message as mes
def messages_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = messages.createbyreq(messages, messages, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def messages_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = messages.getbyparams(messages, messages, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= messages.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, messages, req_dict)
def messages_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def messages_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = messages.updatebyparams(messages,messages, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def messages_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = messages.getbyparams(messages, messages, req_dict)[0]
return JsonResponse(msg)
def messages_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=messages.getbyparams(messages, messages, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def messages_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= messages.getallcolumn( messages, messages)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=messages.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=messages.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in messages.getallcolumn(messages,messages):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=messages.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =messages.page(messages, messages, req_dict)
return JsonResponse(msg)
def messages_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in messages.getallcolumn(messages,messages):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = messages.page(messages,messages, req_dict)
return JsonResponse(msg)
def messages_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= messages.getallcolumn( messages, messages)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=messages.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=messages.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=messages.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=messages.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if messages.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = messages.page(messages, messages, req_dict)
return JsonResponse(msg)
def messages_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= messages.getallcolumn( messages, messages)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= messages.createbyreq(messages,messages, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def messages_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= messages.getallcolumn( messages, messages)
try:
__authSeparate__=messages.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=messages.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= messages.createbyreq(messages,messages, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def messages_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=messages.getbyid(messages,messages,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = messages.updatebyparams(messages,messages, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def messages_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = messages.getbyid(messages,messages, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= messages.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in messages.getallcolumn(messages,messages):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=messages.updatebyparams(messages,messages,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def messages_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =messages.getbyid(messages,messages, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= messages.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in messages.getallcolumn(messages,messages):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=messages.updatebyparams(messages,messages,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def messages_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in messages.getallcolumn(messages,messages) :
del req_dict["mima"]
if "password" not in messages.getallcolumn(messages,messages) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = messages.updatebyparams(messages, messages, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def messages_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=messages.deletes(messages,
messages,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def messages_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= messages.getbyid(messages, messages, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=messages.updatebyparams(messages,messages,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import news
from util.codes import *
from util.auth import Auth
import util.message as mes
def news_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = news.createbyreq(news, news, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def news_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = news.getbyparams(news, news, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= news.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, news, req_dict)
def news_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def news_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = news.updatebyparams(news,news, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def news_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = news.getbyparams(news, news, req_dict)[0]
return JsonResponse(msg)
def news_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=news.getbyparams(news, news, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def news_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= news.getallcolumn( news, news)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=news.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=news.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in news.getallcolumn(news,news):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=news.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =news.page(news, news, req_dict)
return JsonResponse(msg)
def news_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in news.getallcolumn(news,news):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = news.page(news,news, req_dict)
return JsonResponse(msg)
def news_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= news.getallcolumn( news, news)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=news.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=news.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=news.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=news.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if news.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = news.page(news, news, req_dict)
return JsonResponse(msg)
def news_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= news.getallcolumn( news, news)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= news.createbyreq(news,news, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def news_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= news.getallcolumn( news, news)
try:
__authSeparate__=news.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=news.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= news.createbyreq(news,news, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def news_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=news.getbyid(news,news,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = news.updatebyparams(news,news, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def news_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = news.getbyid(news,news, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= news.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in news.getallcolumn(news,news):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=news.updatebyparams(news,news,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def news_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =news.getbyid(news,news, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= news.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in news.getallcolumn(news,news):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=news.updatebyparams(news,news,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def news_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in news.getallcolumn(news,news) :
del req_dict["mima"]
if "password" not in news.getallcolumn(news,news) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = news.updatebyparams(news, news, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def news_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=news.deletes(news,
news,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def news_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= news.getbyid(news, news, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=news.updatebyparams(news,news,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import ruchangtingche
from util.codes import *
from util.auth import Auth
import util.message as mes
def ruchangtingche_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = ruchangtingche.createbyreq(ruchangtingche, ruchangtingche, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def ruchangtingche_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = ruchangtingche.getbyparams(ruchangtingche, ruchangtingche, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= ruchangtingche.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, ruchangtingche, req_dict)
def ruchangtingche_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def ruchangtingche_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = ruchangtingche.updatebyparams(ruchangtingche,ruchangtingche, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def ruchangtingche_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = ruchangtingche.getbyparams(ruchangtingche, ruchangtingche, req_dict)[0]
return JsonResponse(msg)
def ruchangtingche_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=ruchangtingche.getbyparams(ruchangtingche, ruchangtingche, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def ruchangtingche_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= ruchangtingche.getallcolumn( ruchangtingche, ruchangtingche)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=ruchangtingche.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=ruchangtingche.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in ruchangtingche.getallcolumn(ruchangtingche,ruchangtingche):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=ruchangtingche.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =ruchangtingche.page(ruchangtingche, ruchangtingche, req_dict)
return JsonResponse(msg)
def ruchangtingche_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in ruchangtingche.getallcolumn(ruchangtingche,ruchangtingche):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = ruchangtingche.page(ruchangtingche,ruchangtingche, req_dict)
return JsonResponse(msg)
def ruchangtingche_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= ruchangtingche.getallcolumn( ruchangtingche, ruchangtingche)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=ruchangtingche.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=ruchangtingche.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=ruchangtingche.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=ruchangtingche.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if ruchangtingche.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = ruchangtingche.page(ruchangtingche, ruchangtingche, req_dict)
return JsonResponse(msg)
def ruchangtingche_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= ruchangtingche.getallcolumn( ruchangtingche, ruchangtingche)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= ruchangtingche.createbyreq(ruchangtingche,ruchangtingche, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def ruchangtingche_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= ruchangtingche.getallcolumn( ruchangtingche, ruchangtingche)
try:
__authSeparate__=ruchangtingche.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=ruchangtingche.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= ruchangtingche.createbyreq(ruchangtingche,ruchangtingche, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def ruchangtingche_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=ruchangtingche.getbyid(ruchangtingche,ruchangtingche,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = ruchangtingche.updatebyparams(ruchangtingche,ruchangtingche, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def ruchangtingche_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = ruchangtingche.getbyid(ruchangtingche,ruchangtingche, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= ruchangtingche.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in ruchangtingche.getallcolumn(ruchangtingche,ruchangtingche):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=ruchangtingche.updatebyparams(ruchangtingche,ruchangtingche,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def ruchangtingche_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =ruchangtingche.getbyid(ruchangtingche,ruchangtingche, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= ruchangtingche.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in ruchangtingche.getallcolumn(ruchangtingche,ruchangtingche):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=ruchangtingche.updatebyparams(ruchangtingche,ruchangtingche,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def ruchangtingche_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in ruchangtingche.getallcolumn(ruchangtingche,ruchangtingche) :
del req_dict["mima"]
if "password" not in ruchangtingche.getallcolumn(ruchangtingche,ruchangtingche) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = ruchangtingche.updatebyparams(ruchangtingche, ruchangtingche, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def ruchangtingche_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=ruchangtingche.deletes(ruchangtingche,
ruchangtingche,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def ruchangtingche_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= ruchangtingche.getbyid(ruchangtingche, ruchangtingche, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=ruchangtingche.updatebyparams(ruchangtingche,ruchangtingche,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,522 +0,0 @@
#coding:utf-8
__author__ = "ila"
import copy
from django.http import JsonResponse
from django.apps import apps
from django.db.models.aggregates import Count,Sum
from .models import storeup
from util.codes import *
from util.auth import Auth
import util.message as mes
def storeup_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = storeup.createbyreq(storeup, storeup, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
return JsonResponse(msg)
def storeup_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = storeup.getbyparams(storeup, storeup, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
try:
__sfsh__= storeup.__sfsh__
except:
__sfsh__=None
if __sfsh__=='':
if datas[0].get('sfsh')=='':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, storeup, req_dict)
def storeup_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg)
def storeup_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = storeup.updatebyparams(storeup,storeup, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def storeup_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = storeup.getbyparams(storeup, storeup, req_dict)[0]
return JsonResponse(msg)
def storeup_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":""})
data=storeup.getbyparams(storeup, storeup, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg)
def storeup_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= storeup.getallcolumn( storeup, storeup)
#当前登录用户所在表
tablename = request.session.get("tablename")
#authColumn=list(__authTables__.keys())[0]
#authTable=__authTables__.get(authColumn)
# if authTable==tablename:
#params = request.session.get("params")
#req_dict[authColumn]=params.get(authColumn)
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__=storeup.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”生成系统自动生成留言板的表messages同时该表的表属性hasMessage也被设置为”是”,字段包括userid用户idusername(用户名)content留言内容reply回复
#接口page需要区分权限普通用户查看自己的留言和回复记录管理员查看所有的留言和回复记录
try:
__hasMessage__=storeup.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and "userid" in storeup.getallcolumn(storeup,storeup):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=storeup.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =storeup.page(storeup, storeup, req_dict)
return JsonResponse(msg)
def storeup_autoSort(request):
'''
智能推荐功能(表属性[intelRecom/],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
主要信息列表如商品列表新闻列表中使用显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in storeup.getallcolumn(storeup,storeup):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = storeup.page(storeup,storeup, req_dict)
return JsonResponse(msg)
def storeup_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= storeup.getallcolumn( storeup, storeup)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=storeup.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=storeup.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=storeup.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="" and __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
# 本接口可以匿名访问,所以try判断是否为匿名
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__=storeup.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if storeup.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = storeup.page(storeup, storeup, req_dict)
return JsonResponse(msg)
def storeup_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= storeup.getallcolumn( storeup, storeup)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= storeup.createbyreq(storeup,storeup, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def storeup_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= storeup.getallcolumn( storeup, storeup)
try:
__authSeparate__=storeup.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=storeup.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= storeup.createbyreq(storeup,storeup, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def storeup_thumbsup(request,id_):
'''
点赞表属性thumbsUp[/]刷表新增thumbsupnum赞和crazilynum踩字段
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=storeup.getbyid(storeup,storeup,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = storeup.updatebyparams(storeup,storeup, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def storeup_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = storeup.getbyid(storeup,storeup, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= storeup.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in storeup.getallcolumn(storeup,storeup):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=storeup.updatebyparams(storeup,storeup,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def storeup_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =storeup.getbyid(storeup,storeup, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= storeup.__browseClick__
except:
__browseClick__=None
if __browseClick__=="" and "clicknum" in storeup.getallcolumn(storeup,storeup):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=storeup.updatebyparams(storeup,storeup,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def storeup_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in storeup.getallcolumn(storeup,storeup) :
del req_dict["mima"]
if "password" not in storeup.getallcolumn(storeup,storeup) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = storeup.updatebyparams(storeup, storeup, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def storeup_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=storeup.deletes(storeup,
storeup,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def storeup_vote(request,id_):
'''
浏览点击次数表属性[browseClick:/]点击字段clicknum调用info/detail接口的时候后端自动+1投票功能表属性[vote:/]投票字段votenum,调用vote接口后端votenum+1
统计商品或新闻的点击次数提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= storeup.getbyid(storeup, storeup, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=storeup.updatebyparams(storeup,storeup,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1 +0,0 @@
default_app_config = 'main.apps.MainConfig'

@ -1,31 +0,0 @@
from django.contrib import admin
from django.apps import apps, AppConfig
# Register your models here.
from dj2.settings import dbName as schemaName
from main.users_model import users
from main.config_model import config
try:
from main.models import *
except:
pass
# change title
admin.site.site_title = schemaName # 设置页面标题
admin.site.site_header = schemaName # 设置网站页头
admin.site.index_title = schemaName # 设置首页标语
allModels = apps.get_app_config('main').get_models()
for ind, model in enumerate(allModels):
class modelsite(admin.ModelAdmin):
list_display = []
for col in model._meta.fields:
list_display.append(col.name)
search_fields = list_display
admin.site.register(model, modelsite)

@ -1,6 +0,0 @@
from django.apps import AppConfig
class MainConfig(AppConfig):
name = 'main'
verbose_name = verbose_name_plural = r'刷表模块'

@ -1,21 +0,0 @@
# coding:utf-8
__author__ = "ila"
from django.db import models
from .model import BaseModel
class config(BaseModel):
# id=models.BigIntegerField(verbose_name="自增id")
name = models.CharField(max_length=100, verbose_name=u'键名')
value = models.CharField(max_length=100, verbose_name=u'键值')
__tablename__ = 'config'
class Meta:
db_table = 'config'
verbose_name = verbose_name_plural = u'配置表'
# def __str__(self):
# return self.name

@ -1,131 +0,0 @@
# coding:utf-8
__author__ = "ila"
import logging
from django.http import JsonResponse
from .config_model import config
from util.codes import *
from util import message as mes
def config_page(request):
'''
获取参数信息
:return:
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code,
"data": {"currPage": 1, "totalPage": 1, "total": 1, "pageSize": 10, "list": []}}
req_dict = request.session.get('req_dict')
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = config.page(config, config, req_dict)
return JsonResponse(msg)
def config_list(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code,
"data": {"currPage": 1, "totalPage": 1, "total": 1, "pageSize": 10, "list": []}}
req_dict = request.session.get("req_dict")
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = config.page(config, config, req_dict)
return JsonResponse(msg)
def config_info(request, id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = config.getbyid(config, config, int(id_))
if len(data) > 0:
msg['data'] = data[0]
return JsonResponse(msg)
def config_detail(request, id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = config.getbyid(config, config, int(id_))
if len(data) > 0:
msg['data'] = data[0]
return JsonResponse(msg)
def config_save(request):
'''
创建参数信息
:return:
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get('req_dict')
param1 = config.getbyparams(config, config, req_dict)
if param1:
msg['code'] = id_exist_code
msg['msg'] = mes.id_exist_code
return JsonResponse(msg)
error = config.createbyreq(config, config, req_dict)
logging.warning("save_config.res=========>{}".format(error))
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def config_add(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error = config.createbyreq(config, config, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def config_update(request):
'''
更新参数信息
:return:
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get('req_dict')
config.updatebyparams(config, config, req_dict)
return JsonResponse(msg)
def config_delete(request):
'''
删除参数信息
:return:
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get('req_dict')
config.deletes(config,
config,
req_dict.get("ids")
)
return JsonResponse(msg)

@ -1,219 +0,0 @@
# Generated by Django 2.0 on 2022-08-14 05:19
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='cheweileixing',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('cheweileixing', models.CharField(max_length=255, unique=True, verbose_name='车位类型')),
],
options={
'verbose_name': '车位类型',
'verbose_name_plural': '车位类型',
'db_table': 'cheweileixing',
},
),
migrations.CreateModel(
name='cheweiweihu',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('cheweibianhao', models.CharField(max_length=255, verbose_name='车位编号')),
('cheweimingcheng', models.CharField(max_length=255, null=True, verbose_name='车位名称')),
('cheweileixing', models.CharField(max_length=255, null=True, verbose_name='车位类型')),
('cheweiweizhi', models.CharField(max_length=255, null=True, verbose_name='车位位置')),
('weihuleixing', models.CharField(max_length=255, verbose_name='维护类型')),
('weihuxiangmu', models.CharField(max_length=255, null=True, verbose_name='维护项目')),
('weihushijian', models.DateTimeField(verbose_name='维护时间')),
('weihuxiangqing', models.TextField(null=True, verbose_name='维护详情')),
],
options={
'verbose_name': '车位维护',
'verbose_name_plural': '车位维护',
'db_table': 'cheweiweihu',
},
),
migrations.CreateModel(
name='cheweixinxi',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('cheweibianhao', models.CharField(max_length=255, unique=True, verbose_name='车位编号')),
('cheweimingcheng', models.CharField(max_length=255, null=True, verbose_name='车位名称')),
('cheweileixing', models.CharField(max_length=255, null=True, verbose_name='车位类型')),
('cheweitupian', models.CharField(max_length=255, null=True, verbose_name='车位图片')),
('cheweiweizhi', models.CharField(max_length=255, null=True, verbose_name='车位位置')),
('cheweizhuangtai', models.CharField(max_length=255, verbose_name='车位状态')),
('tingchejiage', models.IntegerField(verbose_name='停车价格')),
('shoufeibiaozhun', models.CharField(max_length=255, null=True, verbose_name='收费标准')),
('cheweixiangqing', models.TextField(null=True, verbose_name='车位详情')),
],
options={
'verbose_name': '车位信息',
'verbose_name_plural': '车位信息',
'db_table': 'cheweixinxi',
},
),
migrations.CreateModel(
name='chuchangjiaofei',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('cheweibianhao', models.CharField(max_length=255, verbose_name='车位编号')),
('cheweimingcheng', models.CharField(max_length=255, null=True, verbose_name='车位名称')),
('cheweileixing', models.CharField(max_length=255, null=True, verbose_name='车位类型')),
('cheweitupian', models.CharField(max_length=255, null=True, verbose_name='车位图片')),
('tingchejiage', models.IntegerField(null=True, verbose_name='停车价格')),
('ruchangshijian', models.CharField(max_length=255, null=True, verbose_name='入场时间')),
('chuchangshijian', models.DateTimeField(verbose_name='出场时间')),
('tingcheshizhang', models.IntegerField(verbose_name='停车时长')),
('tingchefeiyong', models.IntegerField(null=True, verbose_name='停车费用')),
('xinxibeizhu', models.CharField(max_length=255, null=True, verbose_name='信息备注')),
('yonghuming', models.CharField(max_length=255, null=True, verbose_name='用户名')),
('shouji', models.CharField(max_length=255, null=True, verbose_name='手机')),
('chepai', models.CharField(max_length=255, null=True, verbose_name='车牌')),
('sfsh', models.CharField(default='', max_length=255, null=True, verbose_name='是否审核')),
('shhf', models.TextField(null=True, verbose_name='审核回复')),
('ispay', models.CharField(default='未支付', max_length=255, null=True, verbose_name='是否支付')),
],
options={
'verbose_name': '出场缴费',
'verbose_name_plural': '出场缴费',
'db_table': 'chuchangjiaofei',
},
),
migrations.CreateModel(
name='config',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, verbose_name='键名')),
('value', models.CharField(max_length=100, verbose_name='键值')),
],
options={
'verbose_name': '配置表',
'verbose_name_plural': '配置表',
'db_table': 'config',
},
),
migrations.CreateModel(
name='huiyuan',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('yonghuming', models.CharField(max_length=255, unique=True, verbose_name='用户名')),
('mima', models.CharField(max_length=255, verbose_name='密码')),
('xingming', models.CharField(max_length=255, null=True, verbose_name='姓名')),
('touxiang', models.CharField(max_length=255, null=True, verbose_name='头像')),
('xingbie', models.CharField(max_length=255, null=True, verbose_name='性别')),
('shouji', models.CharField(max_length=255, null=True, verbose_name='手机')),
('chepai', models.CharField(max_length=255, null=True, verbose_name='车牌')),
],
options={
'verbose_name': '会员',
'verbose_name_plural': '会员',
'db_table': 'huiyuan',
},
),
migrations.CreateModel(
name='messages',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('userid', models.BigIntegerField(verbose_name='留言人id')),
('username', models.CharField(max_length=255, null=True, verbose_name='用户名')),
('content', models.TextField(verbose_name='留言内容')),
('reply', models.TextField(null=True, verbose_name='回复内容')),
],
options={
'verbose_name': '留言板',
'verbose_name_plural': '留言板',
'db_table': 'messages',
},
),
migrations.CreateModel(
name='news',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('title', models.CharField(max_length=255, verbose_name='标题')),
('introduction', models.TextField(null=True, verbose_name='简介')),
('picture', models.CharField(max_length=255, verbose_name='图片')),
('content', models.TextField(verbose_name='内容')),
],
options={
'verbose_name': '公告信息',
'verbose_name_plural': '公告信息',
'db_table': 'news',
},
),
migrations.CreateModel(
name='ruchangtingche',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('cheweibianhao', models.CharField(max_length=255, verbose_name='车位编号')),
('cheweimingcheng', models.CharField(max_length=255, null=True, verbose_name='车位名称')),
('cheweileixing', models.CharField(max_length=255, null=True, verbose_name='车位类型')),
('cheweitupian', models.CharField(max_length=255, null=True, verbose_name='车位图片')),
('cheweiweizhi', models.CharField(max_length=255, null=True, verbose_name='车位位置')),
('cheweizhuangtai', models.CharField(max_length=255, null=True, verbose_name='车位状态')),
('shoufeibiaozhun', models.CharField(max_length=255, null=True, verbose_name='收费标准')),
('tingchejiage', models.IntegerField(null=True, verbose_name='停车价格')),
('ruchangshijian', models.DateTimeField(verbose_name='入场时间')),
('ruchangbeizhu', models.CharField(max_length=255, null=True, verbose_name='入场备注')),
('yonghuming', models.CharField(max_length=255, null=True, verbose_name='用户名')),
('shouji', models.CharField(max_length=255, null=True, verbose_name='手机')),
('chepai', models.CharField(max_length=255, null=True, verbose_name='车牌')),
('sfsh', models.CharField(default='', max_length=255, null=True, verbose_name='是否审核')),
('shhf', models.TextField(null=True, verbose_name='审核回复')),
],
options={
'verbose_name': '入场停车',
'verbose_name_plural': '入场停车',
'db_table': 'ruchangtingche',
},
),
migrations.CreateModel(
name='storeup',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
('userid', models.BigIntegerField(verbose_name='用户id')),
('refid', models.BigIntegerField(null=True, verbose_name='收藏id')),
('tablename', models.CharField(max_length=255, null=True, verbose_name='表名')),
('name', models.CharField(max_length=255, verbose_name='收藏名称')),
('picture', models.CharField(max_length=255, verbose_name='收藏图片')),
],
options={
'verbose_name': '收藏表',
'verbose_name_plural': '收藏表',
'db_table': 'storeup',
},
),
migrations.CreateModel(
name='users',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=100, verbose_name='账号')),
('password', models.CharField(max_length=100, verbose_name='密码')),
('role', models.CharField(max_length=100, verbose_name='角色')),
('addtime', models.DateTimeField(verbose_name='创建时间')),
],
options={
'verbose_name': '管理员表',
'verbose_name_plural': '管理员表',
'db_table': 'users',
},
),
]

@ -1,647 +0,0 @@
# coding:utf-8
__author__ = "ila"
import copy, re, time
import logging as log
from django.db import models
from django.forms.models import model_to_dict
from django.core.paginator import Paginator
from django.db.models import ProtectedError
from threadlocals.threadlocals import get_current_request
from django.db.models import Sum, Max, Min, Avg,Count
# model基础类
class BaseModel(models.Model):
class Meta:
abstract = True
def __Retrieve(self, model):
datas = model.objects.all()
return self.to_list(datas, datas)
def retrieve(self, model):
datas=self.__Retrieve(model, model)
for i in datas:
addtime=i.get("addtime")
if addtime:
addtime=str(addtime)[:19].replace("T"," ")
i["addtime"]=addtime
return datas
def __Page(self, model, params):
'''
刷表专用
http://ip:port/${schemaName}/${tableName}/page
page 当前页
pagesize 每页记录的长度
sort 排序字段,写死在这,如果刷表出错立马崩溃
order 升序默认asc或者降序desc
:param req_dict:
:return:
'''
sort = copy.deepcopy(params.get('sort'))
if sort is None:
sort='id'
order = copy.deepcopy(params.get('order'))
page = copy.deepcopy(params.get('page')) if params.get('page') != None else 1
limit = copy.deepcopy(params.get('limit')) if params.get('limit') != None else 666
try:
del params['sort']
except:
pass
try:
del params['order']
except:
pass
try:
del params['page']
except:
pass
try:
del params['limit']
except:
pass
try:
__sort__ = model.__sort__
except:
__sort__ = None
# 手工实现模糊搜索orz
fuzzy_key, fuzzy_val = None, None
print(params)
for k, v in params.items():
if "%" in str(v):
fuzzy_key = copy.deepcopy(k)
fuzzy_val = copy.deepcopy(v)
fuzzy_val = fuzzy_val.replace("%", "")
if fuzzy_key != None:
del params[fuzzy_key]
# __authSeparate__此属性为真params添加userid只查询个人数据
# try:
# __authSeparate__ = model.__authSeparate__
# except:
# __authSeparate__ = None
# #所有属性为"是"时才有效
# if __authSeparate__=='是':
# request = get_current_request()
# params["userid"] = request.session.get("params").get("id")
if sort != None or __sort__ != None:
if sort == None:
sort = __sort__
if order=='desc':
# 传参判断,需要逆序
datas = model.objects.filter(
**params
).order_by("-{}".format(sort)).all()
else:
# 传参无逆序要求
datas = model.objects.filter(
**params
).order_by("{}".format(sort)).all()
else:
datas = model.objects.filter(
**params
).all()
p = Paginator(datas, int(limit))
try:
p2 = p.page(int(page))
datas = p2.object_list
except:
datas=[]
pages = p.num_pages
try:
data = self.to_list(datas, datas)
except Exception as e:
print(Exception, ":", e)
data = []
newData = []
if fuzzy_key is None:
newData = data
total = p.count
else:
total = 0
for i in data:
for k, v in i.items():
if k == fuzzy_key and fuzzy_val in v:
newData.append(i)
total+=1
# __authTables__
if params.get("tablename") == 'users':
return newData, datas.page, pages, datas.total, datas.per_page
newDataa = []
if hasattr(self, "__authTables__") and self.__authTables__ != {}:
par_keys = params.keys()
authtables_keys = self.__authTables__.keys()
list1 = list(set(par_keys).intersection(set(authtables_keys)))
if len(list1) > 0:
for i in newData:
if i.get(list1[0]) == params.get(list1[0]):
newDataa.append(i)
else:
newDataa = newData
else:
newDataa = newData
return newDataa, page, pages, total, limit
def page(self, model, params):
return self.__Page(self, model, params)
def __GetByColumn(self, model, columnName):
# data1= model.query.options(load_only(column)).all()
datas = model.objects.values(columnName).all()
print(datas)
data_set = set()
for i in datas:
data_set.add(i.get(columnName))
return list(data_set)
def getbyColumn(self, model, columnName):
'''
获取某表的某个字段的内容列表去重
:param model:
:param column:
:return:
'''
return self.__GetByColumn(self, model, columnName)
def __CreateByReq(self, model, params):
'''
根据请求参数创建对应模型记录的公共方法
:param model:
:param params:
:return:
'''
if model.__tablename__ != 'users':
params['id'] = int(float(time.time()) * 1000)
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "bigintegerfield":
column_list.append(col.name)
for k, v in params.items():
if k in column_list:
try:
params[k] = int(v)
except:
params[k] = 0
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "integerfield":
column_list.append(col.name)
for k, v in params.items():
if k in column_list :
try:
params[k] = int(v)
except:
params[k] = 0
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "floatfield":
column_list.append(col.name)
for k, v in params.items():
if k in column_list :
try:
params[k] = float(v)
except:
params[k] = 0.0
column_list = []
for col in model._meta.fields:
if 'char' in str(col.get_internal_type()).lower():
column_list.append(col.name)
for k, v in params.items():
if k in column_list and v == '':
params[k] = ""
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "datetimefield" or str(col.get_internal_type()).lower() == "datefield":
column_list.append(col.name)
params_=copy.deepcopy(params)
for k, v in params_.items():
if k in column_list and v == '':
del params[k]
userid = False
for col in model._meta.fields:
if str(col.name) == 'userid':
if col.null == False:
userid = True
if userid == True:
if params.get("userid") == "" or params.get("userid") == None:
request = get_current_request()
params['userid'] = request.session.get("params").get('id')
for col in model._meta.fields:
if str(col.name) not in params.keys():
if col.null == False:
if "VarChar" in str(col.get_internal_type()) or "Char" in str(col.get_internal_type()):
params[str(col.name)] = ""
column_list = []
for col in model._meta.fields:
column_list.append(col.name)
paramss={}
for k, v in params.items():
if k in column_list:
paramss[k] = v
m = model(**paramss)
try:
ret = m.save()
log.info("ret========>{}".format(ret))
return None
except Exception as e:
return "{}:{}".format(Exception, e)
def createbyreq(self, model, params):
'''
根据请求参数创建对应模型记录
:param model:
:param params:
:return:
'''
return self.__CreateByReq(model, model, params)
def __GetById(self, model, id):
'''
根据id获取数据公共方法
:param id:
:return:
'''
data = model.objects.filter(id=id).all()
return self.to_list(model, data)
def getbyid(self, model, id):
'''
根据id获取数据
:param model:
:param id:
:return:
'''
return self.__GetById(model, model, id)
def __GetByParams(self, model, params):
try:
__loginUser__ = model.__loginUser__
except:
__loginUser__ = None
if __loginUser__ != None:
if params.get('username'):
params[model.__loginUser__] = copy.deepcopy(params.get('username'))
del params['username']
if model.__tablename__ != 'users':
if params.get('password'):
params['mima'] = copy.deepcopy(params.get('password'))
del params['password']
# 前端传了无用参数和传错参数名,在这里修改
paramss = {}
columnList = self.getallcolumn(model, model)
for k, v in params.items():
if k in columnList:
paramss[k] = v
datas_ = model.objects.filter(**paramss).all()
return self.to_list(datas_, datas_)
def getbyparams(self, model, params):
return self.__GetByParams(model, model, params)
def __GetBetweenParams(self, model, columnName, params):
'''
:param model:
:param params:
:return:
'''
print("__GetBetweenParams params=============>",params)
remindstart = copy.deepcopy(params.get("remindstart"))
remindend = copy.deepcopy(params.get("remindend"))
try:
del params["remindstart"]
del params["remindend"]
del params["type"]
except:
pass
# todo where是否合法
datas = eval("model.objects.filter(**params).filter({}__range= [remindstart, remindend]).all()".format(columnName))
print("datas===========>",datas)
try:
data = [i if i.items else model_to_dict(i) for i in datas]
except:
try:
data = [model_to_dict(i) for i in datas]
except:
data = datas
return data
def getbetweenparams(self, model, columnName, params):
'''
区域内查询
:param model:
:param params:
:return:
'''
return self.__GetBetweenParams(self, model, columnName, params)
def __GetComputedByColumn(self, model, columnName):
return model.objects.aggregate(
sum=Sum(columnName),
max=Max(columnName),
min=Min(columnName),
avg=Avg(columnName),
)
def getcomputedbycolumn(self, model, columnName):
'''
求和最大最小平均值
:param model:
:param columnName:
:return:
'''
return self.__GetComputedByColumn(self, model, columnName)
def __GroupByColumnName(self, model, columnName):
'''
django指定获取那些列:values
统计values里每一个字符串出现的次数
:param model:
:param columnName:
:return:
'''
datas = model.objects.values(columnName).annotate(total=Count(columnName)).all()
try:
data = [model_to_dict(i) for i in datas]
except:
data = datas
data = [{columnName: x.get(columnName), "total": int(x.get("total"))} for x in data]
return data
def groupbycolumnname(self, model, columnName):
'''
类别统计
:param model:
:param params:
:return:
'''
return self.__GroupByColumnName(self, model, columnName)
def __GetValueByxyColumnName(self, model, xColumnName, yColumnName):
'''
按值统计接口
SELECT ${xColumnName}, ${yColumnName} total FROM ${tableName} order by ${yColumnName} desc limit 10
:param model:
:param xColumnName:
:param yColumnName:
:return:
'''
datas = model.objects.values(xColumnName).\
annotate(total=Sum(yColumnName)).all()[:10]
try:
data = list(datas)
except Exception as e:
print(Exception,":",e)
data = datas
return data
def getvaluebyxycolumnname(self, model, xColumnName, yColumnName):
'''
:param model:
:param xColumnName:
:param yColumnName:
:return:
'''
return self.__GetValueByxyColumnName(self, model, xColumnName, yColumnName)
def __UpdateByParams(self, model, params):
'''
根据接口传参更新对应id记录的公共方法
:param model:
:param params:
:return:
'''
id_ = copy.deepcopy(params['id'])
del params['id']
# 去掉多传的参数
column_list = self.getallcolumn(model,model) # 获取所有字段名
newParams = {}
for k, v in params.items():
if k in column_list:
ret1 = re.findall("\d{4}-\d{2}-\d{2}", str(v))
ret2 = re.findall("\d{2}:\d{2}:\d{2}", str(v))
if len(ret1) > 0 and len(ret2) > 0:
newParams[k] ="{} {}".format( ret1[0],ret2[0])
else:
newParams[k] = v
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "bigintegerfield":
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list:
try:
newParams[k] = int(v)
except:
newParams[k] = 0
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "integerfield":
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list :
try:
newParams[k] = int(v)
except:
newParams[k] = 0
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "floatfield":
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list :
try:
newParams[k] = float(v)
except:
newParams[k] = 0.0
column_list = []
for col in model._meta.fields:
if 'char' in str(col.get_internal_type()).lower():
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list and v == '':
newParams[k] = ""
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "datetimefield":
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list and v == '':
newParams[k] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "datefield":
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list and v == '':
newParams[k] = time.strftime("%Y-%m-%d", time.localtime(time.time()))
column_list = []
for col in model._meta.fields:
column_list.append(col.name)
paramss = {}
for k, v in newParams.items():
if k in column_list:
paramss[k] = v
try:
model.objects.filter(id=int(id_)).update(
**paramss
)
return None
except Exception as e:
print(Exception, ":", e)
return e
def updatebyparams(self, model, params):
'''
根据接口传参更新对应id记录
:param params:
:return:
'''
return self.__UpdateByParams(model, model, params)
def __Deletes(self, model,ids:list):
'''
删除记录先查询再删除查询结果公共方法
:param user:
:return:
'''
try:
model.objects.filter(id__in =ids).delete()
return None
except Exception as e:
print(Exception, ":", e)
return e
def deletes(self,model, ids:list):
'''
删除记录先查询再删除查询结果
:param user:
:return:
'''
return self.__Deletes(model,model, ids)
def __DeleteByParams(self, model, newParams: dict):
'''
批量删除的内部方法
:param model:
:param params:
:return:
'''
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "integerfield":
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list:
try:
newParams[k] = int(v)
except:
newParams[k] = 0
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "bigintegerfield":
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list:
try:
newParams[k] = int(v)
except:
newParams[k] = 0
column_list = []
for col in model._meta.fields:
if str(col.get_internal_type()).lower() == "floatfield":
column_list.append(col.name)
for k, v in newParams.items():
if k in column_list:
try:
newParams[k] = float(v)
except:
newParams[k] = 0.0
try:
ret = model.objects.filter(**newParams).delete()
log.info("delete===============>{}".format(ret))
return None
except ProtectedError:
return str(ProtectedError)
def deletebyparams(self, model, ids: list):
'''
根据数组传参批量删除一个或多个id的记录
:param model:
:param params:
:return:
'''
return self.__DeleteByParams(model, model, ids)
def to_list(self, datas):
dataList = []
try:
dataList = [model_to_dict(i) for i in datas]
# for i in datas_:
# datas.append(model_to_dict(i))
except Exception as e:
print(Exception, ":", e)
return dataList
def getallcolumn(self, model):
"""
获取当前模型的所有字段
:returns dict:
"""
column_list = []
for col in model._meta.fields:
column_list.append(col.name)
return column_list

@ -1,325 +0,0 @@
#coding:utf-8
__author__ = "ila"
from django.db import models
from .model import BaseModel
from datetime import datetime
class huiyuan(BaseModel):
__doc__ = u'''huiyuan'''
__tablename__ = 'huiyuan'
__loginUser__='yonghuming'
__authTables__={}
__authPeople__=''#用户表表属性loginUserColumn对应的值就是用户名字段mima就是密码字段
__loginUserColumn__='yonghuming'#用户表表属性loginUserColumn对应的值就是用户名字段mima就是密码字段
__sfsh__=''#表sfsh(是否审核,”是”或”否”)字段和sfhf(审核回复)字段,后台列表(page)的操作中要多一个”审核”按钮点击”审核”弹出一个页面包含”是否审核”和”审核回复”点击确定调用update接口修改sfsh和sfhf两个字段。
__authSeparate__=''#后台列表权限
__thumbsUp__=''#表属性thumbsUp[是/否]新增thumbsupnum赞和crazilynum踩字段
__intelRecom__=''#智能推荐功能(表属性:[intelRecom是/否)],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
__browseClick__=''#表属性[browseClick:是/否]点击字段clicknum调用info/detail接口的时候后端自动+1、投票功能表属性[vote:是/否]投票字段votenum,调用vote接口后端votenum+1
__foreEndListAuth__=''#前台列表权限foreEndListAuth[是/否]当foreEndListAuth=是刷的表新增用户字段userid前台list列表接口仅能查看自己的记录和add接口后台赋值userid的值
__foreEndList__=''#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
__isAdmin__=''#表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
yonghuming=models.CharField ( max_length=255,null=False,unique=True, verbose_name='用户名' )
mima=models.CharField ( max_length=255,null=False, unique=False, verbose_name='密码' )
xingming=models.CharField ( max_length=255, null=True, unique=False, verbose_name='姓名' )
touxiang=models.CharField ( max_length=255, null=True, unique=False, verbose_name='头像' )
xingbie=models.CharField ( max_length=255, null=True, unique=False, verbose_name='性别' )
shouji=models.CharField ( max_length=255, null=True, unique=False, verbose_name='手机' )
chepai=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车牌' )
'''
yonghuming=VARCHAR
mima=VARCHAR
xingming=VARCHAR
touxiang=VARCHAR
xingbie=VARCHAR
shouji=VARCHAR
chepai=VARCHAR
'''
class Meta:
db_table = 'huiyuan'
verbose_name = verbose_name_plural = '会员'
class cheweileixing(BaseModel):
__doc__ = u'''cheweileixing'''
__tablename__ = 'cheweileixing'
__authTables__={}
__authPeople__=''#用户表表属性loginUserColumn对应的值就是用户名字段mima就是密码字段
__sfsh__=''#表sfsh(是否审核,”是”或”否”)字段和sfhf(审核回复)字段,后台列表(page)的操作中要多一个”审核”按钮点击”审核”弹出一个页面包含”是否审核”和”审核回复”点击确定调用update接口修改sfsh和sfhf两个字段。
__authSeparate__=''#后台列表权限
__thumbsUp__=''#表属性thumbsUp[是/否]新增thumbsupnum赞和crazilynum踩字段
__intelRecom__=''#智能推荐功能(表属性:[intelRecom是/否)],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
__browseClick__=''#表属性[browseClick:是/否]点击字段clicknum调用info/detail接口的时候后端自动+1、投票功能表属性[vote:是/否]投票字段votenum,调用vote接口后端votenum+1
__foreEndListAuth__=''#前台列表权限foreEndListAuth[是/否]当foreEndListAuth=是刷的表新增用户字段userid前台list列表接口仅能查看自己的记录和add接口后台赋值userid的值
__foreEndList__=''#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
__isAdmin__=''#表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
cheweileixing=models.CharField ( max_length=255,null=False,unique=True, verbose_name='车位类型' )
'''
cheweileixing=VARCHAR
'''
class Meta:
db_table = 'cheweileixing'
verbose_name = verbose_name_plural = '车位类型'
class cheweixinxi(BaseModel):
__doc__ = u'''cheweixinxi'''
__tablename__ = 'cheweixinxi'
__authTables__={}
__authPeople__=''#用户表表属性loginUserColumn对应的值就是用户名字段mima就是密码字段
__sfsh__=''#表sfsh(是否审核,”是”或”否”)字段和sfhf(审核回复)字段,后台列表(page)的操作中要多一个”审核”按钮点击”审核”弹出一个页面包含”是否审核”和”审核回复”点击确定调用update接口修改sfsh和sfhf两个字段。
__authSeparate__=''#后台列表权限
__thumbsUp__=''#表属性thumbsUp[是/否]新增thumbsupnum赞和crazilynum踩字段
__intelRecom__=''#智能推荐功能(表属性:[intelRecom是/否)],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
__browseClick__=''#表属性[browseClick:是/否]点击字段clicknum调用info/detail接口的时候后端自动+1、投票功能表属性[vote:是/否]投票字段votenum,调用vote接口后端votenum+1
__foreEndListAuth__=''#前台列表权限foreEndListAuth[是/否]当foreEndListAuth=是刷的表新增用户字段userid前台list列表接口仅能查看自己的记录和add接口后台赋值userid的值
__foreEndList__=''#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
__isAdmin__=''#表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
cheweibianhao=models.CharField ( max_length=255,null=False,unique=True, verbose_name='车位编号' )
cheweimingcheng=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位名称' )
cheweileixing=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位类型' )
cheweitupian=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位图片' )
cheweiweizhi=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位位置' )
cheweizhuangtai=models.CharField ( max_length=255,null=False, unique=False, verbose_name='车位状态' )
tingchejiage=models.IntegerField ( null=False, unique=False, verbose_name='停车价格' )
shoufeibiaozhun=models.CharField ( max_length=255, null=True, unique=False, verbose_name='收费标准' )
cheweixiangqing=models.TextField ( null=True, unique=False, verbose_name='车位详情' )
'''
cheweibianhao=VARCHAR
cheweimingcheng=VARCHAR
cheweileixing=VARCHAR
cheweitupian=VARCHAR
cheweiweizhi=VARCHAR
cheweizhuangtai=VARCHAR
tingchejiage=Integer
shoufeibiaozhun=VARCHAR
cheweixiangqing=Text
'''
class Meta:
db_table = 'cheweixinxi'
verbose_name = verbose_name_plural = '车位信息'
class cheweiweihu(BaseModel):
__doc__ = u'''cheweiweihu'''
__tablename__ = 'cheweiweihu'
__authTables__={}
__authPeople__=''#用户表表属性loginUserColumn对应的值就是用户名字段mima就是密码字段
__sfsh__=''#表sfsh(是否审核,”是”或”否”)字段和sfhf(审核回复)字段,后台列表(page)的操作中要多一个”审核”按钮点击”审核”弹出一个页面包含”是否审核”和”审核回复”点击确定调用update接口修改sfsh和sfhf两个字段。
__authSeparate__=''#后台列表权限
__thumbsUp__=''#表属性thumbsUp[是/否]新增thumbsupnum赞和crazilynum踩字段
__intelRecom__=''#智能推荐功能(表属性:[intelRecom是/否)],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
__browseClick__=''#表属性[browseClick:是/否]点击字段clicknum调用info/detail接口的时候后端自动+1、投票功能表属性[vote:是/否]投票字段votenum,调用vote接口后端votenum+1
__foreEndListAuth__=''#前台列表权限foreEndListAuth[是/否]当foreEndListAuth=是刷的表新增用户字段userid前台list列表接口仅能查看自己的记录和add接口后台赋值userid的值
__foreEndList__=''#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
__isAdmin__=''#表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
cheweibianhao=models.CharField ( max_length=255,null=False, unique=False, verbose_name='车位编号' )
cheweimingcheng=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位名称' )
cheweileixing=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位类型' )
cheweiweizhi=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位位置' )
weihuleixing=models.CharField ( max_length=255,null=False, unique=False, verbose_name='维护类型' )
weihuxiangmu=models.CharField ( max_length=255, null=True, unique=False, verbose_name='维护项目' )
weihushijian=models.DateTimeField ( null=False, unique=False, verbose_name='维护时间' )
weihuxiangqing=models.TextField ( null=True, unique=False, verbose_name='维护详情' )
'''
cheweibianhao=VARCHAR
cheweimingcheng=VARCHAR
cheweileixing=VARCHAR
cheweiweizhi=VARCHAR
weihuleixing=VARCHAR
weihuxiangmu=VARCHAR
weihushijian=DateTime
weihuxiangqing=Text
'''
class Meta:
db_table = 'cheweiweihu'
verbose_name = verbose_name_plural = '车位维护'
class ruchangtingche(BaseModel):
__doc__ = u'''ruchangtingche'''
__tablename__ = 'ruchangtingche'
__authTables__={'yonghuming':'huiyuan',}
__authPeople__=''#用户表表属性loginUserColumn对应的值就是用户名字段mima就是密码字段
__sfsh__=''#表sfsh(是否审核,”是”或”否”)字段和sfhf(审核回复)字段,后台列表(page)的操作中要多一个”审核”按钮点击”审核”弹出一个页面包含”是否审核”和”审核回复”点击确定调用update接口修改sfsh和sfhf两个字段。
__authSeparate__=''#后台列表权限
__thumbsUp__=''#表属性thumbsUp[是/否]新增thumbsupnum赞和crazilynum踩字段
__intelRecom__=''#智能推荐功能(表属性:[intelRecom是/否)],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
__browseClick__=''#表属性[browseClick:是/否]点击字段clicknum调用info/detail接口的时候后端自动+1、投票功能表属性[vote:是/否]投票字段votenum,调用vote接口后端votenum+1
__foreEndListAuth__=''#前台列表权限foreEndListAuth[是/否]当foreEndListAuth=是刷的表新增用户字段userid前台list列表接口仅能查看自己的记录和add接口后台赋值userid的值
__foreEndList__=''#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
__isAdmin__=''#表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
cheweibianhao=models.CharField ( max_length=255,null=False, unique=False, verbose_name='车位编号' )
cheweimingcheng=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位名称' )
cheweileixing=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位类型' )
cheweitupian=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位图片' )
cheweiweizhi=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位位置' )
cheweizhuangtai=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位状态' )
shoufeibiaozhun=models.CharField ( max_length=255, null=True, unique=False, verbose_name='收费标准' )
tingchejiage=models.IntegerField ( null=True, unique=False, verbose_name='停车价格' )
ruchangshijian=models.DateTimeField ( null=False, unique=False, verbose_name='入场时间' )
ruchangbeizhu=models.CharField ( max_length=255, null=True, unique=False, verbose_name='入场备注' )
yonghuming=models.CharField ( max_length=255, null=True, unique=False, verbose_name='用户名' )
shouji=models.CharField ( max_length=255, null=True, unique=False, verbose_name='手机' )
chepai=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车牌' )
sfsh=models.CharField ( max_length=255, null=True, unique=False,default='', verbose_name='是否审核' )
shhf=models.TextField ( null=True, unique=False, verbose_name='审核回复' )
'''
cheweibianhao=VARCHAR
cheweimingcheng=VARCHAR
cheweileixing=VARCHAR
cheweitupian=VARCHAR
cheweiweizhi=VARCHAR
cheweizhuangtai=VARCHAR
shoufeibiaozhun=VARCHAR
tingchejiage=Integer
ruchangshijian=DateTime
ruchangbeizhu=VARCHAR
yonghuming=VARCHAR
shouji=VARCHAR
chepai=VARCHAR
sfsh=VARCHAR
shhf=Text
'''
class Meta:
db_table = 'ruchangtingche'
verbose_name = verbose_name_plural = '入场停车'
class chuchangjiaofei(BaseModel):
__doc__ = u'''chuchangjiaofei'''
__tablename__ = 'chuchangjiaofei'
__authTables__={'yonghuming':'huiyuan',}
__authPeople__=''#用户表表属性loginUserColumn对应的值就是用户名字段mima就是密码字段
__sfsh__=''#表sfsh(是否审核,”是”或”否”)字段和sfhf(审核回复)字段,后台列表(page)的操作中要多一个”审核”按钮点击”审核”弹出一个页面包含”是否审核”和”审核回复”点击确定调用update接口修改sfsh和sfhf两个字段。
__authSeparate__=''#后台列表权限
__thumbsUp__=''#表属性thumbsUp[是/否]新增thumbsupnum赞和crazilynum踩字段
__intelRecom__=''#智能推荐功能(表属性:[intelRecom是/否)],新增clicktime[前端不显示该字段]字段调用info/detail接口的时候更新按clicktime排序查询)
__browseClick__=''#表属性[browseClick:是/否]点击字段clicknum调用info/detail接口的时候后端自动+1、投票功能表属性[vote:是/否]投票字段votenum,调用vote接口后端votenum+1
__foreEndListAuth__=''#前台列表权限foreEndListAuth[是/否]当foreEndListAuth=是刷的表新增用户字段userid前台list列表接口仅能查看自己的记录和add接口后台赋值userid的值
__foreEndList__=''#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
__isAdmin__=''#表属性isAdmin=”是”,刷出来的用户表也是管理员即page和list可以查看所有人的考试记录(同时应用于其他表)
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
cheweibianhao=models.CharField ( max_length=255,null=False, unique=False, verbose_name='车位编号' )
cheweimingcheng=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位名称' )
cheweileixing=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位类型' )
cheweitupian=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车位图片' )
tingchejiage=models.IntegerField ( null=True, unique=False, verbose_name='停车价格' )
ruchangshijian=models.CharField ( max_length=255, null=True, unique=False, verbose_name='入场时间' )
chuchangshijian=models.DateTimeField ( null=False, unique=False, verbose_name='出场时间' )
tingcheshizhang=models.IntegerField ( null=False, unique=False, verbose_name='停车时长' )
tingchefeiyong=models.IntegerField ( null=True, unique=False, verbose_name='停车费用' )
xinxibeizhu=models.CharField ( max_length=255, null=True, unique=False, verbose_name='信息备注' )
yonghuming=models.CharField ( max_length=255, null=True, unique=False, verbose_name='用户名' )
shouji=models.CharField ( max_length=255, null=True, unique=False, verbose_name='手机' )
chepai=models.CharField ( max_length=255, null=True, unique=False, verbose_name='车牌' )
sfsh=models.CharField ( max_length=255, null=True, unique=False,default='', verbose_name='是否审核' )
shhf=models.TextField ( null=True, unique=False, verbose_name='审核回复' )
ispay=models.CharField ( max_length=255, null=True, unique=False,default='未支付', verbose_name='是否支付' )
'''
cheweibianhao=VARCHAR
cheweimingcheng=VARCHAR
cheweileixing=VARCHAR
cheweitupian=VARCHAR
tingchejiage=Integer
ruchangshijian=VARCHAR
chuchangshijian=DateTime
tingcheshizhang=Integer
tingchefeiyong=Integer
xinxibeizhu=VARCHAR
yonghuming=VARCHAR
shouji=VARCHAR
chepai=VARCHAR
sfsh=VARCHAR
shhf=Text
ispay=VARCHAR
'''
class Meta:
db_table = 'chuchangjiaofei'
verbose_name = verbose_name_plural = '出场缴费'
class storeup(BaseModel):
__doc__ = u'''storeup'''
__tablename__ = 'storeup'
__authTables__={}
__authSeparate__=''#后台列表权限
__foreEndListAuth__=''#前台列表权限foreEndListAuth[是/否]当foreEndListAuth=是刷的表新增用户字段userid前台list列表接口仅能查看自己的记录和add接口后台赋值userid的值
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
userid=models.BigIntegerField ( null=False, unique=False, verbose_name='用户id' )
refid=models.BigIntegerField ( null=True, unique=False, verbose_name='收藏id' )
tablename=models.CharField ( max_length=255, null=True, unique=False, verbose_name='表名' )
name=models.CharField ( max_length=255,null=False, unique=False, verbose_name='收藏名称' )
picture=models.CharField ( max_length=255,null=False, unique=False, verbose_name='收藏图片' )
'''
userid=BigInteger
refid=BigInteger
tablename=VARCHAR
name=VARCHAR
picture=VARCHAR
'''
class Meta:
db_table = 'storeup'
verbose_name = verbose_name_plural = '收藏表'
class news(BaseModel):
__doc__ = u'''news'''
__tablename__ = 'news'
__authTables__={}
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
title=models.CharField ( max_length=255,null=False, unique=False, verbose_name='标题' )
introduction=models.TextField ( null=True, unique=False, verbose_name='简介' )
picture=models.CharField ( max_length=255,null=False, unique=False, verbose_name='图片' )
content=models.TextField ( null=False, unique=False, verbose_name='内容' )
'''
title=VARCHAR
introduction=Text
picture=VARCHAR
content=Text
'''
class Meta:
db_table = 'news'
verbose_name = verbose_name_plural = '公告信息'
class messages(BaseModel):
__doc__ = u'''messages'''
__tablename__ = 'messages'
__authTables__={}
__hasMessage__=''#表属性hasMessage为是新增留言板表messages,字段content内容userid用户id
__foreEndListAuth__=''#前台列表权限foreEndListAuth[是/否]当foreEndListAuth=是刷的表新增用户字段userid前台list列表接口仅能查看自己的记录和add接口后台赋值userid的值
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
userid=models.BigIntegerField ( null=False, unique=False, verbose_name='留言人id' )
username=models.CharField ( max_length=255, null=True, unique=False, verbose_name='用户名' )
content=models.TextField ( null=False, unique=False, verbose_name='留言内容' )
reply=models.TextField ( null=True, unique=False, verbose_name='回复内容' )
'''
userid=BigInteger
username=VARCHAR
content=Text
reply=Text
'''
class Meta:
db_table = 'messages'
verbose_name = verbose_name_plural = '留言板'

@ -1,499 +0,0 @@
# coding:utf-8
__author__ = "ila"
import logging, os, time
from django.http import JsonResponse
from django.apps import apps
from wsgiref.util import FileWrapper
from django.http import HttpResponse,HttpResponseRedirect
from django.shortcuts import redirect
from .config_model import config
from util.codes import *
from util import message as mes
from util.baidubce_api import BaiDuBce
from util.locate import geocoding
from dj2.settings import dbName as schemaName
def schemaName_cal(request, tableName, columnName):
'''
计算规则接口
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, 'data': []}
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
data = m.getcomputedbycolumn(
m,
m,
columnName
)
print(data)
if data:
try:
sum='%.05f' % float(data.get("sum"))
except:
sum=0.00
try:
max='%.05f' % float(data.get("max"))
except:
max=0.00
try:
min='%.05f' % float(data.get("min"))
except:
min=0.00
try:
avg='%.05f' % float(data.get("avg"))
except:
avg=0.00
msg['data'] = {
"sum": sum,
"max": max,
"min": min,
"avg": avg,
}
break
return JsonResponse(msg)
def schemaName_file_upload(request):
'''
上传
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
file = request.FILES.get("file")
if file:
filename = file.name
filesuffix = filename.split(".")[-1]
file_name = "{}.{}".format(int(float(time.time()) * 1000), filesuffix)
filePath = os.path.join(os.getcwd(), "templates/front", file_name)
print("filePath===========>", filePath)
with open(filePath, 'wb+') as destination:
for chunk in file.chunks():
destination.write(chunk)
msg["file"] = file_name
# 判断是否需要保存为人脸识别基础照片
req_dict = request.session.get("req_dict")
type1 = req_dict.get("type", 0)
print("type1=======>",type1)
type1 = int(type1)
if type1 == 1:
params = {"name":"faceFile","value": file_name}
config.createbyreq(config, config, params)
return JsonResponse(msg)
def schemaName_file_download(request):
'''
下载
'''
if request.method in ["POST", "GET"]:
req_dict = request.session.get("req_dict")
filename = req_dict.get("fileName")
filePath = os.path.join(os.getcwd(), "templates/front", filename)
print("filePath===========>", filePath)
file = open(filePath, 'rb')
response = HttpResponse(file)
response['Content-Type'] = 'text/plain'
response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(filePath)
response['Content-Length'] = os.path.getsize(filePath)
return response
def schemaName_follow_level(request, tableName, columnName, level, parent):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, 'data': []}
# 组合查询参数
params = {
"level": level,
"parent": parent
}
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
data = m.getbyparams(
m,
m,
params
)
# 只需要此列的数据
for i in data:
msg['data'].append(i.get(columnName))
break
return JsonResponse(msg)
def schemaName_follow(request, tableName, columnName):
'''
根据option字段值获取某表的单行记录接口
组合columnName和columnValue成dict传入查询方法
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, 'data': []}
# 组合查询参数
params = request.session.get('req_dict')
columnValue = params.get("columnValue")
params = {columnName: columnValue}
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
data = m.getbyparams(
m,
m,
params
)
if len(data)>0:
msg['data'] = data[0]
break
return JsonResponse(msg)
def schemaName_location(request):
'''
定位
:return:
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "address": ''}
req_dict = request.session.get('req_dict')
datas = config.getbyparams(config, config, {"name": "baidu_ditu_ak"})
if len(datas) > 0:
baidu_ditu_ak = datas[0].get("baidu_ditu_ak")
else:
baidu_ditu_ak = 'QvMZVORsL7sGzPyTf5ZhawntyjiWYCif'
lat = req_dict.get("lat", 24.2943350100)
lon = req_dict.get("lng", 116.1287866600)
msg['address'] = geocoding(baidu_ditu_ak, lat, lon)
return JsonResponse(msg)
def schemaName_matchface(request):
'''
baidubce百度人脸识别
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code}
req_dict = request.session.get("req_dict")
face1 = req_dict.get("face1")
file_path1 = os.path.join(os.getcwd(),"templates/front",face1)
face2 = req_dict.get("face1")
file_path2 = os.path.join(os.getcwd(), "templates/front", face2)
data = config.getbyparams(config, config, {"name": "APIKey"})
client_id = data[0].get("APIKey")
data = config.getbyparams(config, config, {"name": "SecretKey"})
client_secret = data[0].get("SecretKey")
bdb = BaiDuBce()
score = bdb.bd_check2pic(client_id, client_secret, file_path1, file_path2)
msg['score'] = score
return JsonResponse(msg)
def schemaName_option(request, tableName, columnName):
'''
获取某表的某个字段列表接口
:param request:
:param tableName:
:param columnName:
:return:
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, 'data': []}
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
data = m.getbyColumn(
m,
m,
columnName
)
msg['data'] = data
break
return JsonResponse(msg)
def schemaName_remind_tablename_columnname_type(request, tableName, columnName, type)->int:
'''
前台提醒接口通用接口不需要登陆
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, 'data': []}
# 组合查询参数
params = request.session.get("req_dict")
remindstart = int(params.get('remindstart')) if params.get('remindstart') != None else None
remindend = int(params.get('remindend')) if params.get('remindend') != None else None
if int(type) == 1: # 数字
if remindstart == None and remindend != None:
params['remindstart'] = 0
elif remindstart != None and remindend == None:
params['remindend'] = 999999
elif remindstart == None and remindend == None:
params['remindstart'] = 0
params['remindend'] = 999999
elif int(type) == 2: # 日期
current_time = int(time.time())
if remindstart == None and remindend != None:
starttime = current_time - 60 * 60 * 24 * 365 * 2
params['remindstart'] = time.strftime("%Y-%m-%d", time.localtime(starttime))
endtime = current_time + 60 * 60 * 24 * remindend
params['remindend'] = time.strftime("%Y-%m-%d", time.localtime(endtime))
elif remindstart != None and remindend == None:
starttime = current_time - 60 * 60 * 24 * remindstart
params['remindstart'] = time.strftime("%Y-%m-%d", time.localtime(starttime))
endtime = current_time + 60 * 60 * 24 * 365 * 2
params['remindend'] = time.strftime("%Y-%m-%d", time.localtime(endtime))
elif remindstart == None and remindend == None:
starttime = current_time - 60 * 60 * 24 * 365 * 2
params['remindstart'] = time.strftime("%Y-%m-%d", time.localtime(starttime))
endtime = current_time + 60 * 60 * 24 * 365 * 2
params['remindend'] = time.strftime("%Y-%m-%d", time.localtime(endtime))
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
data = m.getbetweenparams(
m,
m,
columnName,
params
)
msg['count'] = len(data)
break
return JsonResponse(msg)
def schemaName_tablename_remind_columnname_type(request, tableName, columnName, type):
'''
后台提醒接口判断authSeparate和authTable的权限
'''
if request.method in ["POST", "GET"]:
print("schemaName_tablename_remind_columnname_type==============>")
msg = {"code": normal_code, 'data': []}
req_dict = request.session.get("req_dict")
remindstart = int(req_dict.get('remindstart')) if req_dict.get('remindstart')!=None else None
remindend = int(req_dict.get('remindend')) if req_dict.get('remindend')!=None else None
print("req_dict===================>",req_dict)
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
tableModel=m
break
# 获取全部列名
columns = tableModel.getallcolumn(tableModel, tableModel)
# 当前登录用户所在表
tablename = request.session.get("tablename")
# 当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致]则对应的表有个隐藏属性authTable为”是”那么该用户查看该表信息时只能查看自己的
try:
__authTables__ =tableModel.__authTables__
except:
__authTables__ = {}
if __authTables__ != {}:
for authColumn, authTable in __authTables__.items():
if authTable == tablename:
params = request.session.get("params")
req_dict[authColumn] = params.get(authColumn)
break
'''__authSeparate__此属性为真params添加userid后台只查询个人数据'''
try:
__authSeparate__ =tableModel.__authSeparate__
except:
__authSeparate__ = None
if __authSeparate__ == "":
tablename = request.session.get("tablename")
if tablename != "users" and 'userid' in columns:
try:
req_dict['userid'] = request.session.get("params").get("id")
except:
pass
# 组合查询参数
if int(type) == 1: # 数字
if remindstart == None and remindend != None:
req_dict['remindstart'] = 0
elif remindstart != None and remindend == None:
req_dict['remindend'] = 999999
elif remindstart == None and remindend == None:
req_dict['remindstart'] = 0
req_dict['remindend'] = 999999
elif int(type) == 2: # 日期
current_time = int(time.time())
if remindstart == None and remindend != None:
starttime = current_time - 60 * 60 * 24 * 365 * 2
req_dict['remindstart'] = time.strftime("%Y-%m-%d", time.localtime(starttime))
endtime = current_time + 60 * 60 * 24 * remindend
req_dict['remindend'] = time.strftime("%Y-%m-%d", time.localtime(endtime))
elif remindstart != None and remindend == None:
starttime = current_time - 60 * 60 * 24 * remindstart
req_dict['remindstart'] = time.strftime("%Y-%m-%d", time.localtime(starttime))
endtime = current_time + 60 * 60 * 24 * 365 * 2
req_dict['remindend'] = time.strftime("%Y-%m-%d", time.localtime(endtime))
elif remindstart == None and remindend == None:
starttime = current_time - 60 * 60 * 24 * 365 * 2
req_dict['remindstart'] = time.strftime("%Y-%m-%d", time.localtime(starttime))
endtime = current_time + 60 * 60 * 24 * 365 * 2
req_dict['remindend'] = time.strftime("%Y-%m-%d", time.localtime(endtime))
else:
starttime = current_time - 60 * 60 * 24 * remindstart
req_dict['remindstart'] = time.strftime("%Y-%m-%d", time.localtime(starttime))
endtime = current_time + 60 * 60 * 24 * remindend
req_dict['remindend'] = time.strftime("%Y-%m-%d", time.localtime(endtime))
print("req_dict==============>",req_dict)
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
data = m.getbetweenparams(
m,
m,
columnName,
req_dict
)
msg['count'] = len(data)
break
return JsonResponse(msg)
def schemaName_sh(request, tableName):
'''
根据主键id修改table表的sfsh状态接口
'''
if request.method in ["POST", "GET"]:
print('tableName=========>', tableName)
msg = {"code": normal_code, "msg": "成功", "data": {}}
req_dict = request.session.get("req_dict")
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
# 查询结果
data1 = m.getbyid(
m,
m,
req_dict.get('id')
)
if data1[0].get("sfsh") == '':
req_dict['sfsh'] = ''
else:
req_dict['sfsh'] = ''
# 更新
res = m.updatebyparams(
m,
m,
req_dict
)
# logging.warning("schemaName_sh.res=====>{}".format(res))
if res!=None:
msg["code"]=crud_error_code
msg["code"]=mes.crud_error_code
break
return JsonResponse(msg)
def schemaName_upload(request, fileName):
'''
'''
if request.method in ["POST", "GET"]:
return HttpResponseRedirect ("/{}/front/{}".format(schemaName,fileName))
def schemaName_group_quyu(request, tableName, columnName):
'''
{
"code": 0,
"data": [
{
"total": 2,
"shangpinleibie": "水果"
},
{
"total": 1,
"shangpinleibie": "蔬菜"
}
]
}
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
msg['data'] = m.groupbycolumnname(
m,
m,
columnName
)
break
return JsonResponse(msg)
def schemaName_value_quyu(request, tableName, xColumnName, yColumnName):
'''
按值统计接口,
{
"code": 0,
"data": [
{
"total": 10.0,
"shangpinleibie": "aa"
},
{
"total": 20.0,
"shangpinleibie": "bb"
},
{
"total": 15.0,
"shangpinleibie": "cc"
}
]
}
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__ == tableName:
msg['data'] = m.getvaluebyxycolumnname(
m,
m,
xColumnName,
yColumnName
)
break
return JsonResponse(msg)

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

@ -1,148 +0,0 @@
# coding:utf-8
__author__ = "ila"
import os
from django.urls import path
from main import users_v, config_v, schema_v
# from dj2.settings import dbName as schemaName
# url规则列表
urlpatterns = [
path(r'users/register', users_v.users_register),
path(r'users/login', users_v.users_login),
path(r'users/logout', users_v.users_logout),
path(r'users/session', users_v.users_session),
path(r'users/page', users_v.users_page),
path(r'users/save', users_v.users_save),
path(r'users/info/<id_>', users_v.users_info),
path(r'users/update', users_v.users_update),
path(r'users/delete', users_v.users_delete),
path(r'config/page', config_v.config_page),
path(r'config/list', config_v.config_list),
path(r'config/save', config_v.config_save),
path(r'config/add', config_v.config_add),
path(r'config/info/<id_>', config_v.config_info),
path(r'config/detail/<id_>', config_v.config_detail),
path(r'config/update', config_v.config_update),
path(r'config/delete', config_v.config_delete),
]
# main app的路径
mainDir = os.path.join(os.getcwd(), "main")
# 过滤文件的列表
excludeList = [
"schema_v.py",
"users_v.py",
"config_v.py",
]
# 循环当前目录下的py文件
view_tuple = set()
for i in os.listdir(mainDir):
if i not in excludeList and i[-5:] == "_v.py":
viewName = i[:-3] # 去掉.py后缀字符串
view_tuple.add("from main import {}".format(viewName))
# 组合成import字符串
import_str = '\n'.join(view_tuple)
# print(import_str)
exec(import_str)
for i in os.listdir(mainDir):
if i not in excludeList and i[-5:] == "_v.py":
tableName = i[:-5]
tableName = tableName.replace(" ", "").strip()
print("tableName============>", tableName, len(tableName))
urlpatterns.extend(
[
path(r'{}/register'.format(tableName.lower()),
eval("{}_v.{}_register".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/login'.format(tableName.lower()),
eval("{}_v.{}_login".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/logout'.format(tableName.lower()),
eval("{}_v.{}_logout".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/resetPass'.format(tableName.lower()),
eval("{}_v.{}_resetPass".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/session'.format(tableName.lower()),
eval("{}_v.{}_session".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/default'.format(tableName.lower()),
eval("{}_v.{}_default".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/page'.format(tableName.lower()),
eval("{}_v.{}_page".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/autoSort'.format(tableName.lower()),
eval("{}_v.{}_autoSort".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/save'.format(tableName.lower()),
eval("{}_v.{}_save".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/add'.format(tableName.lower()),
eval("{}_v.{}_add".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/thumbsup/<id_>'.format(tableName.lower()),
eval("{}_v.{}_thumbsup".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/info/<id_>'.format(tableName.lower()),
eval("{}_v.{}_info".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/detail/<id_>'.format(tableName.lower()),
eval("{}_v.{}_detail".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/update'.format(tableName.lower()),
eval("{}_v.{}_update".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/delete'.format(tableName.lower()),
eval("{}_v.{}_delete".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/vote/<id_>'.format(tableName.lower()),
eval("{}_v.{}_vote".format(tableName.capitalize(), tableName.lower()))),
]
)
# examrecord特定接口
if tableName.lower() == "examrecord":
urlpatterns.extend(
[
path(r'{}/groupby'.format(tableName.lower()),
eval("{}_v.{}_groupby".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/deleteRecords'.format(tableName.lower()),
eval("{}_v.{}_deleterecords".format(tableName.capitalize(), tableName.lower()))),
]
)
# forum特定接口
if tableName.lower() == "forum":
urlpatterns.extend(
[
path(r'{}/flist'.format(tableName.lower()),
eval("{}_v.{}_flist".format(tableName.capitalize(), tableName.lower()))),
path(r'{}/list/<id_>'.format(tableName.lower()),
eval("{}_v.{}_list_id".format(tableName.capitalize(), tableName.lower()))),
]
)
else:
urlpatterns.extend(
[
path(r'{}/list'.format(tableName.lower()),
eval("{}_v.{}_list".format(tableName.capitalize(), tableName.lower()))),
]
)
urlpatterns.extend(
[
path(r'cal/<str:tableName>/<str:columnName>', schema_v.schemaName_cal),
path(r'file/download', schema_v.schemaName_file_download),
path(r'file/upload', schema_v.schemaName_file_upload),
path(r'follow/<tableName>/<columnName>/<level>/<parent>', schema_v.schemaName_follow_level),
path(r'follow/<tableName>/<columnName>', schema_v.schemaName_follow),
path(r'location', schema_v.schemaName_location),
path(r'matchFace', schema_v.schemaName_matchface),
path(r'option/<tableName>/<columnName>', schema_v.schemaName_option),
path(r'remind/<tableName>/<columnName>/<type>', schema_v.schemaName_remind_tablename_columnname_type),
# 前台提醒接口(通用接口,不需要登陆)
path(r'<tableName>/remind/<columnName>/<type>', schema_v.schemaName_tablename_remind_columnname_type),
# 后台提醒接口 (每个表的单独接口,需登录)
path(r'sh/<tableName>', schema_v.schemaName_sh),
path(r'upload/<fileName>', schema_v.schemaName_upload),
path(r'group/<tableName>/<columnName>', schema_v.schemaName_group_quyu),
path(r'value/<tableName>/<xColumnName>/<yColumnName>', schema_v.schemaName_value_quyu),
]
)
# print(urlpatterns)

@ -1,22 +0,0 @@
# coding:utf-8
__author__ = "ila"
from django.db import models
from .model import BaseModel
class users(BaseModel):
# id=models.BigIntegerField(verbose_name="自增id")
username = models.CharField(max_length=100, verbose_name=u'账号')
password = models.CharField(max_length=100, verbose_name=u'密码')
role = models.CharField(max_length=100, verbose_name=u'角色')
addtime = models.DateTimeField(auto_now_add=False, verbose_name=u'创建时间')
__tablename__ = 'users'
class Meta:
db_table = 'users'
verbose_name = verbose_name_plural = u'管理员表'
# def __str__(self):
# return self.username

@ -1,161 +0,0 @@
# coding:utf-8
__author__ = "ila"
from django.http import JsonResponse
from .users_model import users
from util.codes import *
from util.auth import Auth
import util.message as mes
def users_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
if req_dict.get('role')!=None:
del req_dict['role']
datas = users.getbyparams(users, users, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, users, req_dict)
def users_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = users.createbyreq(users, users, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def users_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg":mes.normal_code, "data": {}}
req_dict = {"id": request.session.get('params').get("id")}
msg['data'] = users.getbyparams(users, users, req_dict)[0]
return JsonResponse(msg)
def users_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "退出成功",
"code": 0
}
return JsonResponse(msg)
def users_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code,
"data": {"currPage": 1, "totalPage": 1, "total": 1, "pageSize": 10, "list": []}}
req_dict = request.session.get("req_dict")
tablename = request.session.get("tablename")
try:
__hasMessage__ = users.__hasMessage__
except:
__hasMessage__ = None
if __hasMessage__ and __hasMessage__ != "":
if tablename != "users":
req_dict["userid"] = request.session.get("params").get("id")
if tablename == "users":
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = users.page(users, users, req_dict)
else:
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = [],1,0,0,10
return JsonResponse(msg)
def users_info(request, id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = users.getbyid(users, users, int(id_))
if len(data) > 0:
msg['data'] = data[0]
# 浏览点击次数
try:
__browseClick__ = users.__browseClick__
except:
__browseClick__ = None
if __browseClick__ and "clicknum" in users.getallcolumn(users, users):
click_dict = {"id": int(id_), "clicknum": str(int(data[0].get("clicknum", 0)) + 1)}
ret = users.updatebyparams(users, users, click_dict)
if ret != None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def users_save(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error = users.createbyreq(users, users, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def users_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in users.getallcolumn(users,users):
del req_dict["mima"]
if "password" not in users.getallcolumn(users,users):
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = users.updatebyparams(users, users, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def users_delete(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error = users.deletes(users,
users,
req_dict.get("ids")
)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.
Loading…
Cancel
Save