Skip to content

Commit

Permalink
重构项目目录
Browse files Browse the repository at this point in the history
  • Loading branch information
296452965 committed Dec 12, 2022
1 parent 2396494 commit 075b12a
Show file tree
Hide file tree
Showing 274 changed files with 182 additions and 122 deletions.
4 changes: 3 additions & 1 deletion .flaskenv
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
FLASK_APP = bulletin_board
FLASK_ENV=development
# FLASK_APP=app
FLASK_APP = "app:create_app('development')"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ fabric.properties

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

*.env
Empty file removed admin/__init__.py
Empty file.
47 changes: 47 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
from flask import Flask, url_for, redirect
from flask_login import LoginManager
from flask_migrate import Migrate

from config import config
from app.department.models import db


def create_app(config_name=None):
app = Flask(__name__, static_url_path='')
configure_app(app, config_name) # 导入参数设置
db.init_app(app) # 初始化绑定app对象
migrate = Migrate(app, db)
login_manager = LoginManager(app)
login_manager.login_view = 'login.login'
login_manager.login_message = '访问页面需要登录'

@login_manager.user_loader
def load_user(user_id):
# from .department.models import Department
from app.department.models import Department
dep = Department.query.get(int(user_id))
return dep

# 引入蓝图并注册
from app import login, admin, user, department, commands
app.register_blueprint(login.bp) # 注册登录页面视图
app.register_blueprint(admin.admin) # 注册管理员页面视图
app.register_blueprint(user.user) # 注册用户页面视图
app.register_blueprint(department.department) # 注册部门管理页面视图
app.register_blueprint(commands.bp) # 注册部门管理页面视图

# 注册首页路由
@app.route('/')
def hello_world():
return redirect(url_for('login.login'))

return app


def configure_app(app, config_name=None):
if config_name is None:
config_name = os.environ.get('FLASK_ENV', 'development')
if config_name in config:
app.config.from_object(config[config_name])

5 changes: 5 additions & 0 deletions app/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Blueprint

admin = Blueprint('admin', __name__, url_prefix='/admin/')

from .views import *
File renamed without changes.
3 changes: 2 additions & 1 deletion admin/models.py → app/admin/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# flask-sqlalchemy的基本使用
from exts import db
# db的引用关系: exts<-admin<-department
from app.exts import db


# 柱状图数据表
Expand Down
14 changes: 5 additions & 9 deletions admin/views.py → app/admin/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
from flask import Blueprint, render_template, jsonify, request, session, redirect, url_for, flash, send_file
from flask import render_template, jsonify, request, session, redirect, url_for, flash, send_file
from flask.views import MethodView
from flask_login import login_required, current_user
from io import BytesIO
from functools import wraps
import time
import xlsxwriter
import os

# from exts import db
# from admin.models import DataBar, DataLine, Content, Category1, Category2, Unit, Document, Filetype
from admin.models import *
from admin.forms import DocumentForm
from settings import UPLOAD_FOLDER

admin = Blueprint('admin', __name__, url_prefix='/admin/')
from . import admin
from .models import *
from .forms import DocumentForm
from config import UPLOAD_FOLDER


def is_admin(f):
Expand Down
14 changes: 6 additions & 8 deletions commands.py → app/commands.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from bulletin_board import app, db
import click
from department.models import Department
from flask import Blueprint
from app.department.models import db, Department

bp = Blueprint('commands',__name__)

@app.cli.command()

@bp.cli.command()
@click.option('--username', prompt=True, help='The username used to login.')
@click.option('--password', prompt=True, hide_input=True, confirmation_prompt=True, help='The password used to login.')
def admin(username, password):
Expand All @@ -22,8 +24,4 @@ def admin(username, password):
db.session.add(admin)

db.session.commit() # 提交数据库会话
click.echo('Create Admin Done.')


if __name__ == '__main__':
admin()
click.echo('Create Admin Done.')
5 changes: 5 additions & 0 deletions app/department/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Blueprint

department = Blueprint('department', __name__, url_prefix='/')

from .views import *
File renamed without changes.
2 changes: 1 addition & 1 deletion department/models.py → app/department/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from admin.models import db
from app.admin.models import db
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import UserMixin
db = db # 赋值给一变量,否则系统会只找到admin应用的db
Expand Down
8 changes: 4 additions & 4 deletions department/views.py → app/department/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from flask.views import MethodView
from flask_login import login_required

from department.forms import DepartmentForm
from department.models import Department, db
from admin.models import Unit
from .forms import DepartmentForm
from .models import Department, db
from app.admin.models import Unit
from . import department

department = Blueprint('department', __name__, url_prefix='/department/')


# 部门详情
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions app/login/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Blueprint

bp = Blueprint('login', __name__, url_prefix='/')

from .views import *
5 changes: 2 additions & 3 deletions login/views.py → app/login/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from flask import Blueprint, session, redirect, url_for, request, flash, render_template
from flask_login import login_user, logout_user, login_required
from department.models import Department

bp = Blueprint('login', __name__, url_prefix='/')
from app.department.models import Department
from . import bp


