Исправлено много ошибок

This commit is contained in:
mrmur 2022-05-01 14:21:15 +05:00
parent aa65ac0cda
commit 5cf1bf9fde
4 changed files with 361 additions and 303 deletions

Binary file not shown.

0
main.log Normal file
View File

66
main.py
View File

@ -167,6 +167,7 @@ def main_page():
@app.route('/edit_profile/<string:logins>', methods=['GET', 'POST']) @app.route('/edit_profile/<string:logins>', methods=['GET', 'POST'])
def edit_profile(logins): def edit_profile(logins):
if current_user.is_authenticated:
global photo global photo
global help_arg global help_arg
global help_arg_2 global help_arg_2
@ -203,6 +204,7 @@ def edit_profile(logins):
return redirect('/profile') return redirect('/profile')
else: else:
help_arg_2 = form.email.data help_arg_2 = form.email.data
help_arg = True
return redirect('/confirmation') return redirect('/confirmation')
if request.method == "GET": if request.method == "GET":
if current_user.login == logins: if current_user.login == logins:
@ -215,10 +217,13 @@ def edit_profile(logins):
form.password.data = None form.password.data = None
form.password2.data = None form.password2.data = None
return render_template('edit_profile.html', title='Редактирование профиля', form=form, message='', ph_f=ph_f) return render_template('edit_profile.html', title='Редактирование профиля', form=form, message='', ph_f=ph_f)
else:
return redirect('/login')
@app.route('/profile') @app.route('/profile')
def profile(): def profile():
if current_user.is_authenticated:
global help_arg_2 global help_arg_2
db_sess = db_session.create_session() db_sess = db_session.create_session()
pub_post = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id, DiaryPost.public == 1).all() pub_post = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id, DiaryPost.public == 1).all()
@ -246,11 +251,15 @@ def profile():
emotion['is_like'] = 1 emotion['is_like'] = 1
emotion_pub.append(emotion) emotion_pub.append(emotion)
message = 'Ваша почта успешно изменена!' if help_arg_2 == 'EditEmail' else '' message = 'Ваша почта успешно изменена!' if help_arg_2 == 'EditEmail' else ''
return render_template('profile.html', title='Профиль', pub_post=pub_post, emotion_pub=emotion_pub, message=message) return render_template('profile.html', title='Профиль', pub_post=pub_post, emotion_pub=emotion_pub,
message=message)
else:
return redirect('/login')
@app.route('/new_like/<int:user_id>/<int:post_id>/<string:ret_href>') @app.route('/new_like/<int:user_id>/<int:post_id>/<string:ret_href>')
def new_like(user_id, post_id, ret_href): def new_like(user_id, post_id, ret_href):
if current_user.is_authenticated:
session = db_session.create_session() session = db_session.create_session()
find = session.query(Like).filter(Like.post == post_id, Like.user == user_id).first() find = session.query(Like).filter(Like.post == post_id, Like.user == user_id).first()
if find: if find:
@ -286,6 +295,8 @@ def new_like(user_id, post_id, ret_href):
return redirect(f"/{ret_href}") return redirect(f"/{ret_href}")
else: else:
return redirect('/') return redirect('/')
else:
return redirect('/')
@app.route('/publications', methods=['GET', 'POST']) @app.route('/publications', methods=['GET', 'POST'])
@ -333,11 +344,14 @@ def publications():
if pop: if pop:
if len(pop) > 50: if len(pop) > 50:
pop = pop[:50] pop = pop[:50]
pop_post = [session.query(DiaryPost).filter(DiaryPost.public == 1, DiaryPost.id == i.post).first() for i in pop] pop_post = list(
map(lambda x: session.query(DiaryPost).filter(DiaryPost.public == 1, DiaryPost.id == x.post).first(), pop))
emotion_pop = [] emotion_pop = []
for i in pop_post: for i in pop_post:
logging.warning(f'{datetime.datetime.now()}:{i} - i_pop_post')
emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [], emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [],
'author': session.query(User).filter(User.id == i.author).first(), 'like': None, 'is_like': 0} 'author': session.query(User).filter(User.id == i.author).first(), 'like': None,
'is_like': 0}
if i.pos_emot: if i.pos_emot:
emotion['pos_emot'] = i.pos_emot.split() emotion['pos_emot'] = i.pos_emot.split()
else: else:
@ -396,6 +410,7 @@ def publications():
@app.route('/answer_quest/<int:id>', methods=['GET', 'POST']) @app.route('/answer_quest/<int:id>', methods=['GET', 'POST'])
def answer_quest(id): def answer_quest(id):
if current_user.is_authenticated:
session = db_session.create_session() session = db_session.create_session()
answer = AnswerQuest() answer = AnswerQuest()
quest = session.query(Quest).filter(Quest.id == id).first() quest = session.query(Quest).filter(Quest.id == id).first()
@ -421,10 +436,13 @@ def answer_quest(id):
session.commit() session.commit()
return redirect('/diary') return redirect('/diary')
return render_template('answer_quest.html', tetle='Ответ на вопрос', form=answer, message='', quest=quest) return render_template('answer_quest.html', tetle='Ответ на вопрос', form=answer, message='', quest=quest)
else:
return redirect('/')
@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):
if current_user.is_authenticated:
session = db_session.create_session() session = db_session.create_session()
pos = session.query(Quest).filter(Quest.id == id).first() pos = session.query(Quest).filter(Quest.id == id).first()
if pos: if pos:
@ -433,10 +451,13 @@ def delete_quest(id):
else: else:
abort(404) abort(404)
return redirect('/add_question') return redirect('/add_question')
else:
return redirect('/')
@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:
que = AddQuest() que = AddQuest()
session = db_session.create_session() session = db_session.create_session()
if que.validate_on_submit(): if que.validate_on_submit():
@ -450,10 +471,17 @@ def add_question():
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()) question=session.query(Quest).all())
else:
return redirect('/')
@app.route('/post/<int:id>', methods=['GET', 'POST']) @app.route('/post/<int:id>', methods=['GET', 'POST'])
def post_edit(id): def post_edit(id):
if current_user.is_authenticated:
session = db_session.create_session()
find_post = session.query(DiaryPost).filter(DiaryPost.id == id).first()
if find_post:
if find_post.author == current_user.id:
global photo global photo
global help_arg global help_arg
post_ed = AddPost() post_ed = AddPost()
@ -494,18 +522,33 @@ def post_edit(id):
os.remove(help_arg[3:]) os.remove(help_arg[3:])
help_arg = False help_arg = False
if post_ed.photo.data: if post_ed.photo.data:
post_exc.photo = save_photo(post_ed.photo.data, current_user.login, post=True, id_post=post_exc.id) post_exc.photo = save_photo(post_ed.photo.data, current_user.login, post=True,
id_post=post_exc.id)
else: else:
post_exc.photo = photo post_exc.photo = photo
check_pop = session.query(Popularity).filter(Popularity.post == post_exc.id).first()
if post_ed.public.data and check_pop:
session.delete(check_pop)
session.commit() session.commit()
return redirect('/diary') return redirect('/diary')
else: else:
abort(404) abort(404)
return render_template('post.html', form=post_ed, message='', title='Изменить запись', pht=ph_f) return render_template('post.html', form=post_ed, message='', title='Изменить запись', pht=ph_f)
else:
return redirect('/diary')
else:
return redirect('/diary')
else:
return redirect('/login')
@app.route('/post_deleted/<int:id>', methods=['GET', 'POST']) @app.route('/post_deleted/<int:id>', methods=['GET', 'POST'])
def post_deleted(id): def post_deleted(id):
if current_user.is_authenticated:
session = db_session.create_session()
find_post = session.query(DiaryPost).filter(DiaryPost.id == id).first()
if find_post:
if find_post.author == current_user.id:
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,
DiaryPost.author == current_user.id).first() DiaryPost.author == current_user.id).first()
@ -517,10 +560,17 @@ def post_deleted(id):
else: else:
abort(404) abort(404)
return redirect('/diary') return redirect('/diary')
else:
return redirect('/diary')
else:
return redirect('/diary')
else:
return redirect('/login')
@app.route('/add_post', methods=['GET', 'POST']) @app.route('/add_post', methods=['GET', 'POST'])
def add_post(): def add_post():
if current_user.is_authenticated:
pos = AddPost() pos = AddPost()
session = db_session.create_session() session = db_session.create_session()
if pos.validate_on_submit(): if pos.validate_on_submit():
@ -558,6 +608,8 @@ def add_post():
session.commit() session.commit()
return redirect("/diary") return redirect("/diary")
return render_template('post.html', form=pos, title='Новый пост', message='') return render_template('post.html', form=pos, title='Новый пост', message='')
else:
return redirect('/login')
@app.route('/diary', methods=['GET', 'POST']) @app.route('/diary', methods=['GET', 'POST'])
@ -663,6 +715,7 @@ def login():
@app.route('/confirmation', methods=['GET', 'POST']) @app.route('/confirmation', methods=['GET', 'POST'])
def confirmation(): def confirmation():
global help_arg global help_arg
if help_arg:
global send_msg global send_msg
global secret_code global secret_code
global photo global photo
@ -703,6 +756,7 @@ def confirmation():
session.add(user) session.add(user)
session.commit() session.commit()
send_msg = False send_msg = False
help_arg = False
return redirect('/login') return redirect('/login')
else: else:
return render_template('confirmation_reg.html', title='Подтверждение', form=conf, return render_template('confirmation_reg.html', title='Подтверждение', form=conf,
@ -721,8 +775,11 @@ def confirmation():
help_arg_2 = 'EditEmail' help_arg_2 = 'EditEmail'
session.commit() session.commit()
send_msg = False send_msg = False
help_arg = False
return redirect('/profile') return redirect('/profile')
return render_template('confirmation_reg.html', title='Подтверждение', form=conf, message='') return render_template('confirmation_reg.html', title='Подтверждение', form=conf, message='')
else:
return redirect('/')
@app.route('/register', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
@ -796,6 +853,7 @@ def main():
serve(app, host='0.0.0.0', port=5000) serve(app, host='0.0.0.0', port=5000)
except Exception as error: except Exception as error:
logging.warning(f'{datetime.datetime.now()}:{error}') logging.warning(f'{datetime.datetime.now()}:{error}')
print(error)
if __name__ == '__main__': if __name__ == '__main__':

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB