Features: - Added page for an overview of establishments with a possibility to request a membership. - Added page for admins of an establishment to accept or deny those candidates. This is currently only usable via URL, the navigation to this site is not yet implemented in the HTML files. - Added page to add new establishments by providing a name. Improvements: - Better folder structure. - The establishment-specific overview can now be viewed with another URL, as well as some other pages. Bugfixes: - Seriously I don't know anymore what I fixed and what not. But it works just better now :) Future: - Angular has been added to separate the Flask-Backend with the frontend. Angular is currently not connected to the backend, but this will change in the future.
26 lines
1.5 KiB
Python
26 lines
1.5 KiB
Python
from flask import abort, redirect, url_for
|
|
from flask_login import current_user, login_required
|
|
from src import db, LOGGER
|
|
from src.establishment.candidates import bp
|
|
from src.establishment.candidates.forms import EvaluateCandidateForm
|
|
from src.models import Establishment, EstablishmentCandidate, LoginToken, User
|
|
from src.utils.routes_utils import render_custom_template as render_template
|
|
from src.utils.database_utils import generate_token
|
|
|
|
@bp.route("/<establishment_id>", methods=["GET", "POST"])
|
|
@login_required
|
|
def candidates(establishment_id):
|
|
establishment = Establishment.query.get_or_404(establishment_id)
|
|
if(current_user == establishment.User):
|
|
form = EvaluateCandidateForm()
|
|
establishment_candidates = EstablishmentCandidate.query.filter_by(establishment = establishment.id).all()
|
|
if(form.validate_on_submit()):
|
|
if(form.accept.data):
|
|
login_token = LoginToken(Establishment = establishment, User = User.query.get(form.candidate_id.data), token = generate_token())
|
|
db.session.add(login_token)
|
|
establishment_candidate = EstablishmentCandidate.query.filter_by(establishment = establishment.id, user = form.candidate_id.data).first()
|
|
db.session.delete(establishment_candidate)
|
|
db.session.commit()
|
|
return redirect(url_for('.candidates', establishment_id = establishment_id))
|
|
return render_template("establishment/candidates/candidates.html", establishment_candidates=establishment_candidates, form=form)
|
|
abort(403) |