def __call__(self, *args, **kwargs): img = self.__model.img.data if img is not None: filename_img = secure_filename(img.filename).split(".") filename_img = os.path.join('img', os.urandom(15).hex() + "." + filename_img[-1]) img.save(os.path.join(app().app.config["FILE_DIR"], "static", filename_img)) filename_img = filename_img.replace('\\', "/") if current_user.icon != 'lol.png': os.remove(os.path.join(app().app.config["FILE_DIR"], "static", current_user.icon)) else: filename_img = current_user.icon now_user = app().context.query(User).filter(User.id == current_user.id).first() if self.__model.name.data is not None: now_user.name = self.__model.name.data if self.__model.email.data is not None: now_user.email = self.__model.email.data if self.__model.sename.data is not None: now_user.sename = self.__model.sename.data if self.__model.nickname.data is not None: now_user.nickname = self.__model.nickname.data if self.__model.phone.data is not None: now_user.phone = self.__model.phone.data if self.__model.phone.data is not None: now_user.birthday = self.__model.birthday.data now_user.icon = filename_img app().context.commit() return render_template('profile.html', title='Профиль', form=self.__model)
def __call__(self, massed, *args, **kwargs): req = massed.get_json() comment = Comment(text=req["text"], id_sound=req["id"], id_user=current_user.id) app().context.commit() res = make_response(jsonify({"data": "succesfull"}), 200) return res
def __call__(self, massed, *args, **kwargs): sound = app().context.query(Sound).filter( Sound.id == massed["id"]).first() sound = MakeResponse.make_response_sound(sound.__dict__) sound['id_user'] = app().context.query(User).filter( User.id == sound['id_user']).first().__dict__['nickname'] sound["comments"] = len(app().context.query(Comment).filter( Comment.id_sound == sound["id"]).all()) return sound
def __call__(self, massed, *args, **kwargs): req = massed.get_json() sound = app().context.query(Sound).filter( Sound.id == req['id']).first() users = pickle.loads(sound.dislike) users2 = pickle.loads(sound.like) if current_user.id in users: users.remove(current_user.id) else: users.append(current_user.id) if current_user.id in users2: users2.remove(current_user.id) sound.dislike = pickle.dumps(users) sound.like = pickle.dumps(users2) app().context.commit() res = make_response(jsonify({"data": "succesfull"}), 200) return res
def __call__(self, *args, **kwargs): if self.__model.validate_on_submit(): if self.__model.password.data != self.__model.password_again.data: return render_template('register.html', title='Регистрация', form=self.__model, message="Пароли не совпадают") if app().context.query(User).filter(User.email == self.__model.email.data).first(): return render_template('register.html', title='Регистрация', form=self.__model, message="Такой пользователь уже есть") user = User(name=self.__model.name.data, email=self.__model.email.data, sename=self.__model.sename.data, nickname=self.__model.nickname.data, phone=self.__model.phone.data) user.password = self.__model.password.data app().context.add(user) app().context.commit() self.__login_user(user, remember=True) return redirect("/") return render_template('register.html', title='Регистрация', form=self.__model)
def __call__(self, *args, **kwargs): if self.__model.validate_on_submit(): img = self.__model.img.data music = self.__model.music.data filename_img = secure_filename(img.filename).split(".") filename_music = secure_filename(music.filename).split(".") filename_img = os.path.join( 'img', "sound", os.urandom(15).hex() + "." + filename_img[-1]) filename_music = os.path.join( 'sound', os.urandom(15).hex() + "." + filename_music[-1]) sound = Sound(name=self.__model.name.data, img=filename_img.replace('\\', "/"), file_name=filename_music.replace('\\', "/"), teg=self.__model.tag.data, id_user=current_user.id) app().context.add(sound) app().context.commit() img.save( os.path.join(app().app.config["FILE_DIR"], "static", filename_img)) music.save( os.path.join(app().app.config["FILE_DIR"], "static", filename_music)) #return redirect("/") return render_template('load_music.html', title='Загрузка музыки', form=self.__model)
def __call__(self, *args, **kwargs): if self.__model.validate_on_submit(): user = app().context.query(User).filter( User.email == self.__model.email.data).first() if user and user.check_password(self.__model.password.data): self.__login_user(user, remember=self.__model.remember_me.data) return redirect("/") return render_template('login.html', message="Неправильный логин или пароль", form=self.__model) return render_template('login.html', title='Авторизация', form=self.__model)
def __call__(self, massed, *args, **kwargs): req = massed.get_json() print(req) comments = app().context.query(Comment).filter( Comment.id_sound == req["id"]).all() comments_response = {"data": []} for i in range(len(comments)): comments[i] = MakeResponse.make_response_comments( comments[i].__dict__) for i in comments: user = app().context.query(User).filter( User.id == i["id_user"]).first() comments_response["data"].append({ "user": { "nickname": user.nickname, "icon": user.icon }, "comment": { "text": i["text"], "date": i["created_date"] } }) res = make_response(jsonify(comments_response), 200) return res
def __call__(self, massed, *args, **kwargs): req = massed.get_json() user = app().context.query(ListSound).filter( ListSound.id_user == current_user.id).first() if user is None: list_sound = ListSound(id_user=current_user.id, name="Мой плейлист") app().context.add(list_sound) app().context.commit() list_sound = app().context.query(ListSound).filter( ListSound.id_user == current_user.id).first() list_sound_dump = pickle.loads(list_sound.sounds) list_sound_dump = set(list_sound_dump) list_sound_dump.add(req["id"]) list_sound.sounds = pickle.dumps(list_sound_dump) app().context.commit() res = make_response(jsonify({"data": "succesfull"}), 200) return res
def __call__(self, massed, state): req = massed.get_json() sounds = app().context.query(Sound).order_by(desc(Sound.created_date)) if state == 'Новые треки': sounds = app().context.query(Sound).order_by(desc(Sound.created_date)) elif state == 'По прослушиваниям': sounds = app().context.query(Sound).order_by(asc(Sound.listening)) elif state == 'По лайкам/дизлайкам': sounds = sorted(sounds, key=lambda x: len(pickle.loads(x.like)) - len(pickle.loads(x.dislike))) sounds.reverse() elif state == 'Мои треки': sounds = app().context.query(Sound).filter(Sound.id_user == current_user.id).order_by(desc(Sound.created_date)) elif 'Найденные треки по запросу:' in state: sounds = app().context.query(Sound).filter(Sound.name.like(f'%{state[28:]}%')).order_by(desc(Sound.created_date)) sounds = list(map(lambda x: MakeResponse.make_response_sound(x.__dict__), sounds)) for i in sounds: i["comments"] = len(app().context.query(Comment).filter(Comment.id_sound == i["id"]).all()) res = make_response(jsonify({"data": sounds}), 200) return res
def __call__(self, massed, *args, **kwargs): get_music = GetMusicController() req = massed.get_json() user = app().context.query(ListSound).filter(ListSound.id_user == current_user.id).first() if user is None: list_sound = ListSound(id_user=current_user.id, name="Мой плейлист") app().context.add(list_sound) app().context.commit() list_sound = app().context.query(ListSound).filter(ListSound.id_user == current_user.id).all() for i in range(len(list_sound)): list_sound[i] = MakeResponse.make_response_list_music(list_sound[i].__dict__) for play_list in list_sound: sound = [] for id_sound in play_list["sounds"]: sound.append(get_music({"id": id_sound})) play_list["sounds"] = sound res = make_response(jsonify({"data": list_sound}), 200) return res