From 30b1c3cf7388b39d026a0442c78fe85ca71a3a3f Mon Sep 17 00:00:00 2001 From: mrmur Date: Tue, 26 Apr 2022 21:28:52 +0500 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BB=D0=B0=D0=B2=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/moona_data.db | Bin 86016 -> 86016 bytes main.py | 95 +++++++++++++- static/css/main.css | 46 +++++++ static/css/publications.css | 3 +- templates/diary.html | 2 +- templates/main.html | 238 ++++++++++++++++++++++++++++++++++++ 6 files changed, 377 insertions(+), 7 deletions(-) create mode 100644 static/css/main.css create mode 100644 templates/main.html diff --git a/db/moona_data.db b/db/moona_data.db index dde78e5c57738cf51201fa07b1f38f2909d60b86..ea51aec50856f6aef0e6c22bc0681684766ffca8 100644 GIT binary patch delta 175 zcmZozz}m2Yb%HeG#)&e{j2ky5oR(!WGM%g|_ZUcR7Ls2Z;HbpO=*VnjU}U6gV4`be zreI`fWoT|?XryOoU~Xb=&cMI`Qo)L 50: + for_you_post = choices(for_you, k=80) + else: + for_you_post = set(for_you) + emotion_for_you = [] + for i in for_you_post: + emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [], + 'author': session.query(User).filter(User.id == i.author).first(), 'like': None, 'is_like': 0} + if i.pos_emot: + emotion['pos_emot'] = i.pos_emot.split() + else: + emotion['pos_emot'] = None + if i.nig_emot: + emotion['nig_emot'] = i.nig_emot.split() + else: + emotion['nig_emot'] = None + if i.link: + emotion['link'] = i.link.split() + else: + emotion['link'] = None + like = session.query(Like).filter(Like.post == i.id).all() + if like: + emotion['like'] = len(like) + if current_user.is_authenticated: + if session.query(Like).filter(Like.post == i.id, Like.user == current_user.id).first(): + emotion['is_like'] = 1 + emotion_for_you.append(emotion) + 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)) + emotion_you_like_that = [] + for i in you_like_that: + emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [], + 'author': session.query(User).filter(User.id == i.author).first(), 'like': None, 'is_like': 0} + if i.pos_emot: + emotion['pos_emot'] = i.pos_emot.split() + else: + emotion['pos_emot'] = None + if i.nig_emot: + emotion['nig_emot'] = i.nig_emot.split() + else: + emotion['nig_emot'] = None + if i.link: + emotion['link'] = i.link.split() + else: + emotion['link'] = None + like = session.query(Like).filter(Like.post == i.id).all() + if like: + emotion['like'] = len(like) + if current_user.is_authenticated: + if session.query(Like).filter(Like.post == i.id, Like.user == current_user.id).first(): + emotion['is_like'] = 1 + emotion_you_like_that.append(emotion) + quest = session.query(Answer).filter(Answer.user == current_user.id).all() + days_reg = current_user.data_reg - datetime.date.today() + days_reg = abs(days_reg.days) + 1 + if quest: + post_quest = session.query(Quest).filter(Quest.id.in_([i.id_question for i in quest])).all() + else: + post_quest = [] + while len(post_quest) < days_reg: + post_quest.append( + session.query(Quest).filter(Quest.id.notin_([i.id for i in post_quest])).first()) + ans = [] + for i in post_quest: + if i is not None: + ans_id = session.query(Answer).filter( + Answer.id_question == i.id and Answer.user.id == current_user.id).first() + if ans_id is not None: + ans.append(ans_id) + post_quest = post_quest[::-1] + ans = ans[::-1] + ans2 = {} + for i in ans: + ans2[i.id_question] = i + return render_template('main.html', title='moona', for_me_post=for_you_post, emotion_for_you=emotion_for_you, + you_like_that=you_like_that, emotion_you_like_that=emotion_you_like_that, + question=post_quest, + ans=ans2) @app.route('/edit_profile/', methods=['GET', 'POST']) @@ -170,7 +252,10 @@ def new_like(user_id, post_id, ret_href): session.delete(pop) session.delete(find) session.commit() - return redirect(f"/{ret_href}") + if ret_href != 'main': + return redirect(f"/{ret_href}") + else: + return redirect('/') else: popular = session.query(Popularity).filter(Popularity.post == post_id).first() if not popular: @@ -190,7 +275,10 @@ def new_like(user_id, post_id, ret_href): like.date = datetime.datetime.now() session.add(like) session.commit() - return redirect(f"/{ret_href}") + if ret_href != 'main': + return redirect(f"/{ret_href}") + else: + return redirect('/') @app.route('/publications', methods=['GET', 'POST']) @@ -620,7 +708,6 @@ def confirmation(): secret_code = secret_key() mail(f'Ваш секретный код: {secret_code}', help_arg_2, 'Moona Код') send_msg = True - print(secret_code) if conf.validate_on_submit(): if str(conf.code_key.data).strip() == str(secret_code).strip(): user = session.query(User).filter(User.id == current_user.id).first() diff --git a/static/css/main.css b/static/css/main.css new file mode 100644 index 0000000..57ca86e --- /dev/null +++ b/static/css/main.css @@ -0,0 +1,46 @@ +#add_post { + margin-top: 20px; + margin-left: 83%; +} +.row1, .row2, .row3 { + width: 33%; + display:inline-block; + vertical-align: top; + margin-top: 39px; +} +.rowdiv1, .rowdiv2, .rowdiv3 { + width: 95%; +} +.post_zag, .card-text, .card-body, .post_zag, .author { + width: 90%; + margin-left: auto; + margin-right: auto; + text-align: center; +} +.post { + background-color: #7fc3ff; + border-radius: 50px; + width: 90%; + height: 95%; + margin-bottom: 20px; +} +details { + color: #ffffff; +} +table { + margin-left: 10%; + margin-right: auto; + width: 90%; +} +.question { + background-color:#7fc3ff; + border-radius: 22px; + width: 90%; + margin-left: 10px; +} +.is_ans { + background-color:#ddefff; + border:2px solid #ffffff; + border-radius: 25px; + width: 95%; +} \ No newline at end of file diff --git a/static/css/publications.css b/static/css/publications.css index da17a29..0fca6f2 100644 --- a/static/css/publications.css +++ b/static/css/publications.css @@ -37,5 +37,4 @@ details { } .hz1 { margin: 5%; - font-size: 160%; -} \ No newline at end of file + font-size: 160%; \ No newline at end of file diff --git a/templates/diary.html b/templates/diary.html index ceb219e..6ea3f01 100644 --- a/templates/diary.html +++ b/templates/diary.html @@ -3,7 +3,7 @@ {% block content %} {% if current_user.is_authenticated %} -

