Skip to content
Snippets Groups Projects
Commit b64723b6 authored by Andrea Callia D'Iddio's avatar Andrea Callia D'Iddio
Browse files

Feat: prevent students from making changes after a predefined deadline (this year: 17 Oct 2022).

parent 4dfab8e7
No related branches found
No related tags found
1 merge request!7Preventing students from making changes after a predefined deadline
from datetime import datetime
STUDENT = "student"
STAFF = "staff"
DEADLINE_FOR_STUDENT_CHANGES = datetime(2022, 9, 17, 7, 0)
\ No newline at end of file
......@@ -2,7 +2,7 @@ from .message_builders import (
login_manager_message,
login_unsuccessful_error,
project_not_found,
shortlist_not_found,
shortlist_not_found, deadline_expired_for_students,
)
#########################################################################
......@@ -14,3 +14,5 @@ LOGIN_MANAGER_MESSAGE = login_manager_message()
PROJECT_NOT_FOUND = project_not_found()
SHORTLIST_NOT_FOUND = shortlist_not_found()
DEADLINE_EXPIRED_FOR_STUDENTS = deadline_expired_for_students()
......@@ -64,3 +64,13 @@ def shortlist_not_found():
style=ERROR,
)
)
def deadline_expired_for_students():
return MessageEncoder.encode(
Message(
header="<h3><strong>Deadline expired</strong></h3>",
body="<p>The deadline to make changes has now expired, and you cannot make changes to your shortlisting and ranking. If you have questions, please contact Lorenzo Picinali.</p>",
style=ERROR,
)
)
\ No newline at end of file
from functools import wraps
from flask import url_for
from flask import url_for, flash
from flask_login import current_user
from werkzeug.utils import redirect
from app.constants import STAFF, STUDENT
from app import messages
from app.constants import STAFF, STUDENT, DEADLINE_FOR_STUDENT_CHANGES
from datetime import datetime
def staff_only(func):
......@@ -25,3 +28,14 @@ def students_only(func):
return redirect(url_for(f"{current_user.role}.projects"))
return inner
def only_before_deadline_for_students(func):
@wraps(func)
def inner(*args, **kwargs):
if datetime.utcnow() <= DEADLINE_FOR_STUDENT_CHANGES:
return func(*args, **kwargs)
flash(messages.DEADLINE_EXPIRED_FOR_STUDENTS)
return redirect(url_for(f"{current_user.role}.projects"))
return inner
\ No newline at end of file
......@@ -5,7 +5,7 @@ from app import messages
from app.database import db
from app.models.project import Project
from app.models.shortlist import Shortlisting
from app.utils.decorators import students_only
from app.utils.decorators import students_only, only_before_deadline_for_students
bp = Blueprint("student", __name__, url_prefix="/student")
......@@ -44,6 +44,7 @@ def projects_ranking():
@bp.route("/projects/rankings", methods=["PUT"])
@login_required
@students_only
@only_before_deadline_for_students
def update_ranking():
project_ids = request.json
current_shortlist: list[Shortlisting] = Shortlisting.query.filter(
......@@ -68,6 +69,7 @@ def view_project(project_id):
@bp.route("/projects/<project_id>/shortlist")
@login_required
@students_only
@only_before_deadline_for_students
def shortlist_project(project_id):
if Project.query.get(project_id):
shortlisting = Shortlisting(
......@@ -83,6 +85,7 @@ def shortlist_project(project_id):
@bp.route("/projects/<project_id>/unshortlist")
@login_required
@students_only
@only_before_deadline_for_students
def unshortlist_project(project_id):
if Project.query.get(project_id):
shortlist: Shortlisting = (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment