-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
poetry-and-linting: run black+ruff on whole project
- Loading branch information
1 parent
5b73e73
commit 72cab4f
Showing
39 changed files
with
735 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,74 @@ | ||
from flask import Blueprint, render_template, redirect, url_for, request | ||
from flask import Blueprint, redirect, render_template, request, url_for | ||
from flask_login import current_user | ||
from flask_wtf.csrf import CSRFError | ||
|
||
from candle import db | ||
from candle.groups.search import search_groups | ||
from candle.models import UserTimetable | ||
from flask_wtf.csrf import CSRFError | ||
|
||
from candle.rooms.search import search_rooms | ||
from candle.subjects.search import search_subjects | ||
from candle.teachers.search import search_teachers | ||
|
||
common = Blueprint('common', __name__, template_folder="templates", | ||
static_folder='static', | ||
static_url_path='/common/static') | ||
common = Blueprint( | ||
"common", | ||
__name__, | ||
template_folder="templates", | ||
static_folder="static", | ||
static_url_path="/common/static", | ||
) | ||
|
||
|
||
@common.route('/') | ||
@common.route("/") | ||
def home(): | ||
if current_user.is_authenticated: | ||
my_timetables = current_user.timetables | ||
# if the user doesn't have any timetable: | ||
if my_timetables.first() is None: | ||
# create a new one: | ||
ut = UserTimetable(name='Rozvrh', user_id=current_user.id) | ||
ut = UserTimetable(name="Rozvrh", user_id=current_user.id) | ||
db.session.add(ut) | ||
db.session.commit() | ||
else: | ||
# select the latest one (with the highest id): | ||
ut = my_timetables.order_by(UserTimetable.id_)[-1] | ||
# redirect to user's timetable view: | ||
return redirect(url_for('my_timetable.show_timetable', id_=ut.id_) ) | ||
return redirect(url_for("my_timetable.show_timetable", id_=ut.id_)) | ||
else: # user is logged out, show welcome-info: | ||
return render_template('timetable/timetable.html', title='Rozvrh', show_welcome=True) | ||
return render_template( | ||
"timetable/timetable.html", title="Rozvrh", show_welcome=True | ||
) | ||
|
||
|
||
@common.route('/search/') | ||
@common.route("/search/") | ||
def search(): | ||
query = request.args.get("q") | ||
if query: | ||
return render_template("search.html", title="Vyhľadávanie", | ||
subjects=search_subjects(query).limit(20).all(), | ||
groups=search_groups(query).limit(20).all(), | ||
rooms=search_rooms(query).limit(20).all(), | ||
teachers=search_teachers(query).limit(20).all(), | ||
) | ||
return render_template('search.html', title='Vyhľadávanie') | ||
return render_template( | ||
"search.html", | ||
title="Vyhľadávanie", | ||
subjects=search_subjects(query).limit(20).all(), | ||
groups=search_groups(query).limit(20).all(), | ||
rooms=search_rooms(query).limit(20).all(), | ||
teachers=search_teachers(query).limit(20).all(), | ||
) | ||
return render_template("search.html", title="Vyhľadávanie") | ||
|
||
|
||
@common.app_errorhandler(404) | ||
def error_404(error): | ||
return render_template('errors/404.html'), 404 | ||
return render_template("errors/404.html"), 404 | ||
|
||
|
||
@common.app_errorhandler(403) | ||
def error_403(error): | ||
return render_template('errors/403.html'), 403 | ||
return render_template("errors/403.html"), 403 | ||
|
||
|
||
@common.app_errorhandler(500) | ||
def error_500(error): | ||
return render_template('errors/500.html'), 500 | ||
return render_template("errors/500.html"), 500 | ||
|
||
|
||
@common.app_errorhandler(CSRFError) | ||
def csrf_error(reason): | ||
return render_template('errors/csrf_error.html', reason=reason.description), 400 | ||
return render_template("errors/csrf_error.html", reason=reason.description), 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
from candle.groups.models import StudentGroup | ||
from flask_sqlalchemy.query import Query | ||
|
||
from candle.groups.models import StudentGroup | ||
|
||
|
||
def search_groups(query: str|None) -> Query: | ||
def search_groups(query: str | None) -> Query: | ||
groups = StudentGroup.query.order_by(StudentGroup.name) | ||
if query: | ||
groups = groups.filter(StudentGroup.name.ilike(f"%{query}%")) | ||
return groups | ||
|
||
|
||
def get_group(slug: str) -> StudentGroup: | ||
return StudentGroup.query.filter((StudentGroup.id_==slug) | (StudentGroup.name==slug)).first_or_404() | ||
return StudentGroup.query.filter( | ||
(StudentGroup.id_ == slug) | (StudentGroup.name == slug) | ||
).first_or_404() |
Oops, something went wrong.