mgt c8 finish

This commit is contained in:
finn 2024-08-04 09:40:09 -07:00
parent 63bdf8d164
commit 2f920f3b6f
6 changed files with 66 additions and 10 deletions

0
backend/Dockerfile Executable file → Normal file
View File

View File

@ -43,6 +43,7 @@ class EditProfileForm(FlaskForm):
if user is not None: if user is not None:
raise ValidationError('Please use a different username.') raise ValidationError('Please use a different username.')
class EmptyForm(FlaskForm):
submit = SubmitField('Submit')

View File

@ -5,7 +5,7 @@ from datetime import datetime, timezone
import sqlalchemy as sa import sqlalchemy as sa
from app import app, db 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 from app.models import User
@app.before_request @app.before_request
@ -18,7 +18,7 @@ def before_request():
@app.route('/index') @app.route('/index')
@login_required @login_required
def index(): def index():
app.logger.info("AAAAAAAAAAAAAAAAAAAAA") app.logger.info('@@@@@@@@@@@@@@@@@ INFO LOG TEST INDEX')
user = {'username': 'Finnaa'} user = {'username': 'Finnaa'}
posts = [ posts = [
@ -75,12 +75,12 @@ def register():
@login_required @login_required
def user(username): def user(username):
user = db.first_or_404(sa.select(User).where(User.username == username)) user = db.first_or_404(sa.select(User).where(User.username == username))
#app.logger.info('PROFILE DEBUG ###############################')
posts = [ posts = [
{'author': user, 'body': 'Test1'}, {'author': user, 'body': 'Test1'},
{'author': user, 'body': 'Test2?'} {'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']) @app.route('/edit_profile', methods=['GET', 'POST'])
@login_required @login_required
@ -97,3 +97,42 @@ def edit_profile():
form.about_me.data = current_user.about_me form.about_me.data = current_user.about_me
return render_template('edit_profile.html', title='Edit Profile', form=form) 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'))

View File

@ -10,12 +10,28 @@
<h1>Udebug: {{ user }}</h1> <h1>Udebug: {{ user }}</h1>
{% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %} {% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %}
{% if user.last_seen %}<p>Last activity:{{ user.last_seen }}</p>{% endif %} {% if user.last_seen %}<p>Last activity:{{ user.last_seen }}</p>{% endif %}
{% if user == current_user %}
<p><a href="{{ url_for('edit_profile') }}">Edit Profile</a></p>
{% elif not current_user.is_following(user) %}
<p>
<form action="{{ url_for('follow', username=user.username) }}" method="post">
{{ form.hidden_tag() }}
{{ form.submit(value='Follow') }}
</form>
</p>
{% else %}
<p>
<form action="{{ url_for('unfollow', username=user.username) }}" method="post">
{{ form.hidden_tag() }}
{{ form.submit(value='Unfollow') }}
</form>
</p>
{% endif %}
</td> </td>
</tr> </tr>
</table> </table>
{% if user == current_user %}
<p><a href="{{ url_for('edit_profile') }}">Edit Profile</a></p>
{% endif %}
<hr> <hr>
{% for post in posts %} {% for post in posts %}
{% include '_post.html' %} {% include '_post.html' %}

View File

@ -5,8 +5,8 @@ basedir = os.path.abspath(os.path.dirname(__file__))
class Config: class Config:
SECRET_KEY = os.environ.get('FLASK_SECRET_KEY') or 'flasksk' SECRET_KEY = os.environ.get('FLASK_SECRET_KEY') or 'flasksk'
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'zapp.db') #SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'zapp.db')
#SQLALCHEMY_DATABASE_URI = 'mariadb+mariadbconnector://flasku:' + os.environ.get('MYSQL_PASSWORD') + '@db:3306/flask' SQLALCHEMY_DATABASE_URI = 'mariadb+mariadbconnector://flasku:' + os.environ.get('MYSQL_PASSWORD') + '@db:3306/flask'
#MAIL_SERVER = 'pmb' #MAIL_SERVER = 'pmb'
MAIL_SERVER = '' MAIL_SERVER = ''

0
backend/dbdb.sh Normal file → Executable file
View File