username change fix
This commit is contained in:
parent
dfa6c89311
commit
bce05da487
12
app.py
12
app.py
@ -26,6 +26,7 @@ from wtforms.validators import DataRequired, EqualTo, Regexp
|
|||||||
from flask_wtf import FlaskForm, RecaptchaField
|
from flask_wtf import FlaskForm, RecaptchaField
|
||||||
from dotenv import load_dotenv, find_dotenv
|
from dotenv import load_dotenv, find_dotenv
|
||||||
import aiofiles.os
|
import aiofiles.os
|
||||||
|
from sqlalchemy import func, or_
|
||||||
|
|
||||||
dotenv_path = find_dotenv()
|
dotenv_path = find_dotenv()
|
||||||
load_dotenv(dotenv_path, override=True)
|
load_dotenv(dotenv_path, override=True)
|
||||||
@ -234,8 +235,6 @@ class Subscription(db.Model):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<Subscription user_id={self.user_id} author_id={self.author_id}>'
|
return f'<Subscription user_id={self.user_id} author_id={self.author_id}>'
|
||||||
|
|
||||||
from sqlalchemy import func, or_
|
|
||||||
|
|
||||||
def get_content_query(model, subscriptions, search_query):
|
def get_content_query(model, subscriptions, search_query):
|
||||||
query = model.query
|
query = model.query
|
||||||
|
|
||||||
@ -1042,10 +1041,6 @@ def comic_edit(comic_id):
|
|||||||
|
|
||||||
return render_template('comic_edit.html', comic=comic, comic_pages=comic_pages, form=form)
|
return render_template('comic_edit.html', comic=comic, comic_pages=comic_pages, form=form)
|
||||||
|
|
||||||
from flask import flash, redirect, url_for, render_template
|
|
||||||
from werkzeug.utils import secure_filename
|
|
||||||
import os
|
|
||||||
|
|
||||||
def update_related_tables(old_username, new_username):
|
def update_related_tables(old_username, new_username):
|
||||||
|
|
||||||
Comments.query.filter_by(username=old_username).update({"username": new_username})
|
Comments.query.filter_by(username=old_username).update({"username": new_username})
|
||||||
@ -1139,8 +1134,9 @@ def profile_edit():
|
|||||||
elif User.query.filter_by(username=new_username).first():
|
elif User.query.filter_by(username=new_username).first():
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
old_username = current_user.username
|
||||||
current_user.username = new_username
|
current_user.username = new_username
|
||||||
db.session.commit()
|
update_related_tables(old_username, new_username)
|
||||||
return redirect(url_for('profile', username=new_username))
|
return redirect(url_for('profile', username=new_username))
|
||||||
|
|
||||||
elif section == 'bio':
|
elif section == 'bio':
|
||||||
@ -1264,7 +1260,7 @@ def profile(username):
|
|||||||
def user_posts(username):
|
def user_posts(username):
|
||||||
user = User.query.filter_by(username=username).first_or_404()
|
user = User.query.filter_by(username=username).first_or_404()
|
||||||
posts = Post.query.filter_by(username=username).order_by(Post.post_date.desc()).all()
|
posts = Post.query.filter_by(username=username).order_by(Post.post_date.desc()).all()
|
||||||
avatars = {user.username: user.avatar_file for user in User.query.all()} # Словарь аватаров
|
avatars = {user.username: user.avatar_file for user in User.query.all()}
|
||||||
return render_template('post.html', username=username, posts=posts, avatars=avatars)
|
return render_template('post.html', username=username, posts=posts, avatars=avatars)
|
||||||
|
|
||||||
@app.route('/posts/<username>/add_comment/<int:post_id>', methods=['POST'])
|
@app.route('/posts/<username>/add_comment/<int:post_id>', methods=['POST'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user