mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 04:26:23 +03:00
Backend: добавлена базовая админка
This commit is contained in:
@@ -3,6 +3,7 @@ cffi==1.15.1
|
|||||||
click==8.1.3
|
click==8.1.3
|
||||||
cryptography==38.0.3
|
cryptography==38.0.3
|
||||||
Flask==2.2.2
|
Flask==2.2.2
|
||||||
|
Flask-Admin==1.6.0
|
||||||
Flask-Migrate==4.0.0
|
Flask-Migrate==4.0.0
|
||||||
Flask-SQLAlchemy==3.0.2
|
Flask-SQLAlchemy==3.0.2
|
||||||
greenlet==2.0.1
|
greenlet==2.0.1
|
||||||
@@ -16,4 +17,5 @@ pycparser==2.21
|
|||||||
PyMySQL==1.0.2
|
PyMySQL==1.0.2
|
||||||
SQLAlchemy==1.4.44
|
SQLAlchemy==1.4.44
|
||||||
Werkzeug==2.2.2
|
Werkzeug==2.2.2
|
||||||
|
WTForms==3.0.1
|
||||||
zipp==3.10.0
|
zipp==3.10.0
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import json
|
|||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_migrate import Migrate
|
from flask_migrate import Migrate
|
||||||
|
from flask_admin import Admin
|
||||||
|
|
||||||
from textsouls.models import db
|
from textsouls.models import db
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ app = Flask(
|
|||||||
)
|
)
|
||||||
|
|
||||||
migrate = Migrate(app, db)
|
migrate = Migrate(app, db)
|
||||||
|
admin = Admin(name="TextSouls")
|
||||||
|
|
||||||
with open("textsouls/config.json") as config_file:
|
with open("textsouls/config.json") as config_file:
|
||||||
config_data = json.load(config_file)
|
config_data = json.load(config_file)
|
||||||
@@ -20,8 +22,12 @@ app.config.update(main_settings)
|
|||||||
db_settings = config_data["db_settings"]
|
db_settings = config_data["db_settings"]
|
||||||
app.config.update(db_settings)
|
app.config.update(db_settings)
|
||||||
|
|
||||||
|
admin.init_app(app)
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
|
|
||||||
|
from .admin import ts_admin as ts_admin_blueprint
|
||||||
|
|
||||||
|
app.register_blueprint(ts_admin_blueprint)
|
||||||
|
|
||||||
from .main import main as main_blueprint
|
from .main import main as main_blueprint
|
||||||
|
|
||||||
|
|||||||
10
backend/textsouls/admin.py
Normal file
10
backend/textsouls/admin.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from flask import Blueprint
|
||||||
|
from flask_admin.contrib.sqla import ModelView
|
||||||
|
|
||||||
|
from . import admin
|
||||||
|
from textsouls.models import db
|
||||||
|
from textsouls.models import User
|
||||||
|
|
||||||
|
ts_admin = Blueprint("ts_admin", __name__)
|
||||||
|
|
||||||
|
admin.add_view(ModelView(User, db.session))
|
||||||
@@ -14,20 +14,7 @@ class User(db.Model):
|
|||||||
first_name = db.Column(db.String(255), nullable=True)
|
first_name = db.Column(db.String(255), nullable=True)
|
||||||
last_name = db.Column(db.String(255), nullable=True)
|
last_name = db.Column(db.String(255), nullable=True)
|
||||||
username = db.Column(db.String(255), nullable=False)
|
username = db.Column(db.String(255), nullable=False)
|
||||||
registered_on = db.Column(db.DateTime, nullable=False)
|
registered_on = db.Column(
|
||||||
|
db.DateTime, nullable=False, default=datetime.datetime.now()
|
||||||
|
)
|
||||||
is_admin = db.Column(db.Boolean, nullable=False, default=False)
|
is_admin = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
tg_id,
|
|
||||||
first_name,
|
|
||||||
last_name,
|
|
||||||
username,
|
|
||||||
is_admin=False,
|
|
||||||
):
|
|
||||||
self.tg_id = tg_id
|
|
||||||
self.first_name = first_name
|
|
||||||
self.last_name = last_name
|
|
||||||
self.username = username
|
|
||||||
self.registered_on = datetime.datetime.now()
|
|
||||||
self.is_admin = is_admin
|
|
||||||
|
|||||||
Reference in New Issue
Block a user