Блок "Для вас" в разделе публикаций
This commit is contained in:
parent
7ded2a130d
commit
0ee877da84
BIN
db/moona_data.db
BIN
db/moona_data.db
Binary file not shown.
34
main.py
34
main.py
@ -1,6 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
from random import randint
|
from random import randint, choices
|
||||||
|
|
||||||
from flask import Flask, render_template, request
|
from flask import Flask, render_template, request
|
||||||
from flask_login import LoginManager, login_user, logout_user, login_required, current_user
|
from flask_login import LoginManager, login_user, logout_user, login_required, current_user
|
||||||
@ -180,8 +180,38 @@ def publications():
|
|||||||
else:
|
else:
|
||||||
pop_post = []
|
pop_post = []
|
||||||
emotion_pop = []
|
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',
|
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/<int:id>', methods=['GET', 'POST'])
|
@app.route('/answer_quest/<int:id>', methods=['GET', 'POST'])
|
||||||
|
|||||||
BIN
static/app_image/post_photo/Duvakin_post_6.png
Normal file
BIN
static/app_image/post_photo/Duvakin_post_6.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 378 KiB |
@ -1,5 +1,5 @@
|
|||||||
table {
|
table {
|
||||||
margin-left: auto;
|
margin-left: 20px;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
#row1, #row2, #row3 {
|
#row1, #row2, #row3 {
|
||||||
|
|||||||
@ -218,6 +218,102 @@
|
|||||||
<td id="row3">
|
<td id="row3">
|
||||||
<div id="row3_div">
|
<div id="row3_div">
|
||||||
<h1 class="post_zag">Для вас</h1>
|
<h1 class="post_zag">Для вас</h1>
|
||||||
|
{% if for_me_post != [] %}
|
||||||
|
{% for item in for_you_post %}
|
||||||
|
<div class="card-body post">
|
||||||
|
<details>
|
||||||
|
<summary>
|
||||||
|
{% if item.name != None %}
|
||||||
|
<h2 class="card-title post_zag" style="color:#c5f1ff">{{item.name}}</h2>
|
||||||
|
{% endif %}
|
||||||
|
</summary>
|
||||||
|
{% if item.text != None %}
|
||||||
|
<strong class="card-text" style="color:#ffffff">{{item.text}}</strong>
|
||||||
|
{% endif %}
|
||||||
|
</details>
|
||||||
|
{% if emotion_for_you[loop.index0]['pos_emot'] != None %}
|
||||||
|
<div class="pos_emot">
|
||||||
|
<details>
|
||||||
|
<summary class="emot_block">
|
||||||
|
<strong class="emot_block">Позитивные эмоции</strong>
|
||||||
|
</summary>
|
||||||
|
<p></p>
|
||||||
|
{% for item2 in emotion_for_you[loop.index0]['pos_emot'] %}
|
||||||
|
<strong class="alert alert-success" role="alert"
|
||||||
|
style="border-radius: 22px;">{{item2}}</strong>
|
||||||
|
{% endfor %}
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
{% endif %}
|
||||||
|
{% if emotion_for_you[loop.index0]['nig_emot'] != None %}
|
||||||
|
<div class="nig_emot">
|
||||||
|
<details>
|
||||||
|
<summary class="emot_block">
|
||||||
|
<strong class="emot_block">Негативные эмоции</strong>
|
||||||
|
</summary>
|
||||||
|
<p></p>
|
||||||
|
{% for item2 in emotion_for_you[loop.index0]['nig_emot'] %}
|
||||||
|
<strong class="alert alert-danger" role="alert"
|
||||||
|
style="border-radius: 22px;">{{item2}}</strong>
|
||||||
|
{% endfor %}
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
{% endif %}
|
||||||
|
{% if item.photo != None %}
|
||||||
|
<p></p>
|
||||||
|
<div class="photo">
|
||||||
|
<img width="90%" src="{{ item.photo }}"
|
||||||
|
style="border-radius: 22px;">
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
{% endif %}
|
||||||
|
{% if current_user.is_authenticated %}
|
||||||
|
<div class="like">
|
||||||
|
<a type="button"
|
||||||
|
href="/new_like/{{current_user.id}}/{{item.id}}/publications">
|
||||||
|
{% if emotion_for_you[loop.index0]['is_like'] %}
|
||||||
|
<img src="../static/img/like_add.png" width="117" height="100">
|
||||||
|
{% else %}
|
||||||
|
<img src="../static/img/like.png" width="94" height="80">
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
|
{% if emotion_for_you[loop.index0]['like'] != None %}
|
||||||
|
<p style="color:#ffffff">{{emotion_for_you[loop.index0]['like']}}</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if emotion_for_you[loop.index0]['link'] != None %}
|
||||||
|
<details>
|
||||||
|
<summary class="emot_block">
|
||||||
|
<strong class="emot_block">Ссылки</strong>
|
||||||
|
</summary>
|
||||||
|
<p></p>
|
||||||
|
{% for item2 in emotion_for_you[loop.index0]['link'] %}
|
||||||
|
<div class="link">
|
||||||
|
<a class="alert alert-light" role="alert" href="{{ item2 }}" style="border-radius: 22px;">Ссылка
|
||||||
|
{{ loop.index }}</a>
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
{% endfor %}
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
|
<div class="author" style="style=position:absolute; width:148px; height:44px; left:255px; -webkit-border-radius:
|
||||||
|
22px;-moz-border-radius: 22px;border-radius: 22px; border:2px solid #FFFFFF; background-color:#1daff0; top:
|
||||||
|
98px;"><img src="../{{ emotion_for_you[loop.index0]['author'].photo }}" width="40" height="40"
|
||||||
|
style="border-radius: 22px">
|
||||||
|
<strong style="color: #ffffff">{{ emotion_for_you[loop.index0]['author'].name }}</strong>
|
||||||
|
</div>
|
||||||
|
<strong style="color:#ffffff">{{item.date}}</strong>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="bad_centre" style="background-color:#1daff0; border-radius: 22px;color:#ffffff">
|
||||||
|
<h1 class="hz1">Ничего не нашлось :с</h1>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user