Главная страница
This commit is contained in:
parent
86c1fa11d4
commit
30b1c3cf73
BIN
db/moona_data.db
BIN
db/moona_data.db
Binary file not shown.
91
main.py
91
main.py
@ -70,7 +70,89 @@ def load_user(user_id):
|
||||
|
||||
@app.route('/')
|
||||
def main_page():
|
||||
return render_template('base.html', title='moona')
|
||||
session = db_session.create_session()
|
||||
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=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/<string:logins>', methods=['GET', 'POST'])
|
||||
@ -170,7 +252,10 @@ def new_like(user_id, post_id, ret_href):
|
||||
session.delete(pop)
|
||||
session.delete(find)
|
||||
session.commit()
|
||||
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()
|
||||
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()
|
||||
|
||||
46
static/css/main.css
Normal file
46
static/css/main.css
Normal file
@ -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%;
|
||||
}
|
||||
@ -38,4 +38,3 @@ details {
|
||||
.hz1 {
|
||||
margin: 5%;
|
||||
font-size: 160%;
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
{% block content %}
|
||||
{% if current_user.is_authenticated %}
|
||||
<h1 class="upp_zag">Дневник</h1>
|
||||
<h1 class="upp_zag">Главная</h1>
|
||||
<div>
|
||||
<a href="/add_post" id="add_post" class="btn btn-primary"
|
||||
style="background-color:#1daff0;border-radius: 15px;"><strong>Добавить
|
||||
|
||||
238
templates/main.html
Normal file
238
templates/main.html
Normal file
@ -0,0 +1,238 @@
|
||||
<link rel="stylesheet" href="../static/css/main.css">
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1 class="upp_zag">Главная</h1>
|
||||
<div>
|
||||
<a href="/add_post" id="add_post" class="btn btn-primary"
|
||||
style="background-color:#1daff0;border-radius: 15px;"><strong>Добавить
|
||||
запись</strong></a>
|
||||
</div>
|
||||
<table>
|
||||
<th class="row1">
|
||||
<div class="rowdiv1">
|
||||
<h1 class="my_post_zag">Вопросы дня</h1>
|
||||
<div class="my_post">
|
||||
<div class="question">
|
||||
{% for item in question %}
|
||||
<a href="/answer_quest/{{item.id}}" class="btn quest_block">
|
||||
{% if item.id in ans %}
|
||||
<div class="is_ans">
|
||||
<strong>{{item.quest}}</strong>
|
||||
<div class="alert alert-success" role="alert" style="border-radius: 25px;">Ответ есть</div>
|
||||
<strong>{{ans[item.id].answer}}</strong>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="is_ans">
|
||||
<strong>{{item.quest}}</strong>
|
||||
<div class="alert alert-danger" role="alert" style="border-radius: 25px;">Ответа нет</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</th>
|
||||
<th class="row2">
|
||||
<div class="rowdiv2">
|
||||
<h2 class="post_zag">Вам будет интересно</h2>
|
||||
{% if for_me_post != [] %}
|
||||
{% for item in for_me_post %}
|
||||
<div class="card-body post">
|
||||
<details>
|
||||
<summary>
|
||||
{% if item.name != None %}
|
||||
<h3 class="card-title post_zag" style="color:#c5f1ff">{{item.name}}</h3>
|
||||
{% 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}}/main">
|
||||
{% 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 %}
|
||||
{% else %}
|
||||
<div class="bad_centre" style="background-color:#1daff0; border-radius: 22px;color:#ffffff">
|
||||
<p class="hz1">Ничего не нашлось :с</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</th>
|
||||
<th class="row3">
|
||||
<div class="rowdiv3">
|
||||
<h2 class="post_zag">Вам понравились эти посты</h2>
|
||||
{% if you_like_that != [] %}
|
||||
{% for item in you_like_that %}
|
||||
<div class="card-body post">
|
||||
<details>
|
||||
<summary>
|
||||
{% if item.name != None %}
|
||||
<h3 class="card-title post_zag" style="color:#c5f1ff">{{item.name}}</h3>
|
||||
{% endif %}
|
||||
</summary>
|
||||
{% if item.text != None %}
|
||||
<strong class="card-text" style="color:#ffffff">{{item.text}}</strong>
|
||||
{% endif %}
|
||||
</details>
|
||||
{% if emotion_you_like_that[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_you_like_that[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_you_like_that[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_you_like_that[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}}/main">
|
||||
{% if emotion_you_like_that[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_you_like_that[loop.index0]['like'] != None %}
|
||||
<p style="color:#ffffff">{{emotion_you_like_that[loop.index0]['like']}}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if emotion_you_like_that[loop.index0]['link'] != None %}
|
||||
<details>
|
||||
<summary class="emot_block">
|
||||
<strong class="emot_block">Ссылки</strong>
|
||||
</summary>
|
||||
<p></p>
|
||||
{% for item2 in emotion_you_like_that[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_you_like_that[loop.index0]['author'].photo }}" width="40" height="40"
|
||||
style="border-radius: 22px">
|
||||
<strong style="color: #ffffff">{{ emotion_you_like_that[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">
|
||||
<p class="hz1">Ничего не нашлось :с</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</th>
|
||||
</table>
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user