From e8c0f940b805d1b6bae5a9c6b02eecf6262b12ba Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 20 May 2022 21:57:42 +0500 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D0=B2=20=D0=B8=20=D0=BE=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BF=D0=BE=D0=BD?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=B2=D1=88=D0=B8=D1=85=D1=81=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B0=20=D0=B3?= =?UTF-8?q?=D0=BB=D0=B0=D0=B2=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 6722b25..2b8f05c 100644 --- a/main.py +++ b/main.py @@ -104,11 +104,15 @@ def main_page(): emotion['is_like'] = 1 emotion_for_you.append(emotion) if current_user.is_authenticated: - you_like_that = sorted(list(map(lambda x: session.query(DiaryPost).filter(DiaryPost.id == x).first(), - map(lambda x: x.post, - session.query(Like).filter(Like.user == current_user.id).all()))), - key=lambda x: ( - len(x.text), 1 if x.photo else 0, -(x.date - datetime.datetime.now()).days)) + try: + you_like_that = sorted( + list(map(lambda x: session.query(DiaryPost).filter(DiaryPost.id == x, DiaryPost.public == 1).first(), + map(lambda x: x.post, + session.query(Like).filter(Like.user == current_user.id).all()))), + key=lambda x: ( + len(x.text), 1 if x.photo else 0, -(x.date - datetime.datetime.now()).days)) + except Exception: + you_like_that = [] emotion_you_like_that = [] for i in you_like_that: emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [], @@ -420,11 +424,12 @@ def answer_quest(id): answer = AnswerQuest() quest = session.query(Quest).filter(Quest.id == id).first() if request.method == 'GET': - if session.query(Answer).filter(Answer.id_question == id).first(): - ans_quest = session.query(Answer).filter(Answer.id_question == id).first() + if session.query(Answer).filter(Answer.id_question == id, Answer.user == current_user.id).first(): + ans_quest = session.query(Answer).filter(Answer.id_question == id, + Answer.user == current_user.id).first() answer.answer.data = ans_quest.answer if answer.validate_on_submit(): - if not session.query(Answer).filter(Answer.id_question == id).first(): + if not session.query(Answer).filter(Answer.id_question == id, Answer.user == current_user.id).first(): answer_user = Answer(id_question=id, answer=answer.answer.data, user=current_user.id, @@ -563,6 +568,13 @@ def post_deleted(id): if pos: if pos.photo: os.remove(pos.photo[3:]) + if pos.public == 1: + likes = session.query(Like).filter(Like.post == pos.id).all() + if likes: + map(lambda i: session.delete(i), likes) + pop = session.query(Popularity).filter(Popularity.post == pos.id).first() + if pop: + session.delete(pop) session.delete(pos) session.commit() else: