hanze/programmeerles-ouderen

merged master -> friedel-dev (006b434cba30f7a1656250247e2ddc20d9d31c78)
Repositories

commit 006b434cba30f7a1656250247e2ddc20d9d31c78
parent 37797f037cdaed16b6e70fe3a9970c3ded977804
Author: Friedel Schön <[email protected]>
Date:   Thu,  7 Apr 2022 15:17:34 +0200

merged master -> friedel-dev

Diffstat:
Mpgmles/__init__.py4+---
Mpgmles/forms.py2+-
Mpgmles/routes.py25++++++++++++++-----------
Mpgmles/site.db0
Mpgmles/templates/course.html2+-
5 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/pgmles/__init__.py b/pgmles/__init__.py @@ -1,5 +1,3 @@ -from typing import cast - from flask import Flask from flask_bcrypt import Bcrypt from flask_login import LoginManager @@ -13,7 +11,7 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' db = SQLAlchemy(app) bcrypt = Bcrypt(app) login_manager = LoginManager(app) -login_manager.login_view = cast(None, 'login') +login_manager.login_view = 'login' login_manager.login_message_category = 'info' calendar = Calendar() diff --git a/pgmles/forms.py b/pgmles/forms.py @@ -76,7 +76,7 @@ class SubscribeForm(FlaskForm): class UnsubscribeForm(FlaskForm): lang_id = HiddenField() - submit = SubmitField('Unsubsribe') + submit = SubmitField('Unsubscribe') class PostForm(FlaskForm): # redundant diff --git a/pgmles/routes.py b/pgmles/routes.py @@ -6,8 +6,9 @@ from flask_login import current_user, login_required, login_user, logout_user from PIL import Image from . import app, bcrypt, calendar, db -from .forms import LoginForm, PostForm, RegistrationForm, UpdateAccountForm -from .models import Course, CourseMember, User +from .forms import (LanguageForm, LoginForm, PostForm, RegistrationForm, + SubscribeForm, UnsubscribeForm, UpdateAccountForm) +from .models import Classes, Language, User @app.route("/") @@ -132,7 +133,7 @@ def update_lang(lang_id): lang.info = form.info.data db.session.commit() flash('The course has been updated!', 'success') - return redirect(url_for('home', lang_id=lang.id)) + return redirect(url_for('index', lang_id=lang.id)) elif request.method == 'GET': form.name.data = lang.name form.info.data = lang.info @@ -143,25 +144,27 @@ def update_lang(lang_id): def course(course_id): form = SubscribeForm() form2 = UnsubscribeForm() - subscription = Classes.query.filter_by( - user_id=current_user.id, language_id=course_id).first() - show = True - if subscription: - show = False - if form.validate_on_submit() and show == True: + subscription = None + if current_user.is_authenticated: + subscription = Classes.query.filter_by( + user_id=current_user.id, language_id=course_id).first() + + if form.validate_on_submit() and not subscription: course = Classes(user_id=current_user.id, language_id=course_id, teacher_id=1, location="hier") db.session.add(course) db.session.commit() flash('You have subscribed to this course!', 'success') return redirect(url_for('account')) - if form2.validate_on_submit() and show == False: + + if form2.validate_on_submit() and subscription: db.session.delete(subscription) db.session.commit() flash('You been have Unsubscribed to this course!', 'success') return redirect(url_for('account')) + course = Language.query.get_or_404(course_id) - return render_template('course.html', calendar=calendar, title=course.name, course=course, form=form, form2=form2, show=show) + return render_template('course.html', calendar=calendar, title=course.name, course=course, form=form, form2=form2, show=not subscription) @app.route("/course/<int:post_id>/update", methods=['GET', 'POST']) diff --git a/pgmles/site.db b/pgmles/site.db Binary files differ. diff --git a/pgmles/templates/course.html b/pgmles/templates/course.html @@ -14,7 +14,7 @@ {{ form.submit(class="btn btn-outline-info") }} </div> </form> - {%else%} + {% else %} <form method="POST" action=""> {{ form2.hidden_tag() }} <div class="form-group">