diff --git a/db/moona_data.db b/db/moona_data.db index 0b6bb7a..d2e261f 100644 Binary files a/db/moona_data.db and b/db/moona_data.db differ diff --git a/main.py b/main.py index 457bfd9..96c68d1 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ import datetime import os -from random import randint +from random import randint, choices from flask import Flask, render_template, request from flask_login import LoginManager, login_user, logout_user, login_required, current_user @@ -180,8 +180,38 @@ def publications(): else: pop_post = [] emotion_pop = [] + for_you = sorted(session.query(DiaryPost).filter(DiaryPost.public == 1).all(), + key=lambda x: (len(x.text), 1 if x.photo else 0, -(x.date - datetime.datetime.now()).days)) + if len(for_you) > 50: + for_you_post = choices(for_you, k=50) + 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) return render_template('publications.html', fresh_post=fresh_posts, emotion_fresh=emotion_fresh, title='moona', - pop_post=pop_post, emotion_pop=emotion_pop) + pop_post=pop_post, emotion_pop=emotion_pop, for_you_post=for_you_post, + emotion_for_you=emotion_for_you) @app.route('/answer_quest/', methods=['GET', 'POST']) diff --git a/static/app_image/post_photo/Duvakin_post_6.png b/static/app_image/post_photo/Duvakin_post_6.png new file mode 100644 index 0000000..4efdbac Binary files /dev/null and b/static/app_image/post_photo/Duvakin_post_6.png differ diff --git a/static/css/publications.css b/static/css/publications.css index f70d347..2bea14b 100644 --- a/static/css/publications.css +++ b/static/css/publications.css @@ -1,5 +1,5 @@ table { -margin-left: auto; +margin-left: 20px; margin-right: auto; } #row1, #row2, #row3 { diff --git a/templates/publications.html b/templates/publications.html index 6ad70eb..83d0ab3 100644 --- a/templates/publications.html +++ b/templates/publications.html @@ -218,6 +218,102 @@

Для вас

+ {% if for_me_post != [] %} + {% for item in for_you_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 %}