mgt c8 finish
This commit is contained in:
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
|
||||
import sqlalchemy as sa
|
||||
|
||||
from app import app, db
|
||||
from app.forms import LoginForm, RegistrationForm, EditProfileForm
|
||||
from app.forms import LoginForm, RegistrationForm, EditProfileForm, EmptyForm
|
||||
from app.models import User
|
||||
|
||||
@app.before_request
|
||||
@@ -18,7 +18,7 @@ def before_request():
|
||||
@app.route('/index')
|
||||
@login_required
|
||||
def index():
|
||||
app.logger.info("AAAAAAAAAAAAAAAAAAAAA")
|
||||
app.logger.info('@@@@@@@@@@@@@@@@@ INFO LOG TEST INDEX')
|
||||
|
||||
user = {'username': 'Finnaa'}
|
||||
posts = [
|
||||
@@ -75,12 +75,12 @@ def register():
|
||||
@login_required
|
||||
def user(username):
|
||||
user = db.first_or_404(sa.select(User).where(User.username == username))
|
||||
#app.logger.info('PROFILE DEBUG ###############################')
|
||||
posts = [
|
||||
{'author': user, 'body': 'Test1'},
|
||||
{'author': user, 'body': 'Test2?'}
|
||||
]
|
||||
return render_template('user.html', user=user, posts=posts)
|
||||
form = EmptyForm()
|
||||
return render_template('user.html', user=user, posts=posts, form=form)
|
||||
|
||||
@app.route('/edit_profile', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@@ -97,3 +97,42 @@ def edit_profile():
|
||||
form.about_me.data = current_user.about_me
|
||||
return render_template('edit_profile.html', title='Edit Profile', form=form)
|
||||
|
||||
@app.route('/follow/<username>', methods=['POST'])
|
||||
@login_required
|
||||
def follow(username):
|
||||
form = EmptyForm()
|
||||
if form.validate_on_submit():
|
||||
user = db.session.scalar(sa.select(User).where(User.username == username))
|
||||
if user is None:
|
||||
flash(f'User {username} not found.')
|
||||
return redirect(url_for('index'))
|
||||
if user == current_user:
|
||||
flash('You cannot follow yourself.')
|
||||
return redirect(url_for('user', username=username))
|
||||
current_user.follow(user)
|
||||
db.session.commit()
|
||||
flash(f'You are now following {username}.')
|
||||
return redirect(url_for('user', username=username))
|
||||
else:
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/unfollow/<username>', methods=['POST'])
|
||||
@login_required
|
||||
def unfollow(username):
|
||||
form = EmptyForm()
|
||||
if form.validate_on_submit():
|
||||
user = db.session.scalar(sa.select(User).where(User.username == username))
|
||||
if user is None:
|
||||
flash(f'User {username} not found.')
|
||||
return redirect(url_for('index'))
|
||||
if user == current_user:
|
||||
flash('You cannot unfollow yourself.')
|
||||
return redirect(url_for('user', username=username))
|
||||
current_user.unfollow(user)
|
||||
db.session.commit()
|
||||
flash(f'You have unfollowed {username}.')
|
||||
return redirect(url_for('user', username=username))
|
||||
else:
|
||||
return redirect(url_for('index'))
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user