Skip to content
Snippets Groups Projects
Commit 8daa51c4 authored by Andrea Callia D'Iddio's avatar Andrea Callia D'Iddio Committed by Ivan Procaccini
Browse files

Preventing students from making changes after a predefined deadline

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, 10, 17, 7, 0)
\ No newline at end of file
from .message_builders import (
deadline_expired_for_students,
login_manager_message,
login_unsuccessful_error,
project_not_found,
......@@ -14,3 +15,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
......@@ -61,6 +61,7 @@
saveButton.innerHTML = "Save"
}, 5000)
}
window.location.href = "{{ url_for(current_user.role ~ '.projects_ranking') }}"
})
})
</script>
......
from datetime import datetime
from functools import wraps
from flask import url_for
from flask import flash, url_for
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 DEADLINE_FOR_STUDENT_CHANGES, STAFF, STUDENT
def staff_only(func):
......@@ -25,3 +27,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
......@@ -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 only_before_deadline_for_students, students_only
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