Дневник

+

Главная

Добавить diff --git a/templates/main.html b/templates/main.html new file mode 100644 index 0000000..dd69aea --- /dev/null +++ b/templates/main.html @@ -0,0 +1,238 @@ + +{% extends "base.html" %} + +{% block content %} +

Главная

+
+ Добавить + запись +
+ + + + +
+ + +
+

Вам будет интересно

+ {% if for_me_post != [] %} + {% for item in for_me_post %} +
+
+ + {% if item.name != None %} +

{{item.name}}

+ {% endif %} +
+ {% if item.text != None %} + {{item.text}} + {% endif %} +
+ {% if emotion_for_you[loop.index0]['pos_emot'] != None %} +
+
+ + Позитивные эмоции + +

+ {% for item2 in emotion_for_you[loop.index0]['pos_emot'] %} + {{item2}} + {% endfor %} +
+
+

+ {% endif %} + {% if emotion_for_you[loop.index0]['nig_emot'] != None %} +
+
+ + Негативные эмоции + +

+ {% for item2 in emotion_for_you[loop.index0]['nig_emot'] %} + {{item2}} + {% endfor %} +
+
+

+ {% endif %} + {% if item.photo != None %} +

+
+ +
+

+ {% endif %} + {% if current_user.is_authenticated %} + + {% endif %} + {% if emotion_for_you[loop.index0]['link'] != None %} +
+ + Ссылки + +

+ {% for item2 in emotion_for_you[loop.index0]['link'] %} + +

+ {% endfor %} +
+ {% endif %} +
+ {{ emotion_for_you[loop.index0]['author'].name }} +
+ {{item.date}} +
+ {% endfor %} + {% else %} +
+

Ничего не нашлось :с

+
+ {% endif %} +
+
+
+

Вам понравились эти посты

+ {% if you_like_that != [] %} + {% for item in you_like_that %} +
+
+ + {% if item.name != None %} +

{{item.name}}

+ {% endif %} +
+ {% if item.text != None %} + {{item.text}} + {% endif %} +
+ {% if emotion_you_like_that[loop.index0]['pos_emot'] != None %} +
+
+ + Позитивные эмоции + +

+ {% for item2 in emotion_you_like_that[loop.index0]['pos_emot'] %} + {{item2}} + {% endfor %} +
+
+

+ {% endif %} + {% if emotion_you_like_that[loop.index0]['nig_emot'] != None %} +
+
+ + Негативные эмоции + +

+ {% for item2 in emotion_you_like_that[loop.index0]['nig_emot'] %} + {{item2}} + {% endfor %} +
+
+

+ {% endif %} + {% if item.photo != None %} +

+
+ +
+

+ {% endif %} + {% if current_user.is_authenticated %} + + {% endif %} + {% if emotion_you_like_that[loop.index0]['link'] != None %} +
+ + Ссылки + +

+ {% for item2 in emotion_you_like_that[loop.index0]['link'] %} + +

+ {% endfor %} +
+ {% endif %} +
+ {{ emotion_you_like_that[loop.index0]['author'].name }} +
+ {{item.date}} +
+ {% endfor %} + {% else %} +
+

Ничего не нашлось :с

+
+ {% endif %} +
+
+{% endblock %} \ No newline at end of file