def add_listening(): snd = Application().context.query(Sound).filter( Sound.id == request.get_json()["id"]).first() if f'{snd.id}viewed' not in session: listn = pickle.loads(snd.listening) listn.append(0) snd.listening = pickle.dumps(listn) session[f'{snd.id}viewed'] = 1 Application().context.commit() return 'a'
class User(Application().model, UserMixin): __tablename__ = "users" id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String, nullable=True) sename = Column(String, nullable=True) nickname = Column(String, nullable=True) birthday = Column(Date, nullable=True) icon = Column(String, nullable=True, default="img/lol.png") email = Column(String, index=True, unique=True, nullable=True) phone = Column(Integer, nullable=True) type = Column(Integer, default=1) hashed_password = Column(String, nullable=True) @property def password(self): return self.hashed_password @password.setter def password(self, val): self.hashed_password = generate_password_hash(val) def check_password(self, password): return check_password_hash(self.hashed_password, password)
class ListSound(Application().model): __tablename__ = "ListsSound" id = Column(Integer, primary_key=True) id_user = Column(Integer) name = Column(String, nullable=True) sounds = Column(LargeBinary, nullable=True, default=pickle.dumps(set()))
class Comment(Application().model): __tablename__ = "comments" id = Column(Integer, primary_key=True) text = Column(String, nullable=True) created_date = Column(DateTime, default=datetime.datetime.now) id_user = Column(Integer) id_sound = Column(Integer)
class Sound(Application().model): __tablename__ = "sounds" id = Column(Integer, primary_key=True) name = Column(String, nullable=True) img = Column(String, nullable=True) file_name = Column(String, nullable=True) teg = Column(String, nullable=True) listening = Column(LargeBinary, nullable=True, default=pickle.dumps([])) like = Column(LargeBinary, nullable=True, default=pickle.dumps([])) dislike = Column(LargeBinary, nullable=True, default=pickle.dumps([])) created_date = Column(DateTime, default=datetime.datetime.now) id_user = Column(Integer)
def load_user(user_id): db_sess = Application().context return db_sess.query(User).get(user_id)
def main(): Application().create_context("db/sound.db") app.run()
from forms.ReqistrationForm import RegisterForm from forms.UploadMusicForm import UploadMusicForm from forms.ProfileForm import ProfileForm from Models.User import User from Models.Sound import Sound import os import pickle from flask import Flask, render_template, redirect, request, abort, session, make_response, jsonify from flask_login import login_user, logout_user, login_required from sqlalchemy import desc from forms.comment import Comment Application().app = Flask(__name__) app = Application().app app.config["FILE_DIR"] = os.path.dirname(os.path.abspath(__file__)) login_manager = Application().login_manager state = 'Новые треки' @login_manager.user_loader def load_user(user_id): db_sess = Application().context return db_sess.query(User).get(user_id) @app.route("/", methods=['GET', 'POST'])