Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
Implemented question deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
evgfilim1 committed Aug 18, 2018
1 parent 8959581 commit 23d5251
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def edit_question(question_id):
q = Question.query.get(question_id)
if q is None:
flash(f'Вопроса с id={question_id} не существует')
return redirect(back('admin'))
return redirect(back('manage_questions'))
form = AddQuestionForm()
if form.validate_on_submit():
q.title = form.question.data
Expand Down Expand Up @@ -276,5 +276,18 @@ def upload_questions():
return redirect(url_for('manage_questions'))


@app.route('/admin/questions/delete/<int:question_id>')
@admin_required
def delete_question(question_id):
q = Question.query.get(question_id)
if not q:
flash(f'Вопроса с id={question_id} не существует')
return redirect(back('manage_questions'))
db.session.delete(q)
db.session.commit()
flash('Вопрос удалён!', 'success')
return redirect(back('manage_questions'))


if __name__ == '__main__':
app.run()
1 change: 1 addition & 0 deletions templates/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{% endif %}
{% if editable %}
<p><a href="{{ url_for('edit_question', question_id=q.id) }}">Редактировать вопрос</a></p>
<p><a class="destructive-confirm" href="{{ url_for('delete_question', question_id=q.id) }}">Удалить вопрос</a></p>
{% endif %}
<div class="answers">
{# TODO: shuffle answers #}
Expand Down

0 comments on commit 23d5251

Please sign in to comment.