Изменены css и html файлы страницы diary, добавлено корректное отображение вопросов, возможность отвечать на них и редактировать ответы.
This commit is contained in:
parent
2040c3fde6
commit
c00724f5e2
BIN
db/moona_data.db
BIN
db/moona_data.db
Binary file not shown.
8
forms/answer_quest.py
Normal file
8
forms/answer_quest.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from flask_wtf import FlaskForm
|
||||||
|
from wtforms import StringField, SubmitField
|
||||||
|
from wtforms.validators import DataRequired
|
||||||
|
|
||||||
|
|
||||||
|
class AnswerQuest(FlaskForm):
|
||||||
|
answer = StringField('Ваш ответ:', validators=[DataRequired()])
|
||||||
|
submit = SubmitField('Сохранить')
|
||||||
45
main.py
45
main.py
@ -13,6 +13,7 @@ from data.diary_post import DiaryPost
|
|||||||
from data.questions import Quest
|
from data.questions import Quest
|
||||||
from data.users import User
|
from data.users import User
|
||||||
from forms.add_question import AddQuest
|
from forms.add_question import AddQuest
|
||||||
|
from forms.answer_quest import AnswerQuest
|
||||||
from forms.login import LoginForm
|
from forms.login import LoginForm
|
||||||
from forms.post import AddPost
|
from forms.post import AddPost
|
||||||
from forms.recovery import RecoveryForm, Conf, Finish
|
from forms.recovery import RecoveryForm, Conf, Finish
|
||||||
@ -69,6 +70,35 @@ def main_page():
|
|||||||
return render_template('base.html', title='moona')
|
return render_template('base.html', title='moona')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/answer_quest/<int:id>', methods=['GET', 'POST'])
|
||||||
|
def answer_quest(id):
|
||||||
|
session = db_session.create_session()
|
||||||
|
answer = AnswerQuest()
|
||||||
|
quest = session.query(Quest).filter(Quest.id == id).first()
|
||||||
|
if request.method == 'GET':
|
||||||
|
if session.query(Answer).filter(Answer.id_question == id).first():
|
||||||
|
ans_quest = session.query(Answer).filter(Answer.id_question == id).first()
|
||||||
|
answer.answer.data = ans_quest.answer
|
||||||
|
if answer.validate_on_submit():
|
||||||
|
if not session.query(Answer).filter(Answer.id_question == id).first():
|
||||||
|
answer_user = Answer(id_question=id,
|
||||||
|
answer=answer.answer.data,
|
||||||
|
user=current_user.id,
|
||||||
|
date=datetime.date.today())
|
||||||
|
quest.one_used = True
|
||||||
|
if len(session.query(Answer).filter(Answer.id_question == id).all()) == len(session.query(User).all()):
|
||||||
|
quest.all_used = True
|
||||||
|
session.add(answer_user)
|
||||||
|
session.commit()
|
||||||
|
return redirect('/diary')
|
||||||
|
else:
|
||||||
|
ans_quest = session.query(Answer).filter(Answer.id_question == id).first()
|
||||||
|
ans_quest.answer = answer.answer.data
|
||||||
|
session.commit()
|
||||||
|
return redirect('/diary')
|
||||||
|
return render_template('answer_quest.html', tetle='Ответ на вопрос', form=answer, message='', quest=quest)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/delete_quest/<int:id>', methods=['GET', 'POST'])
|
@app.route('/delete_quest/<int:id>', methods=['GET', 'POST'])
|
||||||
def delete_quest(id):
|
def delete_quest(id):
|
||||||
session = db_session.create_session()
|
session = db_session.create_session()
|
||||||
@ -212,9 +242,18 @@ def diary():
|
|||||||
while len(post_quest) < days_reg:
|
while len(post_quest) < days_reg:
|
||||||
post_quest.append(
|
post_quest.append(
|
||||||
db_sess.query(Quest).filter(Quest.id.notin_([i.id for i in post_quest])).first())
|
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 == current_user.id).first()
|
||||||
|
if ans_id:
|
||||||
|
ans.append(ans_id)
|
||||||
|
if ans:
|
||||||
|
ls = [i.id_question for i in ans]
|
||||||
else:
|
else:
|
||||||
posts = None
|
posts = None
|
||||||
return render_template('diary.html', title='moona', my_post=posts, message='', question=post_quest)
|
return render_template('diary.html', title='moona', my_post=posts, message='', question=post_quest[::-1],
|
||||||
|
ans=ans[::-1], ls=ls, ln=len(ans))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
@ -255,7 +294,6 @@ def confirmation():
|
|||||||
send_msg = True
|
send_msg = True
|
||||||
if conf.validate_on_submit():
|
if conf.validate_on_submit():
|
||||||
if str(conf.code_key.data).strip() == str(secret_code).strip():
|
if str(conf.code_key.data).strip() == str(secret_code).strip():
|
||||||
print(secret_code)
|
|
||||||
if form.photo.data:
|
if form.photo.data:
|
||||||
user = User(
|
user = User(
|
||||||
name=form.name.data,
|
name=form.name.data,
|
||||||
@ -275,7 +313,8 @@ def confirmation():
|
|||||||
age=form.age.data,
|
age=form.age.data,
|
||||||
about=form.about.data,
|
about=form.about.data,
|
||||||
email=form.email.data,
|
email=form.email.data,
|
||||||
role='user'
|
role='user',
|
||||||
|
photo='../static/img/Икона.png'
|
||||||
)
|
)
|
||||||
user.set_password(form.password.data)
|
user.set_password(form.password.data)
|
||||||
session.add(user)
|
session.add(user)
|
||||||
|
|||||||
@ -18,7 +18,6 @@ text-align: center;
|
|||||||
width: 70%;
|
width: 70%;
|
||||||
}
|
}
|
||||||
#all_my_post {
|
#all_my_post {
|
||||||
width: 35%;
|
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
@ -49,3 +48,23 @@ margin-left: 85%;
|
|||||||
#edit_btn {
|
#edit_btn {
|
||||||
background-color: #c5f1ff;
|
background-color: #c5f1ff;
|
||||||
}
|
}
|
||||||
|
#row2 {
|
||||||
|
width: 35%;
|
||||||
|
}
|
||||||
|
#all_my_question {
|
||||||
|
width: 30%;
|
||||||
|
}
|
||||||
|
#row1 {
|
||||||
|
width: 35%;
|
||||||
|
}
|
||||||
|
.question, .my_post {
|
||||||
|
background-color:#7fc3ff;
|
||||||
|
border-radius: 22px;
|
||||||
|
width: 90%;
|
||||||
|
margin-left: 5%;
|
||||||
|
}
|
||||||
|
.is_ans {
|
||||||
|
background-color:#ddefff;
|
||||||
|
border:2px solid #FFFFFF;
|
||||||
|
border-radius: 25px;
|
||||||
|
}
|
||||||
@ -2,7 +2,15 @@
|
|||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
|
.add_q{
|
||||||
|
width: 50%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.h_q {
|
.h_q {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
form {
|
||||||
|
width: 60%;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
BIN
static/img/MoonCcircl.ico
Normal file
BIN
static/img/MoonCcircl.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
@ -1,5 +1,5 @@
|
|||||||
<link rel="stylesheet" href="../static/css/diary.css">
|
<link rel="stylesheet" href="../static/css/diary.css">
|
||||||
<link rel="stylesheet" href="../static/css/add_question.css">
|
<link rel="stylesheet" href="../static/css/question.css">
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|||||||
43
templates/answer_quest.html
Normal file
43
templates/answer_quest.html
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<link rel="stylesheet" href="../static/css/diary.css">
|
||||||
|
<link rel="stylesheet" href="../static/css/question.css">
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if current_user.is_authenticated %}
|
||||||
|
<div class="add_q">
|
||||||
|
<h1 class="h_q">Ответьте на вопрос</h1>
|
||||||
|
<div class="alert alert-primary" role="alert"
|
||||||
|
style="background-color:#ddefff; border:2px solid #FFFFFF; border-radius: 25px;width: 60%;text-align:
|
||||||
|
center;margin-left: auto;
|
||||||
|
margin-right: auto;">
|
||||||
|
|
||||||
|
<h2 class="h_q">{{quest.quest}}</h2>
|
||||||
|
</div>
|
||||||
|
<form action="" method="POST" enctype="multipart/form-data">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ form.csrf_token }}
|
||||||
|
<p>
|
||||||
|
{{ form.answer.label }}<br>
|
||||||
|
{{ form.answer(class="form-control") }}<br>
|
||||||
|
{% for error in form.answer.errors %}
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
<p>{{ form.submit(type="submit", class="btn btn-primary") }}</p>
|
||||||
|
{% if message != '' %}
|
||||||
|
<div class="alert alert-danger" role="alert">{{ message }}</div>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="bad_user">
|
||||||
|
<div class="bad_centre">
|
||||||
|
<h1 id="hz1">Вы не авторизованы в системе</h1>
|
||||||
|
<h2 id="hz2">Поэтому вам не доступна эта страница</h2>
|
||||||
|
<p></p>
|
||||||
|
<img id="image" src="../static/img/Надпись Moona без фона.png"></div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
@ -7,6 +7,7 @@
|
|||||||
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
|
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
|
||||||
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
|
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
|
||||||
crossorigin="anonymous">
|
crossorigin="anonymous">
|
||||||
|
<link rel="icon" href="../static/img/MoonCcircl.ico" type="image/x-icon">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:wght@700&family=Montserrat+Alternates:wght@600&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:wght@700&family=Montserrat+Alternates:wght@600&display=swap" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../static/css/base.css">
|
<link rel="stylesheet" href="../static/css/base.css">
|
||||||
<title>{{title}}</title>
|
<title>{{title}}</title>
|
||||||
|
|||||||
@ -3,10 +3,17 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a href="/add_post" id="add_post" class="btn btn-primary" style="background-color:#1daff0"><strong>Добавить
|
<a href="/add_post" id="add_post" class="btn btn-primary"
|
||||||
|
style="background-color:#1daff0;border-radius: 15px;"><strong>Добавить
|
||||||
запись</strong></a>
|
запись</strong></a>
|
||||||
</div><h1 class="my_post_zag">Мои мысли</h1>
|
</div>
|
||||||
|
<table>
|
||||||
|
<td id="row1">
|
||||||
|
</td>
|
||||||
|
<td id="row2">
|
||||||
|
<h1 class="my_post_zag">Мои мысли</h1>
|
||||||
<div id="all_my_post">
|
<div id="all_my_post">
|
||||||
{% if my_post != [] %}
|
{% if my_post != [] %}
|
||||||
{% for item in my_post %}
|
{% for item in my_post %}
|
||||||
@ -44,7 +51,8 @@
|
|||||||
{% if item.photo != None %}
|
{% if item.photo != None %}
|
||||||
<p></p>
|
<p></p>
|
||||||
<div class="photo">
|
<div class="photo">
|
||||||
<img width="90%" src="{{ item.photo }}">
|
<img width="90%" src="{{ item.photo }}"
|
||||||
|
style="border-radius: 22px; border:2px solid #FFFFFF;">
|
||||||
</div>
|
</div>
|
||||||
<p></p>
|
<p></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -56,21 +64,25 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.public == 1 or item.public == 'True' %}
|
{% if item.public == 1 or item.public == 'True' %}
|
||||||
<div class="alert alert-success" role="alert" id="pub">Запись опубликована</div>
|
<div style="border-radius: 22px;" class="alert alert-success" role="alert" id="pub">Запись
|
||||||
|
опубликована
|
||||||
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="alert alert-danger" role="alert" id="ptivate">Запись приватная</div>
|
<div style="border-radius: 22px;" class="alert alert-danger" role="alert" id="ptivate">Запись
|
||||||
|
приватная
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="my_author" style="style=position:absolute; width:148px; height:44px; left:255px; -webkit-border-radius:
|
<div class="my_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:
|
22px;-moz-border-radius: 22px;border-radius: 22px; border:2px solid #FFFFFF; background-color:#1daff0; top:
|
||||||
98px;"><img src="../{{ current_user.photo }}" width="40" height="40" style="border-radius: 50%">
|
98px;"><img src="../{{ current_user.photo }}" width="40" height="40" style="border-radius: 22px">
|
||||||
<strong style="color: #ffffff">{{ current_user.name }}</strong>
|
<strong style="color: #ffffff">{{ current_user.name }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<strong style="color:#ffffff">{{item.date}}</strong>
|
<strong style="color:#ffffff">{{item.date}}</strong>
|
||||||
<div>
|
<div>
|
||||||
<a 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>
|
||||||
<a href="/post_deleted/{{ item.id }}" class="btn btn-danger">
|
<a style="border-radius: 15px;" href="/post_deleted/{{ item.id }}" class="btn btn-danger">
|
||||||
Удалить
|
Удалить
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@ -82,13 +94,31 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="all_my_question">
|
</td>
|
||||||
|
<td id="all_my_question">
|
||||||
|
<h1 class="my_post_zag">Вопросы дня</h1>
|
||||||
|
<div class="my_post">
|
||||||
|
<div class="question">
|
||||||
{% for item in question %}
|
{% for item in question %}
|
||||||
<div class="alert alert-primary" role="alert">
|
<a href="/answer_quest/{{item.id}}" class="btn">
|
||||||
|
{% if item.id in ls %}
|
||||||
|
<div class="is_ans">
|
||||||
<strong>{{item.quest}}</strong>
|
<strong>{{item.quest}}</strong>
|
||||||
|
<div class="alert alert-success" role="alert" style="border-radius: 25px;">Ответ есть</div>
|
||||||
|
<strong>{{ans[ln - loop.index0].answer}}</strong>
|
||||||
</div>
|
</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 %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="bad_user">
|
<div class="bad_user">
|
||||||
<div class="bad_centre">
|
<div class="bad_centre">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user