# 登录页面,使用flask-login
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 7 additions & 5 deletions templates/user/case.html → app/templates/user/case.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@
</tr>
</thead>
<tbody>
<tr>
{% for doc in documents %}
{% for doc in documents %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ doc.filename }}</td>
<td>
<a class="btn btn-primary btn-sm" href="{{ url_for('user.document_download',fid=doc.id) }}"><span class="mdi mdi-download"></span>下载文件</a>
<a class="btn btn-primary btn-sm"
href="{{ url_for('user.document_download',fid=doc.id) }}"><span
class="mdi mdi-download"></span>下载文件</a>
</td>
{% endfor %}
</tr>
</tr>
{% endfor %}
</tbody>
</table>
</div>
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions templates/user/inform.html → app/templates/user/inform.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
</tr>
</thead>
<tbody>
<tr>
{% for doc in documents %}
{% for doc in documents %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ doc.filename }}</td>
<td>
<a class="btn btn-primary btn-sm" href="{{ url_for('user.document_download',fid=doc.id) }}"><span class="mdi mdi-download"></span>下载文件</a>
</td>
{% endfor %}
</tr>
</tr>
{% endfor %}
</tbody>
</table>
</div>
Expand Down
12 changes: 7 additions & 5 deletions templates/user/policy.html → app/templates/user/policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@
</tr>
</thead>
<tbody>
<tr>
{% for doc in documents %}
{% for doc in documents %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ doc.filename }}</td>
<td>
<a class="btn btn-primary btn-sm" href="{{ url_for('user.document_download',fid=doc.id) }}"><span class="mdi mdi-download"></span>下载文件</a>
<a class="btn btn-primary btn-sm"
href="{{ url_for('user.document_download',fid=doc.id) }}"><span
class="mdi mdi-download"></span>下载文件</a>
</td>
{% endfor %}
</tr>
</tr>
{% endfor %}
</tbody>
</table>
</div>
Expand Down
File renamed without changes.
34 changes: 19 additions & 15 deletions templates/user/video.html → app/templates/user/video.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@
</tr>
</thead>
<tbody>
<tr>
{% for doc in documents %}
{% for doc in documents %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ doc.filename }}</td>
<td>
<a class="btn btn-primary btn-sm" href="{{ url_for('user.document_download',fid=doc.id) }}"><span class="mdi mdi-download"></span>下载文件</a>
<a class="btn btn-primary btn-sm" href="{{ url_for('user.video_watch',fid=doc.id) }}"><span class="mdi mdi-video"></span>在线观看</a>
<a class="btn btn-primary btn-sm"
href="{{ url_for('user.document_download',fid=doc.id) }}"><span
class="mdi mdi-download"></span>下载文件</a>
<a class="btn btn-primary btn-sm"
href="{{ url_for('user.video_watch',fid=doc.id) }}"><span
class="mdi mdi-video"></span>在线观看</a>
</td>
{% endfor %}
</tr>
</tr>
{% endfor %}
</tbody>
</table>
</div>
Expand All @@ -52,13 +56,13 @@
</div>
{% endblock %}
{% block js_ext %}
<script type="text/javascript">
$(function(){
$('.search-bar .dropdown-menu a').click(function() {
var field = $(this).data('field') || '';
$('#search-field').val(field);
$('#search-btn').html($(this).text() + ' <span class="caret"></span>');
});
});
</script>
<script type="text/javascript">
$(function () {
$('.search-bar .dropdown-menu a').click(function () {
var field = $(this).data('field') || '';
$('#search-field').val(field);
$('#search-btn').html($(this).text() + ' <span class="caret"></span>');
});
});
</script>
{% endblock %}
File renamed without changes.
5 changes: 5 additions & 0 deletions app/user/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Blueprint

user = Blueprint('user', __name__, url_prefix='/user/')

from .views import *
7 changes: 3 additions & 4 deletions user/views.py → app/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from flask.views import MethodView
import os

from admin.models import *
from settings import UPLOAD_FOLDER

user = Blueprint('user', __name__, url_prefix='/user/')
from app.admin.models import *
from config import UPLOAD_FOLDER
from . import user


# 用户页面主页
Expand Down
40 changes: 0 additions & 40 deletions bulletin_board.py

This file was deleted.

49 changes: 49 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os

basedir = os.path.abspath(os.path.dirname(__file__))
HOST = os.environ.get('HOST')
PORT = os.environ.get('PORT')
USER = os.environ.get('USER')
PASSWORD = os.environ.get('PASSWORD')
CHARSET = os.environ.get('CHARSET')

# 上传配置
UPLOAD_FOLDER = os.environ.get('UPLOAD_FOLDER')
MAX_CONTENT_LENGTH = 128 * 1024 * 1024 # 128MB


class BaseConfig:
# SQLALCHEMY配置
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = False


class DevelopmentConfig(BaseConfig):
SECRET_KEY = 'dev'
DEBUG = True
DATABASE = 'cyk_flask'
DB_URI = 'mysql+pymysql://{}:{}@{}:{}/{}?{}'.format(USER, PASSWORD, HOST, PORT, DATABASE, CHARSET)
SQLALCHEMY_DATABASE_URI = DB_URI


class TestingConfig(BaseConfig):
SECRET_KEY = 'test'
DATABASE = 'cyk_flask_test'
DB_URI = 'mysql+pymysql://{}:{}@{}:{}/{}?{}'.format(USER, PASSWORD, HOST, PORT, DATABASE, CHARSET)
SQLALCHEMY_DATABASE_URI = DB_URI


class ProductionConfig(BaseConfig):
SECRET_KEY = os.environ.get('SECRET_KEY')
DATABASE = 'cyk_flask'
DB_URI = 'mysql+pymysql://{}:{}@{}:{}/{}?{}'.format(USER, PASSWORD, HOST, PORT, DATABASE, CHARSET)
SQLALCHEMY_DATABASE_URI = DB_URI


config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': DevelopmentConfig
}

Empty file removed department/__init__.py
Empty file.
Empty file removed login/__init__.py
Empty file.
Loading

0 comments on commit 075b12a

Please sign in to comment.