1
0
forked from finn/site

mgt c6 done

This commit is contained in:
finn 2024-08-03 05:34:12 -07:00
parent 2b122f6ab2
commit 626ababdc3
3 changed files with 15 additions and 13 deletions

View File

@ -1,13 +1,19 @@
from flask import render_template, flash, redirect, url_for, request from flask import render_template, flash, redirect, url_for, request
from flask_login import current_user, login_user, logout_user, login_required
from urllib.parse import urlsplit from urllib.parse import urlsplit
from datetime import datetime, timezone from datetime import datetime, timezone
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
import sqlalchemy as sa
from flask_login import current_user, login_user, logout_user, login_required
from app.models import User from app.models import User
@app.before_request
def before_request():
if current_user.is_authenticated:
current_user.last_seen = datetime.now(timezone.utc)
db.session.commit()
@app.route('/') @app.route('/')
@app.route('/index') @app.route('/index')
@login_required @login_required
@ -27,12 +33,6 @@ def index():
#return posts; #return posts;
return render_template('index.html', title='Home', posts=posts) return render_template('index.html', title='Home', posts=posts)
@app.before_request
def before_request():
if current_user.is_authenticated:
current_user.last_seen = datetime.now(timezone.utc)
db.session.commit()
@app.route('/login', methods=['GET', 'POST']) @app.route('/login', methods=['GET', 'POST'])
def login(): def login():
if current_user.is_authenticated: if current_user.is_authenticated:
@ -92,6 +92,6 @@ def edit_profile():
return redirect(url_for('edit_profile')) return redirect(url_for('edit_profile'))
elif request.method == 'GET': elif request.method == 'GET':
form.username.data = current_user.username form.username.data = current_user.username
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)

View File

@ -6,12 +6,14 @@
<td><img src="data:image/png;base64,{{ user.gen_avatar(write_png=False) }}"></td> <td><img src="data:image/png;base64,{{ user.gen_avatar(write_png=False) }}"></td>
<td> <td>
<h1>User: {{ user.username }}</h1> <h1>User: {{ user.username }}</h1>
<h1>CUdebug: {{ current_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 %}
</td> </td>
</tr> </tr>
</table> </table>
{% if user == current_user() %} {% if user == current_user %}
<p><a href="{{ url_for('edit_profile') }}">Edit Profile</a></p> <p><a href="{{ url_for('edit_profile') }}">Edit Profile</a></p>
{% endif %} {% endif %}
<hr> <hr>

View File

@ -1,8 +1,8 @@
"""empty message """empty message
Revision ID: 1a0e4f823e90 Revision ID: 4a2c3a72038e
Revises: Revises:
Create Date: 2024-08-03 04:56:53.822820 Create Date: 2024-08-03 05:02:15.935738
""" """
from alembic import op from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '1a0e4f823e90' revision = '4a2c3a72038e'
down_revision = None down_revision = None
branch_labels = None branch_labels = None
depends_on = None depends_on = None