from app.service import service_select
from app.core.mysql import MysqlPool
import json
import csv
import ast
import os
mysqlPool = MysqlPool()
# 帮助方法,合并对象
def obj_update(*config):
config_temp = {}
for o in config:
config_temp.update(o)
return config_temp
# 权限集合
dict_auth = {}
# 控制器父类
class Controller:
def __init__(self, config):
"""
构造函数
@param {Dictionary} config 配置参数
"""
# 配置参数
self.config = config or {}
# 添加服务
self.service = service_select(self.config["service"])
cg = {
# 选择的模板那路径模板
"tpl":
"./index/",
# 选择的服务
"service":
"user",
# 注册get请求路由
"get": ["list", "view", "table"],
# 注册post请求路由
"post": [],
# 注册get api路由
"get_api": [
"del",
"get_list",
"get_obj",
"count",
"count_group",
"sum",
"sum_group",
"avg",
"avg_group",
"list_group",
"bar_group"
],
# 注册post api路由
"post_api": ["add", "del", "set", "import_db", "export_db", "upload"],
"interact": [],
"unique": []
}
if config:
if "interact" in config:
config["interact"].extend(cg["interact"])
else:
config["interact"] = cg["interact"]
if "get" in config:
config["get"].extend(cg["get"])
else:
config["get"] = cg["get"]
if "post" in config:
config["post"].extend(cg["post"])
else:
config["post"] = cg["post"]
if "get_api" in config:
config["get_api"].extend(cg["get_api"])
else:
config["get_api"] = cg["get_api"]
if "post_api" in config:
config["post_api"].extend(cg["post_api"])
else:
config["post_api"] = cg["post_api"]
if "unique" in config:
config["unique"].extend(cg["unique"])
else:
config["unique"] = cg["unique"]
# 公共模型,用于在render()为传递模板数据补充
def model(self, ctx, model):
m = {}
m.update(model)
#
# model_temp.user = ctx.session.user
# 获取导航
service = service_select("nav")
m["nav_top"] = service.Get_list({"location": "top"})
m["nav_side"] = service.Get_list({"location": "side"})
m["nav_foot"] = service.Get_list({"location": "foot"})
# 获取轮播图
service = service_select("slides")
m["list_slides"] = service.Get_list({})
# 获取公告
service = service_select("notice")
m["list_notice"] = service.Get_list({},
{"orderby": "`update_time` desc"})
# 交互模型接口
if ("interact" in self.config) and self.config["interact"]:
m = self.model_interact(ctx, m)
m["query"] = ctx.query
m["body"] = ctx.body
m["auth"] = ctx.auth
return m
# 交互对象
def interact_obj(self, ctx, o):
interact = self.config["interact"]
if interact:
source_table = service_select(
self.config["service"]).config["table"]
source_field = source_table + "_id"
# 评论
if "comment" in interact:
service = service_select("comment")
source_id = o[source_field]
o["comment_list"] = service.Get_list(
{
"source_table": source_table,
"source_field": source_field,
"source_id": source_id
}, {
"page": 1,
"size": 10,
})
o["comment_len"] = service.Count({
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
})
# 评分
if "score" in interact:
service = service_select("score")
source_id = o[source_field]
o["score_list"] = service.Get_list(
{
"source_table": source_table,
"source_field": source_field,
"source_id": source_id
}, {
"page": 1,
"size": 10,
})
o["score_len"] = service.Avg(
{
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
},
{"field": "score_num"},
)
# 收藏
if "collect" in interact:
service = service_select("collect")
source_id = o[source_field]
o["collect_list"] = service.Get_list(
{
"source_table": source_table,
"source_field": source_field,
"source_id": source_id
}, {
"page": 1,
"size": 10,
})
o["collect_len"] = service.Count({
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
})
# 点赞
if "praise" in interact:
service = service_select("praise")
source_id = o[source_field]
o["praise_list"] = service.Get_list(
{
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
}, {
"page": 1,
"size": 10,
})
o["praise_len"] = service.Count({
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
})
return o
# 交互列表
def interact_list(self, ctx, list_1):
interact = self.config["interact"]
if interact:
source_table = service_select(
self.config["service"]).config["table"]
source_field = source_table + "_id"
# 评论数
if "comment" in interact:
service = service_select("comment")
for o in list_1:
source_id = o[source_field]
o["comment_len"] = service.Count({
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
})
# 平均分
if "score" in interact:
service = service_select("score")
for o in list_1:
source_id = o[source_field]
o["score_len"] = service.Avg(
{
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
},
{"field": "score_num"},
)
# 收藏人数
if "collect" in interact:
service = service_select("collect")
for o in list_1:
source_id = o[source_field]
o["collect_len"] = service.Count({
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
})
# 点赞人数
if "praise" in interact:
service = service_select("praise")
for o in list_1:
source_id = o[source_field]
o["praise_len"] = service.Count({
"source_table": source_table,
"source_field": source_field,
"source_id": source_id,
})
# 交互模型
def model_interact(self, ctx, m):
if ("list" in m) and m["list"]:
self.interact_list(ctx, m["list"])
elif ("obj" in m) and m["obj"]:
self.interact_obj(ctx, m["obj"])
return m
"""
公共参数校验
"""
def Check_param(self, ctx):
return True
# 首页
def Index(self, ctx):
"""首页
@param {Object} ctx http请求上下文
@return {Object} 返回html页面
"""
query = dict(ctx.query)
config_plus = {}
if "field" in query:
field = query.pop("field")
config_plus["field"] = field
if "page" in query:
page = query.pop("page")
config_plus["page"] = page
if "size" in query:
size = query.pop("size")
config_plus["size"] = size
result_list = self.service.Get_list(
query, obj_update(self.config, config_plus))
result_dict = {"list": result_list}
model = self.model(ctx, result_dict)
return ctx.render(self.config["tpl"] + "index" + ".html", model)
def Api(self, ctx):
return {"demo": "hello world!"}
# 列表页面
def List(self, ctx):
"""
列表页面
@param {Object} ctx http请求上下文
@return {Object} 返回html页面
"""
query = dict(ctx.query)
config_plus = {}
if "field" in query:
field = query.pop("field")
config_plus["field"] = field
if "page" in query:
page = query.pop("page")
config_plus["page"] = page
if "size" in query:
size = query.pop("size")
config_plus["size"] = size
result_list = self.service.Get_list(
query, obj_update(
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
Python校园疫情监控平台(源码+数据库)290915 (584个子文件)
preview.bat 582B
deploy.bat 452B
deploy.bat 452B
preview.bat 209B
preview.bat 209B
生成依赖表.bat 93B
设置镜像源.bat 62B
运行.bat 39B
安装.bat 31B
安裝sass.bat 16B
运行.bat 13B
安装.bat 12B
安装.bat 11B
运行.bat 11B
无源安装.bat 5B
.browserslistrc 33B
bootstrap.min.css 158KB
diy.css 89KB
base.css 89KB
base.css 88KB
bootstrap-icons.css 61KB
font-awesome.min.css 30KB
diy.css 21KB
theme.css 14KB
theme.css 14KB
common.css 996B
bootstrap-treeview.min.css 204B
fontawesome-webfont.eot 162KB
banner_1.gif 31KB
banner_2.gif 31KB
index.html 628B
index.html 628B
favicon.ico 4KB
favicon.ico 4KB
link_7.jfif 23KB
auth_bg.jpeg 19KB
微信图片_20201005131254.jpg 11.16MB
微信图片_20201005131240.jpg 10.15MB
微信图片_20201005131247.jpg 8.82MB
news_img_1.jpg 2.81MB
jingdian (8).jpg 2.05MB
jingdian (8).jpg 2.05MB
jingdian (4)_1.jpg 1.76MB
jingdian (4).jpg 1.76MB
jingdian (4)_1.jpg 1.76MB
jingdian (4).jpg 1.76MB
jingdian (3).jpg 1.47MB
jingdian (3).jpg 1.47MB
slide4.jpg 1.02MB
undefinedjingdian (5).jpg 559KB
undefinedjingdian (5).jpg 559KB
fuwuyuan03.jpg 498KB
img2.jpg 456KB
slide3.jpg 456KB
fuwuyuan05.jpg 431KB
undefinedjingdian (1).jpg 407KB
undefinedjingdian (1).jpg 407KB
slide2.jpg 400KB
slide5.jpg 375KB
jingdian (10)_2.jpg 368KB
jingdian (10)_1.jpg 368KB
jingdian (10).jpg 368KB
jingdian (10)_2.jpg 368KB
jingdian (10)_1.jpg 368KB
jingdian (10).jpg 368KB
jingdian (11)_12.jpg 319KB
jingdian (11)_11.jpg 319KB
jingdian (11)_13.jpg 319KB
jingdian (11)_6.jpg 319KB
jingdian (11)_4.jpg 319KB
jingdian (11)_5.jpg 319KB
jingdian (11)_8.jpg 319KB
jingdian (11)_9.jpg 319KB
jingdian (11)_10.jpg 319KB
jingdian (11)_2.jpg 319KB
jingdian (11)_1.jpg 319KB
jingdian (11)_3.jpg 319KB
jingdian (11).jpg 319KB
jingdian (11)_7.jpg 319KB
undefinedjingdian (11).jpg 319KB
jingdian (11)_12.jpg 319KB
jingdian (11)_11.jpg 319KB
jingdian (11)_13.jpg 319KB
jingdian (11)_6.jpg 319KB
jingdian (11)_4.jpg 319KB
jingdian (11)_5.jpg 319KB
jingdian (11)_8.jpg 319KB
jingdian (11)_9.jpg 319KB
jingdian (11)_10.jpg 319KB
jingdian (11)_2.jpg 319KB
jingdian (11)_1.jpg 319KB
jingdian (11)_3.jpg 319KB
jingdian (11).jpg 319KB
jingdian (11)_7.jpg 319KB
undefinedjingdian (11).jpg 319KB
1.jpg 271KB
img.jpg 262KB
slide1.jpg 262KB
img3.jpg 262KB
user_avatar_11.jpg 253KB
共 584 条
- 1
- 2
- 3
- 4
- 5
- 6
FYKJ_2010
- 粉丝: 3922
- 资源: 711
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 汽车级带驱动保护芯片规格书
- 基于matlab实现遗传算法优化bp神经网络权值阈值的MATLAB程序.rar
- 基于matlab实现遗传算法优化BP网络(用于电力负荷预测预测).rar
- 基于matlab实现用于speech enhancement的经典噪声估计源代码完整,可直接使用 .rar
- 基于matlab实现振动信号预处理,主要为五点三次平滑法和平均法.rar
- 基于matlab实现直流电机双闭环控制matlab程序,双闭环能增加系统的动态响应,提升控制性能.rar
- 基于matlab实现直流电机的闭环控制,通过simulink的仿真,来设置pid参数,达到成功的控制直流电机的运行 .rar
- 基于matlab实现在振动信号处理中的应用,书籍和源码 工程振动信号的预处理以及模态参数的识别程序.rar
- Sora关于视频分镜的提示词技巧.docx
- 基于java的Saas OA协同办公软件源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0