-
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.
Merge pull request #24 from fmfi-svt/refactor
Some refactoring
- Loading branch information
Showing
81 changed files
with
645 additions
and
509 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from flask import Blueprint | ||
|
||
|
||
def get_error_handler(code, message): | ||
def fn(error): | ||
return {"error": message}, code | ||
|
||
return fn | ||
|
||
|
||
def create_api(): | ||
api = Blueprint('api', __name__, url_prefix="/api") | ||
|
||
from candle.teachers.api import teachers | ||
from candle.subjects.api import subjects | ||
from candle.rooms.api import rooms | ||
from candle.groups.api import groups | ||
|
||
api.register_blueprint(teachers) | ||
api.register_blueprint(subjects) | ||
api.register_blueprint(rooms) | ||
api.register_blueprint(groups) | ||
|
||
api.register_error_handler(404, get_error_handler(404, "Not found.")) | ||
api.register_error_handler(403, get_error_handler(403, "Forbidden.")) | ||
api.register_error_handler(500, get_error_handler(500, "Server error.")) | ||
|
||
return api | ||
|
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from flask import Blueprint, render_template, redirect, url_for, request | ||
from flask_login import current_user | ||
|
||
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.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) | ||
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_) ) | ||
else: # user is logged out, show welcome-info: | ||
return render_template('timetable/timetable.html', title='Rozvrh', show_welcome=True) | ||
|
||
|
||
@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') | ||
|
||
|
||
@common.app_errorhandler(404) | ||
def error_404(error): | ||
return render_template('errors/404.html'), 404 | ||
|
||
|
||
@common.app_errorhandler(403) | ||
def error_403(error): | ||
return render_template('errors/403.html'), 403 | ||
|
||
|
||
@common.app_errorhandler(500) | ||
def error_500(error): | ||
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 |
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 |
---|---|---|
|
@@ -287,4 +287,4 @@ ul.quickswitch li.active a { | |
|
||
#web_header ul.quickswitch li.active a { | ||
color: black; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -823,4 +823,4 @@ ul.quickswitch li a { | |
|
||
#welcome { | ||
font-size: 1.25em; | ||
} | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{% extends "main/base.html" %} | ||
|
||
{% block obsah %} | ||
<form> | ||
<input type="text" name="q" value="{{ request.args.q }}"> | ||
<button type="submit">Vyhľadať</button> | ||
</form> | ||
|
||
{% if subjects %} | ||
<h2>Predmety</h2> | ||
<ul> | ||
{% for subject in subjects %} | ||
<li><a href="{{ url_for("subjects.show_timetable", slug=subject.url_id) }}">{{ subject }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% if groups %} | ||
<h2>Krúžky</h2> | ||
<ul> | ||
{% for group in groups %} | ||
<li><a href="{{ url_for("groups.show_timetable", slug=group.url_id) }}">{{ group }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% if teachers %} | ||
<h2>Učitelia</h2> | ||
<ul> | ||
{% for teacher in teachers %} | ||
<li><a href="{{ url_for("teachers.show_timetable", slug=teacher.url_id) }}">{{ teacher }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% if rooms %} | ||
<h2>Miestnosti</h2> | ||
<ul> | ||
{% for room in rooms %} | ||
<li><a href="{{ url_for("rooms.show_timetable", slug=room.url_id) }}">{{ room }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% endblock %} | ||
|
Oops, something went wrong.