Заготовка раздела пользователя

This commit is contained in:
mrmur 2022-04-22 16:35:07 +05:00
parent f64e568bf6
commit 215f6f8399
5 changed files with 204 additions and 5 deletions

Binary file not shown.

35
main.py
View File

@ -72,6 +72,36 @@ def main_page():
return render_template('base.html', title='moona')
@app.route('/profile')
def profile():
db_sess = db_session.create_session()
pub_post = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id, DiaryPost.public == 1).all()
pub_post = pub_post[::-1]
emotion_pub = []
for i in pub_post:
emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [], 'like': None, 'is_like': 0,
'author': current_user}
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 = db_sess.query(Like).filter(Like.post == i.id).all()
if like:
emotion['like'] = len(like)
if db_sess.query(Like).filter(Like.post == i.id, Like.user == current_user.id).first():
emotion['is_like'] = 1
emotion_pub.append(emotion)
return render_template('profile.html', title='Профиль', pub_post=pub_post, emotion_pub=emotion_pub)
@app.route('/new_like/<int:user_id>/<int:post_id>/<string:ret_href>')
def new_like(user_id, post_id, ret_href):
session = db_session.create_session()
@ -592,11 +622,6 @@ def about():
return render_template('about.html', title='О нас')
@app.route('/profile')
def profile():
return render_template('profil.html', title='Профиль')
def main():
db_session.global_init("db/moona_data.db")
app.run()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 MiB

46
static/css/profile.css Normal file
View File

@ -0,0 +1,46 @@
.profile_header_photo_img {
border-radius: 50%;
border: 3px solid #ffffff;
margin-top: 40px;
margin-left: 15%;
}
.profile_header_name {
text-align: right;
color: #ffffff;
margin-right: 25px;
}
.profile_header {
width: 90%;
}
.all_profile {
margin-left: 10%;
width: 85%;
margin-right: 5%;
background-color: #66c0e9;
margin-top: 55px;
border-radius: 50px;
}
.row_centre, .row_right {
width: 33%;
}
table {
width: 99%;
margin-left: 10%;
margin-right: 10%;
}
.profile_header_photo_img {
float:right;
margin-right: 5px;
}
.row_left {
color: #ffffff;
width: 20%;
}
.user_posts {
margin-top: 50px;
}
.user_posts {
width: 35%;
margin-right: auto;
margin-left: auto;
}

128
templates/profile.html Normal file
View File

@ -0,0 +1,128 @@
<link rel="stylesheet" href="../static/css/profile.css">
<link rel="stylesheet" href="../static/css/publications.css">
{% extends "base.html" %}
{% block content %}
<div class="all_profile">
<div class="profile_header">
<table>
<th class="row_left">
{% if current_user.about %}
<h2>О себе:</h2>
<h5>
{{current_user.about}}
</h5>
{% endif %}
<div>
<a href="/edit_profile/{{current_user.id}}" type="submit" class="btn btn-primary"
style="background-color:#38aaff">Редактировать профиль</a>
</div>
</th>
<th class="row_centre">
</th>
<th class="row_right">
<img src="../{{ current_user.photo }}" width="200" class="profile_header_photo_img">
<h1 class="profile_header_name">{{current_user.name}}</h1>
</th>
</table>
</div>
</div>
<div class="user_posts">
<h1 class="post_zag">Опубликованные посты</h1>
{% if pub_post != [] %}
{% for item in pub_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_pub[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_pub[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_pub[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_pub[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}}/profile">
{% if emotion_pub[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_pub[loop.index0]['like'] != None %}
<p style="color:#ffffff">{{emotion_pub[loop.index0]['like']}}</p>
{% endif %}
</div>
{% endif %}
{% if emotion_pub[loop.index0]['link'] != None %}
<details>
<summary class="emot_block">
<strong class="emot_block">Ссылки</strong>
</summary>
<p></p>
{% for item2 in emotion_pub[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_pub[loop.index0]['author'].photo }}" width="40" height="40"
style="border-radius: 22px">
<strong style="color: #ffffff">{{ emotion_pub[loop.index0]['author'].name }}</strong>
</div>
<strong style="color:#ffffff">{{item.date}}</strong>
</div>
{% endfor %}
{% else %}
<div class="bad_centre" style="background-color:#1daff0; border-radius: 22px;color:#ffffff">
<h1 class="hz1">Ничего не нашлось :с</h1>
</div>
{% endif %}
</div>
{% endblock %}