Заготовка для отображения ежедневных вопросов
This commit is contained in:
parent
8e4edce065
commit
2040c3fde6
@ -9,6 +9,8 @@ class Answer(SqlAlchemyBase, UserMixin):
|
|||||||
|
|
||||||
id = sqlalchemy.Column(sqlalchemy.Integer,
|
id = sqlalchemy.Column(sqlalchemy.Integer,
|
||||||
primary_key=True, autoincrement=True)
|
primary_key=True, autoincrement=True)
|
||||||
|
id_question = sqlalchemy.Column(sqlalchemy.Integer,
|
||||||
|
sqlalchemy.ForeignKey("questions.id"), nullable=True)
|
||||||
answer = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
answer = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
||||||
user = sqlalchemy.Column(sqlalchemy.Integer,
|
user = sqlalchemy.Column(sqlalchemy.Integer,
|
||||||
sqlalchemy.ForeignKey("users.id"), nullable=True)
|
sqlalchemy.ForeignKey("users.id"), nullable=True)
|
||||||
|
|||||||
@ -10,3 +10,5 @@ class Quest(SqlAlchemyBase, UserMixin):
|
|||||||
id = sqlalchemy.Column(sqlalchemy.Integer,
|
id = sqlalchemy.Column(sqlalchemy.Integer,
|
||||||
primary_key=True, autoincrement=True)
|
primary_key=True, autoincrement=True)
|
||||||
quest = sqlalchemy.Column(sqlalchemy.Text, nullable=False)
|
quest = sqlalchemy.Column(sqlalchemy.Text, nullable=False)
|
||||||
|
all_used = sqlalchemy.Column(sqlalchemy.Boolean, nullable=True, default=False)
|
||||||
|
one_used = sqlalchemy.Column(sqlalchemy.Boolean, nullable=True, default=False)
|
||||||
|
|||||||
BIN
db/moona_data.db
BIN
db/moona_data.db
Binary file not shown.
33
main.py
33
main.py
@ -8,6 +8,7 @@ from flask_restful import abort
|
|||||||
from werkzeug.utils import redirect
|
from werkzeug.utils import redirect
|
||||||
|
|
||||||
from data import db_session
|
from data import db_session
|
||||||
|
from data.answer_quest import Answer
|
||||||
from data.diary_post import DiaryPost
|
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
|
||||||
@ -68,11 +69,23 @@ def main_page():
|
|||||||
return render_template('base.html', title='moona')
|
return render_template('base.html', title='moona')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/delete_quest/<int:id>', methods=['GET', 'POST'])
|
||||||
|
def delete_quest(id):
|
||||||
|
session = db_session.create_session()
|
||||||
|
pos = session.query(Quest).filter(Quest.id == id).first()
|
||||||
|
if pos:
|
||||||
|
session.delete(pos)
|
||||||
|
session.commit()
|
||||||
|
else:
|
||||||
|
abort(404)
|
||||||
|
return redirect('/add_question')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/add_question', methods=['GET', 'POST'])
|
@app.route('/add_question', methods=['GET', 'POST'])
|
||||||
def add_question():
|
def add_question():
|
||||||
que = AddQuest()
|
que = AddQuest()
|
||||||
if que.validate_on_submit():
|
|
||||||
session = db_session.create_session()
|
session = db_session.create_session()
|
||||||
|
if que.validate_on_submit():
|
||||||
if que.quest.data in list(map(lambda x: x.quest, session.query(Quest).all())):
|
if que.quest.data in list(map(lambda x: x.quest, session.query(Quest).all())):
|
||||||
return render_template('add_question.html', message='Такой вопрос уже есть!', title='Добавить вопрос',
|
return render_template('add_question.html', message='Такой вопрос уже есть!', title='Добавить вопрос',
|
||||||
form=que)
|
form=que)
|
||||||
@ -81,7 +94,8 @@ def add_question():
|
|||||||
session.add(new_que)
|
session.add(new_que)
|
||||||
session.commit()
|
session.commit()
|
||||||
que.quest.data = ''
|
que.quest.data = ''
|
||||||
return render_template('add_question.html', message='', title='Добавить вопрос', form=que)
|
return render_template('add_question.html', message='', title='Добавить вопрос', form=que,
|
||||||
|
question=session.query(Quest).all())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/post/<int:id>', methods=['GET', 'POST'])
|
@app.route('/post/<int:id>', methods=['GET', 'POST'])
|
||||||
@ -147,11 +161,14 @@ def add_post():
|
|||||||
pos = AddPost()
|
pos = AddPost()
|
||||||
session = db_session.create_session()
|
session = db_session.create_session()
|
||||||
if pos.validate_on_submit():
|
if pos.validate_on_submit():
|
||||||
|
try:
|
||||||
id = session.query(DiaryPost).order_by(DiaryPost.id)[-1].id
|
id = session.query(DiaryPost).order_by(DiaryPost.id)[-1].id
|
||||||
if id:
|
if id:
|
||||||
id += 1
|
id += 1
|
||||||
else:
|
else:
|
||||||
id = -1
|
id = -1
|
||||||
|
except Exception:
|
||||||
|
id = -1
|
||||||
if pos.photo.data:
|
if pos.photo.data:
|
||||||
diart_pos = DiaryPost(name=pos.name.data,
|
diart_pos = DiaryPost(name=pos.name.data,
|
||||||
text=pos.text.data,
|
text=pos.text.data,
|
||||||
@ -185,9 +202,19 @@ def diary():
|
|||||||
db_sess = db_session.create_session()
|
db_sess = db_session.create_session()
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
posts = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id).all()
|
posts = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id).all()
|
||||||
|
quest = db_sess.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 = db_sess.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(
|
||||||
|
db_sess.query(Quest).filter(Quest.id.notin_([i.id for i in post_quest])).first())
|
||||||
else:
|
else:
|
||||||
posts = None
|
posts = None
|
||||||
return render_template('diary.html', title='moona', my_post=posts, message='')
|
return render_template('diary.html', title='moona', my_post=posts, message='', question=post_quest)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
|
|||||||
BIN
static/app_image/post_photo/Duvakin_post_-1.png
Normal file
BIN
static/app_image/post_photo/Duvakin_post_-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 141 KiB |
8
static/css/add_question.css
Normal file
8
static/css/add_question.css
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.all_div {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
width: 50%;
|
||||||
|
}
|
||||||
|
.h_q {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
@ -1,10 +1,12 @@
|
|||||||
<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">
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if current_user.is_authenticated and (current_user.role == 'admin' or current_user.role == 'moder') %}
|
{% if current_user.is_authenticated and (current_user.role == 'admin' or current_user.role == 'moder') %}
|
||||||
<div>
|
<div class="all_div">
|
||||||
<h1>Введите новый вопрос</h1>
|
<div class="add_q">
|
||||||
|
<h1 class="h_q">Введите новый вопрос</h1>
|
||||||
<form action="" method="POST" enctype="multipart/form-data">
|
<form action="" method="POST" enctype="multipart/form-data">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ form.csrf_token }}
|
{{ form.csrf_token }}
|
||||||
@ -22,6 +24,20 @@
|
|||||||
<div class="alert alert-danger" role="alert">{{ message }}</div>
|
<div class="alert alert-danger" role="alert">{{ message }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="edit_q">
|
||||||
|
<details>
|
||||||
|
<summary>
|
||||||
|
Все вопросы
|
||||||
|
</summary>
|
||||||
|
{% for item in question %}
|
||||||
|
<div class="alert alert-primary" role="alert">
|
||||||
|
<strong>{{item.quest}}</strong>
|
||||||
|
<a href="/delete_quest/{{item.id}}" class="alert alert-danger" role="alert"><strong>Удалить</strong></a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="bad_user">
|
<div class="bad_user">
|
||||||
|
|||||||
@ -8,14 +8,18 @@
|
|||||||
запись</strong></a>
|
запись</strong></a>
|
||||||
</div><h1 class="my_post_zag">Мои мысли</h1>
|
</div><h1 class="my_post_zag">Мои мысли</h1>
|
||||||
<div id="all_my_post">
|
<div id="all_my_post">
|
||||||
|
{% if my_post != [] %}
|
||||||
{% for item in my_post %}
|
{% for item in my_post %}
|
||||||
<div class="card-body" id="my_post">
|
<div class="card-body" id="my_post">
|
||||||
{% if item.name != None %}
|
<details>
|
||||||
|
<summary style="color:#ffffff">{% if item.name != None %}
|
||||||
<h2 class="card-title" id="my_post_zag" style="color:#c5f1ff">{{item.name}}</h2>
|
<h2 class="card-title" id="my_post_zag" style="color:#c5f1ff">{{item.name}}</h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</summary>
|
||||||
{% if item.text != None %}
|
{% if item.text != None %}
|
||||||
<strong class="card-text" id="my_text" style="color:#ffffff">{{item.text}}</strong>
|
<strong class="card-text" id="my_text" style="color:#ffffff">{{item.text}}</strong>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</details>
|
||||||
{% if item.pos_emot != None %}
|
{% if item.pos_emot != None %}
|
||||||
<div class="pos_emot">
|
<div class="pos_emot">
|
||||||
{% for item2 in item.pos_emot %}
|
{% for item2 in item.pos_emot %}
|
||||||
@ -72,6 +76,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<div class="bad_centre" style="background-color:#1daff0; border-radius: 22px;color:#ffffff">
|
||||||
|
<h1 class="hz1">Ничего не нашлось :с</h1>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="all_my_question">
|
||||||
|
{% for item in question %}
|
||||||
|
<div class="alert alert-primary" role="alert">
|
||||||
|
<strong>{{item.quest}}</strong>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="bad_user">
|
<div class="bad_user">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user