Основа для лайков и дизлайков
This commit is contained in:
parent
169ec49972
commit
39c4475fba
@ -1 +1 @@
|
||||
from . import users, diary_post, questions, answer_quest
|
||||
from . import users, diary_post, questions, answer_quest, like, dislike
|
||||
16
data/dislike.py
Normal file
16
data/dislike.py
Normal file
@ -0,0 +1,16 @@
|
||||
import sqlalchemy
|
||||
from flask_login import UserMixin
|
||||
|
||||
from .db_session import SqlAlchemyBase
|
||||
|
||||
|
||||
class Dislike(SqlAlchemyBase, UserMixin):
|
||||
__tablename__ = 'dislike'
|
||||
|
||||
id = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
primary_key=True, autoincrement=True)
|
||||
user = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
sqlalchemy.ForeignKey("users.id"), nullable=True, default=None)
|
||||
post = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
sqlalchemy.ForeignKey("posts.id"), nullable=True, default=None)
|
||||
date = sqlalchemy.Column(sqlalchemy.DateTime, nullable=True, default=None)
|
||||
16
data/like.py
Normal file
16
data/like.py
Normal file
@ -0,0 +1,16 @@
|
||||
import sqlalchemy
|
||||
from flask_login import UserMixin
|
||||
|
||||
from .db_session import SqlAlchemyBase
|
||||
|
||||
|
||||
class Like(SqlAlchemyBase, UserMixin):
|
||||
__tablename__ = 'like'
|
||||
|
||||
id = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
primary_key=True, autoincrement=True)
|
||||
user = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
sqlalchemy.ForeignKey("users.id"), nullable=True, default=None)
|
||||
post = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
sqlalchemy.ForeignKey("posts.id"), nullable=True, default=None)
|
||||
date = sqlalchemy.Column(sqlalchemy.DateTime, nullable=True, default=None)
|
||||
BIN
db/moona_data.db
BIN
db/moona_data.db
Binary file not shown.
43
main.py
43
main.py
@ -10,6 +10,8 @@ from werkzeug.utils import redirect
|
||||
from data import db_session
|
||||
from data.answer_quest import Answer
|
||||
from data.diary_post import DiaryPost
|
||||
from data.like import Like
|
||||
from data.dislike import Dislike
|
||||
from data.questions import Quest
|
||||
from data.users import User
|
||||
from forms.add_question import AddQuest
|
||||
@ -70,6 +72,30 @@ def main_page():
|
||||
return render_template('base.html', title='moona')
|
||||
|
||||
|
||||
@app.route('/new_dislike/<int:user_id>/<int:post_id>/<string:ret_href>')
|
||||
def new_dislike(user_id, post_id, ret_href):
|
||||
session = db_session.create_session()
|
||||
dislike = Dislike()
|
||||
dislike.user = user_id
|
||||
dislike.post = post_id
|
||||
dislike.date = datetime.datetime.now()
|
||||
session.add(dislike)
|
||||
session.commit()
|
||||
return redirect(f"/{ret_href}")
|
||||
|
||||
|
||||
@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()
|
||||
like = Like()
|
||||
like.user = user_id
|
||||
like.post = post_id
|
||||
like.date = datetime.datetime.now()
|
||||
session.add(like)
|
||||
session.commit()
|
||||
return redirect(f"/{ret_href}")
|
||||
|
||||
|
||||
@app.route('/publications', methods=['GET', 'POST'])
|
||||
def publications():
|
||||
session = db_session.create_session()
|
||||
@ -261,7 +287,7 @@ def diary():
|
||||
pub_post = pub_post[::-1]
|
||||
emotion_pub = []
|
||||
for i in pub_post:
|
||||
emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': []}
|
||||
emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [], 'like': None, 'dislike': None}
|
||||
if i.pos_emot:
|
||||
emotion['pos_emot'] = i.pos_emot.split()
|
||||
else:
|
||||
@ -274,6 +300,12 @@ def diary():
|
||||
emotion['link'] = i.link.split()
|
||||
else:
|
||||
emotion['link'] = None
|
||||
like = db_sess.query(Like).filter(Like.post == i.id).all()
|
||||
if like:
|
||||
emotion['like'] = like
|
||||
dislike = db_sess.query(Like).filter(Like.post == i.id).all()
|
||||
if like:
|
||||
emotion['dislike'] = dislike
|
||||
emotion_pub.append(emotion)
|
||||
lis_emotion = []
|
||||
for i in posts:
|
||||
@ -303,10 +335,11 @@ def diary():
|
||||
db_sess.query(Quest).filter(Quest.id.notin_([i.id for i in post_quest])).first())
|
||||
ans = []
|
||||
for i in post_quest:
|
||||
ans_id = db_sess.query(Answer).filter(
|
||||
Answer.id_question == i.id and Answer.user.id == current_user.id).first()
|
||||
if ans_id:
|
||||
ans.append(ans_id)
|
||||
if i is not None:
|
||||
ans_id = db_sess.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 = {}
|
||||
|
||||
@ -125,4 +125,26 @@ textarea {
|
||||
table {
|
||||
margin-left: 5%;
|
||||
width: 90%;
|
||||
}
|
||||
.like {
|
||||
width: 50%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
.like_block, .dislike_block {
|
||||
border-radius: 22px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
.div_like {
|
||||
background-color: #95e9ff;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
.div_dislike {
|
||||
background-color: #df3c43;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
BIN
static/img/dislike.png
Normal file
BIN
static/img/dislike.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 113 KiB |
BIN
static/img/like.png
Normal file
BIN
static/img/like.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 101 KiB |
@ -78,12 +78,34 @@
|
||||
приватная
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="my_author"><img src="../{{ current_user.photo }}" width="40" height="40" style="border-radius: 22px">
|
||||
<form>
|
||||
<table class="like">
|
||||
<th class="like_block">
|
||||
<div class="div_like">
|
||||
<a type="button"
|
||||
href="/new_like/{{current_user.id}}/{{item.id}}/diary">
|
||||
<img src="../static/img/like.png" width="50" height="50"
|
||||
style="margin-left: auto;margin-right: auto;">
|
||||
</a></div>
|
||||
</th>
|
||||
<th class="dislike_block">
|
||||
<div class="div_dislike">
|
||||
<a type="button" class="dislike"
|
||||
href="/new_dislike/{{current_user.id}}/{{item.id}}/diary">
|
||||
<img src="../static/img/dislike.png" width="50" height="50"
|
||||
style="margin-left: auto;margin-right: auto;">
|
||||
</a>
|
||||
</div>
|
||||
</th>
|
||||
</table>
|
||||
</form>
|
||||
<div class="my_author"><img src="../{{ current_user.photo }}" width="40" height="40"
|
||||
style="border-radius: 22px">
|
||||
<strong style="color: #ffffff">{{ current_user.name }}</strong>
|
||||
</div>
|
||||
<strong style="color:#ffffff">{{item.date}}</strong>
|
||||
<div>
|
||||
<a style="border-radius: 15px;" href="/post/{{ item.id }}" class="btn", id="edit_btn">
|
||||
<a style="border-radius: 15px;" href="/post/{{ item.id }}" class="btn" , id="edit_btn">
|
||||
Изменить
|
||||
</a>
|
||||
<a style="border-radius: 15px;" href="/post_deleted/{{ item.id }}" class="btn btn-danger">
|
||||
@ -120,11 +142,14 @@
|
||||
<summary class="emot_block">
|
||||
<strong class="emot_block">Позитивные эмоции</strong>
|
||||
</summary>
|
||||
<ul style="list-style-type: none">
|
||||
<ul style="list-style-type: none">
|
||||
{% for item2 in emotion[loop.index0]['pos_emot'] %}
|
||||
<li><div class="emot"><strong class="alert alert-success" role="alert" style="border-radius: 22px;">{{item2}}</strong></div></li>
|
||||
<li>
|
||||
<div class="emot"><strong class="alert alert-success" role="alert"
|
||||
style="border-radius: 22px;">{{item2}}</strong></div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</ul>
|
||||
</details>
|
||||
</div>
|
||||
{% endif %}
|
||||
@ -136,7 +161,10 @@
|
||||
</summary>
|
||||
<ul style="list-style-type: none">
|
||||
{% for item2 in emotion[loop.index0]['nig_emot'] %}
|
||||
<li><div class="emot"><strong class="alert alert-danger" role="alert" style="border-radius: 22px;">{{item2}}</strong></div></li>
|
||||
<li>
|
||||
<div class="emot"><strong class="alert alert-danger" role="alert"
|
||||
style="border-radius: 22px;">{{item2}}</strong></div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</details>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user