mgt c8 finish
This commit is contained in:
parent
63bdf8d164
commit
2f920f3b6f
0
backend/Dockerfile
Executable file → Normal file
0
backend/Dockerfile
Executable file → Normal file
@ -43,6 +43,7 @@ class EditProfileForm(FlaskForm):
|
||||
if user is not None:
|
||||
raise ValidationError('Please use a different username.')
|
||||
|
||||
|
||||
class EmptyForm(FlaskForm):
|
||||
submit = SubmitField('Submit')
|
||||
|
||||
|
||||
|
@ -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'))
|
||||
|
||||
|
||||
|
@ -10,12 +10,28 @@
|
||||
<h1>Udebug: {{ user }}</h1>
|
||||
{% if user.about_me %}<p>{{ user.about_me }}</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>
|
||||
</tr>
|
||||
</table>
|
||||
{% if user == current_user %}
|
||||
<p><a href="{{ url_for('edit_profile') }}">Edit Profile</a></p>
|
||||
{% endif %}
|
||||
<hr>
|
||||
{% for post in posts %}
|
||||
{% include '_post.html' %}
|
||||
|
@ -5,8 +5,8 @@ basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
class Config:
|
||||
SECRET_KEY = os.environ.get('FLASK_SECRET_KEY') or 'flasksk'
|
||||
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 = 'sqlite:///' + os.path.join(basedir, 'zapp.db')
|
||||
SQLALCHEMY_DATABASE_URI = 'mariadb+mariadbconnector://flasku:' + os.environ.get('MYSQL_PASSWORD') + '@db:3306/flask'
|
||||
|
||||
#MAIL_SERVER = 'pmb'
|
||||
MAIL_SERVER = ''
|
||||
|
0
backend/dbdb.sh
Normal file → Executable file
0
backend/dbdb.sh
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user