mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 04:26:23 +03:00
not working mess
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
alembic==1.8.1
|
alembic==1.8.1
|
||||||
|
amqp==5.1.1
|
||||||
|
billiard==3.6.4.0
|
||||||
|
celery==5.2.7
|
||||||
cffi==1.15.1
|
cffi==1.15.1
|
||||||
click==8.1.3
|
click==8.1.3
|
||||||
|
click-didyoumean==0.3.0
|
||||||
|
click-plugins==1.1.1
|
||||||
|
click-repl==0.2.0
|
||||||
cryptography==38.0.3
|
cryptography==38.0.3
|
||||||
Flask==2.2.2
|
Flask==2.2.2
|
||||||
Flask-Admin==1.6.0
|
Flask-Admin==1.6.0
|
||||||
@@ -12,12 +18,18 @@ importlib-metadata==5.0.0
|
|||||||
importlib-resources==5.10.0
|
importlib-resources==5.10.0
|
||||||
itsdangerous==2.1.2
|
itsdangerous==2.1.2
|
||||||
Jinja2==3.1.2
|
Jinja2==3.1.2
|
||||||
|
kombu==5.2.4
|
||||||
Mako==1.2.4
|
Mako==1.2.4
|
||||||
MarkupSafe==2.1.1
|
MarkupSafe==2.1.1
|
||||||
|
prompt-toolkit==3.0.33
|
||||||
pycparser==2.21
|
pycparser==2.21
|
||||||
PyMySQL==1.0.2
|
PyMySQL==1.0.2
|
||||||
|
pytz==2022.6
|
||||||
|
six==1.16.0
|
||||||
SQLAlchemy==1.4.44
|
SQLAlchemy==1.4.44
|
||||||
SQLAlchemy-serializer==1.4.1
|
SQLAlchemy-serializer==1.4.1
|
||||||
|
vine==5.0.0
|
||||||
|
wcwidth==0.2.5
|
||||||
Werkzeug==2.2.2
|
Werkzeug==2.2.2
|
||||||
WTForms==3.0.1
|
WTForms==3.0.1
|
||||||
zipp==3.10.0
|
zipp==3.10.0
|
||||||
|
|||||||
@@ -13,6 +13,19 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"table_name": "sendlists_destionations_statuses",
|
||||||
|
"records": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "В ожидании"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Отправлено"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"table_name": "character_races",
|
"table_name": "character_races",
|
||||||
"records": [
|
"records": [
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
|
||||||
from flask_migrate import Migrate
|
from flask_migrate import Migrate
|
||||||
from flask_admin import Admin
|
|
||||||
|
|
||||||
|
from textsouls.common.database import db
|
||||||
|
from textsouls.common.admin import admin
|
||||||
|
|
||||||
|
from textsouls.actions.api import actions_bp
|
||||||
|
from textsouls.characters.api import characters_bp
|
||||||
|
from textsouls.users.api import users_bp
|
||||||
|
|
||||||
|
|
||||||
app = Flask(
|
app = Flask(
|
||||||
"__name__",
|
"__name__",
|
||||||
)
|
)
|
||||||
db = SQLAlchemy()
|
|
||||||
|
|
||||||
migrate = Migrate(app, db, compare_type=True)
|
migrate = Migrate(app, db, compare_type=True)
|
||||||
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)
|
||||||
@@ -22,17 +27,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)
|
celery_settings = config_data["CELERY_SETTINGS"]
|
||||||
|
app.config.update(celery_settings)
|
||||||
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
|
admin.init_app(app)
|
||||||
|
|
||||||
from textsouls.actions.api import bp
|
app.register_blueprint(actions_bp)
|
||||||
|
app.register_blueprint(characters_bp)
|
||||||
app.register_blueprint(bp)
|
app.register_blueprint(users_bp)
|
||||||
|
|
||||||
from textsouls.characters.api import bp
|
|
||||||
|
|
||||||
app.register_blueprint(bp)
|
|
||||||
|
|
||||||
from textsouls.users.api import bp
|
|
||||||
|
|
||||||
app.register_blueprint(bp)
|
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
|
|
||||||
from textsouls import db
|
|
||||||
from textsouls import admin
|
from textsouls import admin
|
||||||
|
|
||||||
|
from textsouls.common.database import db
|
||||||
from textsouls.common.api import register_api
|
from textsouls.common.api import register_api
|
||||||
from textsouls.common.api import CommonAdminView
|
from textsouls.common.admin import CommonAdminView
|
||||||
|
|
||||||
from textsouls.actions.models import DuelParticipant
|
from textsouls.actions.models import DuelParticipant
|
||||||
from textsouls.actions.models import Duel
|
from textsouls.actions.models import Duel
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint("actions", __name__)
|
actions_bp = Blueprint("actions", __name__)
|
||||||
|
|
||||||
register_api(bp, DuelParticipant, "duels_participant")
|
register_api(actions_bp, DuelParticipant, "duels_participant")
|
||||||
register_api(bp, Duel, "duels")
|
register_api(actions_bp, Duel, "duels")
|
||||||
|
|
||||||
admin.add_view(CommonAdminView(DuelParticipant, db.session))
|
admin.add_view(CommonAdminView(DuelParticipant, db.session))
|
||||||
admin.add_view(CommonAdminView(Duel, db.session))
|
admin.add_view(CommonAdminView(Duel, db.session))
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
|
|
||||||
from textsouls import db
|
from textsouls.common.database import db
|
||||||
from textsouls import admin
|
from textsouls.common.admin import admin
|
||||||
|
|
||||||
from textsouls.common.api import register_api
|
from textsouls.common.api import register_api
|
||||||
from textsouls.common.api import CommonAdminView
|
from textsouls.common.admin import CommonAdminView
|
||||||
|
|
||||||
from textsouls.characters.models import CharacterRace
|
from textsouls.characters.models import CharacterRace
|
||||||
from textsouls.characters.models import CharacterClass
|
from textsouls.characters.models import CharacterClass
|
||||||
@@ -23,3 +23,12 @@ admin.add_view(CommonAdminView(CharacterRace, db.session))
|
|||||||
admin.add_view(CommonAdminView(CharacterClass, db.session))
|
admin.add_view(CommonAdminView(CharacterClass, db.session))
|
||||||
admin.add_view(CommonAdminView(CharacterState, db.session))
|
admin.add_view(CommonAdminView(CharacterState, db.session))
|
||||||
admin.add_view(CommonAdminView(Character, db.session))
|
admin.add_view(CommonAdminView(Character, db.session))
|
||||||
|
|
||||||
|
|
||||||
|
from textsouls.telegram.tasks import broadcast_message
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/test", methods=["POST"])
|
||||||
|
def run_task():
|
||||||
|
task = broadcast_message.delay()
|
||||||
|
return str(task.id), 202
|
||||||
|
|||||||
11
backend/textsouls/common/admin.py
Normal file
11
backend/textsouls/common/admin.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from flask_admin import Admin
|
||||||
|
from flask_admin.contrib.sqla import ModelView
|
||||||
|
|
||||||
|
|
||||||
|
class CommonAdminView(ModelView):
|
||||||
|
def __init__(self, model, *args, **kwargs):
|
||||||
|
self.column_list = [c.key for c in model.__table__.columns]
|
||||||
|
super(CommonAdminView, self).__init__(model, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
admin = Admin(name="TextSouls")
|
||||||
@@ -1,15 +1,7 @@
|
|||||||
from flask import request
|
from flask import request
|
||||||
from flask.views import MethodView
|
from flask.views import MethodView
|
||||||
|
|
||||||
from flask_admin.contrib.sqla import ModelView
|
from textsouls.common.database import db
|
||||||
|
|
||||||
from textsouls import db
|
|
||||||
|
|
||||||
|
|
||||||
class CommonAdminView(ModelView):
|
|
||||||
def __init__(self, model, *args, **kwargs):
|
|
||||||
self.column_list = [c.key for c in model.__table__.columns]
|
|
||||||
super(CommonAdminView, self).__init__(model, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class ItemAPI(MethodView):
|
class ItemAPI(MethodView):
|
||||||
|
|||||||
18
backend/textsouls/common/celery.py
Normal file
18
backend/textsouls/common/celery.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from celery import Celery
|
||||||
|
|
||||||
|
|
||||||
|
def make_celery(app):
|
||||||
|
celery = Celery(
|
||||||
|
app.import_name,
|
||||||
|
backend=app.config["CELERY_RESULT_BACKEND"],
|
||||||
|
broker=app.config["CELERY_BROKER_URL"],
|
||||||
|
)
|
||||||
|
celery.conf.update(app.config)
|
||||||
|
|
||||||
|
class ContextTask(celery.Task):
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
with app.app_context():
|
||||||
|
return self.run(*args, **kwargs)
|
||||||
|
|
||||||
|
celery.Task = ContextTask
|
||||||
|
return celery
|
||||||
3
backend/textsouls/common/database.py
Normal file
3
backend/textsouls/common/database.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
db = SQLAlchemy()
|
||||||
16
backend/textsouls/telegram/tasks.py
Normal file
16
backend/textsouls/telegram/tasks.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from textsouls.common.database import db
|
||||||
|
from textsouls import celery
|
||||||
|
|
||||||
|
from textsouls.users.models import User, Sendlist, SendlistDestination
|
||||||
|
|
||||||
|
|
||||||
|
@celery.task()
|
||||||
|
def broadcast_message(message):
|
||||||
|
sendlist = Sendlist(message=message)
|
||||||
|
db.session.add(sendlist)
|
||||||
|
db.session.commit()
|
||||||
|
for user in User.query.all():
|
||||||
|
db.session.add(
|
||||||
|
SendlistDestination(sendlist_id=sendlist.id, user_id=user.id)
|
||||||
|
)
|
||||||
|
db.session.commit()
|
||||||
@@ -2,7 +2,7 @@ from flask import Blueprint
|
|||||||
|
|
||||||
from flask_admin.contrib.sqla import ModelView
|
from flask_admin.contrib.sqla import ModelView
|
||||||
|
|
||||||
from textsouls import db
|
from textsouls.common.database import db
|
||||||
from textsouls import admin
|
from textsouls import admin
|
||||||
|
|
||||||
from textsouls.common.api import register_api
|
from textsouls.common.api import register_api
|
||||||
|
|||||||
@@ -21,6 +21,65 @@ class User(db.Model, SerializerMixin):
|
|||||||
)
|
)
|
||||||
is_admin = db.Column(db.Boolean, nullable=False, default=False)
|
is_admin = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
characters = db.relationship("Character", backref="user", lazy="dynamic")
|
characters = db.relationship("Character", backref="user", lazy="dynamic")
|
||||||
|
destinations = db.relationship(
|
||||||
|
"SendlistDestination", backref="sendlist", lazy="dynamic"
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.id}: {self.username}"
|
return f"{self.id}: {self.username}"
|
||||||
|
|
||||||
|
|
||||||
|
class Sendlist(db.Model, SerializerMixin):
|
||||||
|
|
||||||
|
__tablename__ = "sendlists"
|
||||||
|
|
||||||
|
serialize_rules = ("-destination",)
|
||||||
|
|
||||||
|
id = db.Column(db.BigInteger, primary_key=True)
|
||||||
|
message = db.Column(db.String(255), nullable=True)
|
||||||
|
destinations = db.relationship(
|
||||||
|
"SendlistDestination", backref="sendlist", lazy="dynamic"
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.message[:12]}..."
|
||||||
|
|
||||||
|
|
||||||
|
class SendlistDestinationStatus(db.Model, SerializerMixin):
|
||||||
|
|
||||||
|
__tablename__ = "sendlists_destionations_statuses"
|
||||||
|
|
||||||
|
serialize_rules = ("-destination",)
|
||||||
|
|
||||||
|
id = db.Column(db.BigInteger, primary_key=True)
|
||||||
|
name = db.Column(db.String(255), nullable=False)
|
||||||
|
destinations = db.relationship(
|
||||||
|
"SendlistDestination",
|
||||||
|
backref="status",
|
||||||
|
lazy="dynamic",
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class SendlistDestination(db.Model, SerializerMixin):
|
||||||
|
|
||||||
|
__tablename__ = "sendlists_destionations"
|
||||||
|
|
||||||
|
id = db.Column(db.BigInteger, primary_key=True)
|
||||||
|
sendlist_id = db.Column(
|
||||||
|
db.Integer,
|
||||||
|
db.ForeignKey("sendlists.id", ondelete="CASCADE"),
|
||||||
|
)
|
||||||
|
user_id = db.Column(
|
||||||
|
db.BigInteger,
|
||||||
|
db.ForeignKey("users.id", ondelete="CASCADE"),
|
||||||
|
)
|
||||||
|
status_id = db.Column(
|
||||||
|
db.Integer,
|
||||||
|
db.ForeignKey("sendlists_destionations_types.id", ondelete="CASCADE"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.message[:12]}..."
|
||||||
|
|||||||
Reference in New Issue
Block a user