diff --git a/db/moona_data.db b/db/moona_data.db index e3c406a..4bbfa02 100644 Binary files a/db/moona_data.db and b/db/moona_data.db differ diff --git a/forms/answer_quest.py b/forms/answer_quest.py new file mode 100644 index 0000000..6f6c29e --- /dev/null +++ b/forms/answer_quest.py @@ -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('Сохранить') diff --git a/main.py b/main.py index b7e33e6..a3f3522 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ from data.diary_post import DiaryPost from data.questions import Quest from data.users import User from forms.add_question import AddQuest +from forms.answer_quest import AnswerQuest from forms.login import LoginForm from forms.post import AddPost from forms.recovery import RecoveryForm, Conf, Finish @@ -69,6 +70,35 @@ def main_page(): return render_template('base.html', title='moona') +@app.route('/answer_quest/', 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/', methods=['GET', 'POST']) def delete_quest(id): session = db_session.create_session() @@ -212,9 +242,18 @@ def diary(): 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()) + + 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: 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') @@ -255,7 +294,6 @@ def confirmation(): send_msg = True if conf.validate_on_submit(): if str(conf.code_key.data).strip() == str(secret_code).strip(): - print(secret_code) if form.photo.data: user = User( name=form.name.data, @@ -275,7 +313,8 @@ def confirmation(): age=form.age.data, about=form.about.data, email=form.email.data, - role='user' + role='user', + photo='../static/img/Икона.png' ) user.set_password(form.password.data) session.add(user) diff --git a/static/css/diary.css b/static/css/diary.css index eb3be74..74e0bab 100644 --- a/static/css/diary.css +++ b/static/css/diary.css @@ -18,7 +18,6 @@ text-align: center; width: 70%; } #all_my_post { -width: 35%; margin-left: auto; margin-right: auto; } @@ -48,4 +47,24 @@ margin-left: 85%; } #edit_btn { 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; } \ No newline at end of file diff --git a/static/css/add_question.css b/static/css/question.css similarity index 52% rename from static/css/add_question.css rename to static/css/question.css index 31ba6ba..db84ce8 100644 --- a/static/css/add_question.css +++ b/static/css/question.css @@ -2,7 +2,15 @@ margin-left: auto; margin-right: auto; width: 50%; +.add_q{ + width: 50%; +} } .h_q { text-align: center; +} +form { +width: 60%; +margin-left: auto; + margin-right: auto; } \ No newline at end of file diff --git a/static/img/MoonCcircl.ico b/static/img/MoonCcircl.ico new file mode 100644 index 0000000..6dae1ce Binary files /dev/null and b/static/img/MoonCcircl.ico differ diff --git a/templates/add_question.html b/templates/add_question.html index 5578bb1..865c5f0 100644 --- a/templates/add_question.html +++ b/templates/add_question.html @@ -1,5 +1,5 @@ - + {% extends "base.html" %} {% block content %} diff --git a/templates/answer_quest.html b/templates/answer_quest.html new file mode 100644 index 0000000..cc32b8e --- /dev/null +++ b/templates/answer_quest.html @@ -0,0 +1,43 @@ + + +{% extends "base.html" %} + +{% block content %} +{% if current_user.is_authenticated %} +
+

Ответьте на вопрос

+ +
+ {{ form.hidden_tag() }} + {{ form.csrf_token }} +

+ {{ form.answer.label }}
+ {{ form.answer(class="form-control") }}
+ {% for error in form.answer.errors %} +

+ {% endfor %} +

+

{{ form.submit(type="submit", class="btn btn-primary") }}

+ {% if message != '' %} + + {% endif %} +
+
+{% else %} +
+
+

Вы не авторизованы в системе

+

Поэтому вам не доступна эта страница

+

+
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index b90d104..572d0ae 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,6 +7,7 @@ href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> + {{title}} diff --git a/templates/diary.html b/templates/diary.html index 1095793..8f3320a 100644 --- a/templates/diary.html +++ b/templates/diary.html @@ -3,92 +3,122 @@ {% block content %} {% if current_user.is_authenticated %} +
- Добавить + Добавить запись -

Мои мысли

-
- {% if my_post != [] %} - {% for item in my_post %} -
-
- {% if item.name != None %} -

{{item.name}}

+
+ + + + +
+ +

Мои мысли

+
+ {% if my_post != [] %} + {% for item in my_post %} +
+
+ {% if item.name != None %} +

{{item.name}}

+ {% endif %} +
+ {% if item.text != None %} + {{item.text}} + {% endif %} +
+ {% if item.pos_emot != None %} +
+ {% for item2 in item.pos_emot %} + {{item2}} + {% endfor %} +
{% endif %} - - {% if item.text != None %} - {{item.text}} - {% endif %} - - {% if item.pos_emot != None %} -
- {% for item2 in item.pos_emot %} - {{item2}} - {% endfor %} -
- {% endif %} - {% if item.nig_emot != None %} -
- {% for item2 in item.nig_emot %} - {{item2}} - {% endfor %} -
- {% endif %} - {% if item.case != None %} -
- {% for item2 in item.case %} - {{item2}} - {% endfor %} -
- {% endif %} - {% if item.photo != None %} -

-
- -
-

- {% endif %} - {% if item.link != None %} - {% for item2 in item.link %} - - {% endfor %} - {% endif %} - {% if item.public == 1 or item.public == 'True' %} - - {% else %} - - {% endif %} -
+ {% for item2 in item.nig_emot %} + {{item2}} + {% endfor %} +
+ {% endif %} + {% if item.case != None %} +
+ {% for item2 in item.case %} + {{item2}} + {% endfor %} +
+ {% endif %} + {% if item.photo != None %} +

+
+ +
+

+ {% endif %} + {% if item.link != None %} + {% for item2 in item.link %} + + {% endfor %} + {% endif %} + {% if item.public == 1 or item.public == 'True' %} + + {% else %} + + {% endif %} +
- {{ current_user.name }} + 98px;"> + {{ current_user.name }} +
+ {{item.date}} + +
+ {% endfor %} + {% else %} +
+

Ничего не нашлось :с

+
+ {% endif %}
- {{item.date}} -
+

Вопросы дня

+
+
- - {% endfor %} - {% else %} -
-

Ничего не нашлось :с

-
- {% endif %} - -
- {% for item in question %} - - {% endfor %} -
+
{% else %}