-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
31 lines (24 loc) · 1.02 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from decorators import login_required, check_access_level
from db import db, Configuration, Role
from flask import Blueprint, render_template, flash, current_app, url_for, request, make_response, redirect, session, \
Flask
config_bp = Blueprint('config', __name__)
@config_bp.route('/next_year', methods=['POST'])
@login_required
@check_access_level(Role.ADMIN)
def next_year():
last_year = Configuration.query.order_by(Configuration.year.desc()).first()
new_year = last_year.year + 1
try:
# Check whether the following year already exists in the database
existing_config = Configuration.query.filter_by(year=new_year).first()
if existing_config is not None:
return make_response("The year already exists", 500)
config = Configuration(year=new_year)
db.session.add(config)
db.session.commit()
Configuration.update_current_year(config.id)
except Exception as e:
db.session.rollback()
raise e
return redirect(url_for("index"))