Исправлены ошибки удаления постов
This commit is contained in:
parent
a74fd4af62
commit
6e69eb608b
11
main.py
11
main.py
@ -460,11 +460,13 @@ def delete_quest(id):
|
|||||||
@app.route('/add_question', methods=['GET', 'POST'])
|
@app.route('/add_question', methods=['GET', 'POST'])
|
||||||
def add_question():
|
def add_question():
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
|
if current_user.role == 'admin':
|
||||||
que = AddQuest()
|
que = AddQuest()
|
||||||
session = db_session.create_session()
|
session = db_session.create_session()
|
||||||
if que.validate_on_submit():
|
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)
|
||||||
new_que = Quest()
|
new_que = Quest()
|
||||||
new_que.quest = que.quest.data.strip()
|
new_que.quest = que.quest.data.strip()
|
||||||
@ -475,6 +477,8 @@ def add_question():
|
|||||||
question=session.query(Quest).all())
|
question=session.query(Quest).all())
|
||||||
else:
|
else:
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return redirect('/')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/post/<int:id>', methods=['GET', 'POST'])
|
@app.route('/post/<int:id>', methods=['GET', 'POST'])
|
||||||
@ -552,8 +556,7 @@ def post_deleted(id):
|
|||||||
if find_post:
|
if find_post:
|
||||||
if find_post.author == current_user.id or current_user.role == 'admin':
|
if find_post.author == current_user.id or current_user.role == 'admin':
|
||||||
session = db_session.create_session()
|
session = db_session.create_session()
|
||||||
pos = session.query(DiaryPost).filter(DiaryPost.id == id,
|
pos = session.query(DiaryPost).filter(DiaryPost.id == id).first()
|
||||||
DiaryPost.author == current_user.id).first()
|
|
||||||
if pos:
|
if pos:
|
||||||
if pos.photo:
|
if pos.photo:
|
||||||
os.remove(pos.photo[3:])
|
os.remove(pos.photo[3:])
|
||||||
@ -752,7 +755,7 @@ def confirmation():
|
|||||||
about=form.about.data,
|
about=form.about.data,
|
||||||
email=form.email.data,
|
email=form.email.data,
|
||||||
role='user',
|
role='user',
|
||||||
photo='../static/img/Икона.png'
|
photo='../static/img/None_logo.png'
|
||||||
)
|
)
|
||||||
user.set_password(form.password.data)
|
user.set_password(form.password.data)
|
||||||
session.add(user)
|
session.add(user)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user