精简功能
This commit is contained in:
@@ -498,71 +498,6 @@ powerdata = [
|
||||
create_time=now_time,
|
||||
enable=1,
|
||||
|
||||
), Power(
|
||||
id=52,
|
||||
name='定时任务',
|
||||
type='0',
|
||||
code='',
|
||||
url='',
|
||||
open_type='',
|
||||
parent_id='0',
|
||||
icon='layui-icon layui-icon-log',
|
||||
sort=3,
|
||||
create_time=now_time,
|
||||
enable=1,
|
||||
|
||||
), Power(
|
||||
id=53,
|
||||
name='任务管理',
|
||||
type='1',
|
||||
code='admin:task:main',
|
||||
url='/admin/task',
|
||||
open_type='_iframe',
|
||||
parent_id='52',
|
||||
icon='layui-icon ',
|
||||
sort=1,
|
||||
create_time=now_time,
|
||||
enable=1,
|
||||
|
||||
), Power(
|
||||
id=54,
|
||||
name='任务增加',
|
||||
type='2',
|
||||
code='admin:task:add',
|
||||
url='',
|
||||
open_type='',
|
||||
parent_id='53',
|
||||
icon='layui-icon ',
|
||||
sort=1,
|
||||
create_time=now_time,
|
||||
enable=1,
|
||||
|
||||
), Power(
|
||||
id=55,
|
||||
name='任务修改',
|
||||
type='2',
|
||||
code='admin:task:edit',
|
||||
url='',
|
||||
open_type='',
|
||||
parent_id='53',
|
||||
icon='layui-icon ',
|
||||
sort=2,
|
||||
create_time=now_time,
|
||||
enable=1,
|
||||
|
||||
), Power(
|
||||
id=56,
|
||||
name='任务删除',
|
||||
type='2',
|
||||
code='admin:task:remove',
|
||||
url='',
|
||||
open_type='',
|
||||
parent_id='53',
|
||||
icon='layui-icon ',
|
||||
sort=23,
|
||||
create_time=now_time,
|
||||
enable=1,
|
||||
|
||||
), Power(
|
||||
id=57,
|
||||
name='邮件管理',
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
import os
|
||||
|
||||
import jinja2
|
||||
|
||||
|
||||
class NewViewModular():
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def path_is_exists(self):
|
||||
return os.path.exists(f"applications/view/{self.name.split('/')[0]}")
|
||||
|
||||
def new_dirs(self):
|
||||
if not self.path_is_exists():
|
||||
# 如果不存在则创建目录
|
||||
|
||||
# 创建目录操作函数
|
||||
os.makedirs(f"applications/view/{self.name.split('/')[0]}")
|
||||
|
||||
print(self.name + ' 创建成功')
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def add_view(self):
|
||||
# jinja渲染
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath='applications/common/script/newmodular/template/')
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
TEMPLATE_FILE = "view"
|
||||
template = templateEnv.get_template(TEMPLATE_FILE, )
|
||||
templateVars = {"name": self.name}
|
||||
outputText = template.render(templateVars)
|
||||
with open(f"applications/view/{self.name}.py", "a", encoding='utf-8') as f:
|
||||
f.write(outputText)
|
||||
f.close()
|
||||
|
||||
def add_init(self):
|
||||
# 判断__init__.py
|
||||
if os.path.exists(f"applications/view/{self.name.split('/')[0]}/__init__.py"):
|
||||
with open(f"applications/view/{self.name.split('/')[0]}/__init__.py", "r") as file:
|
||||
lines = file.readlines()
|
||||
print(lines)
|
||||
file.close()
|
||||
import_line_num = 0
|
||||
for line in lines:
|
||||
if 'def' in line:
|
||||
import_line_num = lines.index(line) - 2
|
||||
with open(f"applications/view/{self.name.split('/')[0]}/__init__.py", "w") as file:
|
||||
lines.insert(import_line_num,
|
||||
f"from applications.view.{self.name.replace('/', '.')} import {self.name.replace('/', '_')}\n")
|
||||
print(lines)
|
||||
lines.insert(len(lines) - 1, f" app.register_blueprint({self.name.replace('/', '_')})\n")
|
||||
print(lines)
|
||||
file.writelines(lines)
|
||||
file.close()
|
||||
return True
|
||||
else:
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath='applications/common/script/newmodular/template/')
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
TEMPLATE_FILE = "__init__"
|
||||
template = templateEnv.get_template(TEMPLATE_FILE, )
|
||||
templateVars = {"name": self.name}
|
||||
output = template.render(templateVars)
|
||||
with open(f"applications/view/{self.name.split('/')[0]}/__init__.py", "a", encoding='utf-8') as f:
|
||||
f.write(output)
|
||||
f.close()
|
||||
self.add_root_init()
|
||||
return True
|
||||
|
||||
def add_root_init(self):
|
||||
with open(f"applications/view/__init__.py", "r") as file:
|
||||
lines = file.readlines()
|
||||
file.close()
|
||||
import_line_num = 0
|
||||
for line in lines:
|
||||
if 'def' in line:
|
||||
import_line_num = lines.index(line) - 2
|
||||
with open(f"applications/view/__init__.py", "w") as file:
|
||||
lines.insert(
|
||||
import_line_num,
|
||||
f"from applications.view.{self.name.split('/')[0]} import register_{self.name.split('/')[0]}_views\n")
|
||||
print(lines)
|
||||
lines.insert(len(lines) - 1, f" register_{self.name.split('/')[0]}_views(app)\n")
|
||||
print(lines)
|
||||
file.writelines(lines)
|
||||
file.close()
|
||||
|
||||
def new_view(self):
|
||||
self.new_dirs()
|
||||
self.add_view()
|
||||
self.add_init()
|
||||
@@ -1,6 +0,0 @@
|
||||
from flask import Flask
|
||||
from applications.view.{{name.replace('/','.')}} import {{name.replace('/','_')}}
|
||||
|
||||
|
||||
def register_{{name.split('/')[0]}}_views(app: Flask):
|
||||
app.register_blueprint({{name.replace('/','_')}})
|
||||
@@ -1,8 +0,0 @@
|
||||
from flask import Blueprint
|
||||
|
||||
{{name.replace('/','_')}} = Blueprint('{{name.replace('/','_')}}', __name__, url_prefix='/{{name}}')
|
||||
|
||||
|
||||
@{{name.replace('/','_')}}.route('/')
|
||||
def index():
|
||||
return "这是{{name}}路由"
|
||||
@@ -1,54 +0,0 @@
|
||||
from apscheduler.events import (
|
||||
EVENT_JOB_ADDED,
|
||||
EVENT_JOB_ERROR,
|
||||
EVENT_JOB_EXECUTED,
|
||||
EVENT_JOB_MISSED,
|
||||
EVENT_JOB_REMOVED,
|
||||
EVENT_JOB_SUBMITTED,
|
||||
)
|
||||
|
||||
from applications.extensions.init_apscheduler import scheduler
|
||||
|
||||
|
||||
def job_missed(event):
|
||||
"""Job missed event."""
|
||||
with scheduler.app.app_context():
|
||||
print(event) # noqa: T001
|
||||
|
||||
|
||||
def job_error(event):
|
||||
"""Job error event."""
|
||||
with scheduler.app.app_context():
|
||||
print(event) # noqa: T001
|
||||
|
||||
|
||||
def job_executed(event):
|
||||
"""Job executed event."""
|
||||
with scheduler.app.app_context():
|
||||
print(event) # noqa: T001
|
||||
|
||||
|
||||
def job_added(event):
|
||||
"""Job added event."""
|
||||
with scheduler.app.app_context():
|
||||
print(event) # noqa: T001
|
||||
|
||||
|
||||
def job_removed(event):
|
||||
"""Job removed event."""
|
||||
with scheduler.app.app_context():
|
||||
print(event) # noqa: T001
|
||||
|
||||
|
||||
def job_submitted(event):
|
||||
"""Job scheduled to run event."""
|
||||
with scheduler.app.app_context():
|
||||
print(event) # noqa: T001
|
||||
|
||||
|
||||
scheduler.add_listener(job_missed, EVENT_JOB_MISSED)
|
||||
scheduler.add_listener(job_error, EVENT_JOB_ERROR)
|
||||
scheduler.add_listener(job_executed, EVENT_JOB_EXECUTED)
|
||||
scheduler.add_listener(job_added, EVENT_JOB_ADDED)
|
||||
scheduler.add_listener(job_removed, EVENT_JOB_REMOVED)
|
||||
scheduler.add_listener(job_submitted, EVENT_JOB_SUBMITTED)
|
||||
@@ -1,15 +0,0 @@
|
||||
import datetime
|
||||
|
||||
task_list = ['task2', 'task3', 'task4']
|
||||
|
||||
|
||||
def task2(a, b):
|
||||
print(f'定时任务_1_{a},{b},{datetime.datetime.now()}')
|
||||
|
||||
|
||||
def task3(a, b):
|
||||
print(f'定时任务_2_{a}{b}{datetime.datetime.now()}')
|
||||
|
||||
|
||||
def task4(a, b):
|
||||
print(f'定时任务_4_{a}{b}{datetime.datetime.now()}')
|
||||
Reference in New Issue
Block a user