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

Add deadline to prevent further changes from staff.

parent 8feb1631
No related branches found
No related tags found
1 merge request!11Add deadline to prevent further changes from staff.
......@@ -4,3 +4,4 @@ STUDENT = "student"
STAFF = "staff"
DEADLINE_FOR_STUDENT_CHANGES = datetime(2022, 10, 20, 7, 0)
DEADLINE_FOR_STAFF_CHANGES = datetime(2022, 10, 20, 7, 0)
from .message_builders import (
deadline_expired_for_staff,
deadline_expired_for_students,
login_manager_message,
login_unsuccessful_error,
......@@ -17,3 +18,4 @@ PROJECT_NOT_FOUND = project_not_found()
SHORTLIST_NOT_FOUND = shortlist_not_found()
DEADLINE_EXPIRED_FOR_STUDENTS = deadline_expired_for_students()
DEADLINE_EXPIRED_FOR_STAFF = deadline_expired_for_staff()
......@@ -73,4 +73,14 @@ def deadline_expired_for_students():
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
)
def deadline_expired_for_staff():
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 further changes. If you have questions, please contact Lorenzo Picinali.</p>",
style=ERROR,
)
)
{% extends "components/layout.html" %}
{% macro project_details_section(label, value, style) %}
<section class="w3-section">
<div class="w3-quarter">
<h4 class="w3-text-teal">{{ label }}:</h4>
</div>
<div class="w3-rest">
<p>{{ value }}</p>
</div>
</section>
{% endmacro %}
{% block content %}
<div class="w3-content">
<div class="w3-container">
<h1 class="w3-center w3-text-teal">Project proposal</h1>
{{ project_details_section('Title', project.title) }}
{{ project_details_section('Proposer', person.full_name if person.full_name else person.username) }}
{{ project_details_section('Description', project.description) }}
</div>
</div>
{% endblock %}
......@@ -12,8 +12,13 @@
<li class="w3-display-container">
{{ project.title }}
<div class="w3-display-right">
<a href="{{ url_for("staff.edit_project", project_id=project.id) }}"
class="w3-button w3-hover-teal">Edit</a>
{% if allow_edit %}
<a href="{{ url_for("staff.edit_project", project_id=project.id) }}"
class="w3-button w3-hover-teal">Edit</a>
{% else %}
<a href="{{ url_for("staff.view_project", project_id=project.id) }}"
class="w3-button w3-hover-teal">View</a>
{% endif %}
<a href="{{ url_for("staff.delete_project", project_id=project.id) }}"
class="w3-button w3-hover-red">Delete</a>
</div>
......
......@@ -61,6 +61,7 @@
saveButton.innerHTML = "Save"
}, 5000)
}
window.location.href = "{{ url_for(current_user.role ~ '.projects_ranking') }}"
})
})
</script>
......
......@@ -6,7 +6,12 @@ from flask_login import current_user
from werkzeug.utils import redirect
from app import messages
from app.constants import DEADLINE_FOR_STUDENT_CHANGES, STAFF, STUDENT
from app.constants import (
DEADLINE_FOR_STAFF_CHANGES,
DEADLINE_FOR_STUDENT_CHANGES,
STAFF,
STUDENT,
)
def staff_only(func):
......@@ -38,3 +43,14 @@ def only_before_deadline_for_students(func):
return redirect(url_for(f"{current_user.role}.projects"))
return inner
def only_before_deadline_for_staff(func):
@wraps(func)
def inner(*args, **kwargs):
if datetime.utcnow() <= DEADLINE_FOR_STAFF_CHANGES:
return func(*args, **kwargs)
flash(messages.DEADLINE_EXPIRED_FOR_STAFF)
return redirect(url_for(f"{current_user.role}.projects"))
return inner
......@@ -5,12 +5,13 @@ from flask_login import current_user, login_required
from sqlalchemy import and_
from app import messages
from app.constants import DEADLINE_FOR_STAFF_CHANGES
from app.database import db
from app.forms.project import ProjectForm
from app.models.person import Person
from app.models.project import Project
from app.models.shortlist import Shortlisting
from app.utils.decorators import staff_only
from app.utils.decorators import only_before_deadline_for_staff, staff_only
bp = Blueprint("staff", __name__, url_prefix="/staff")
......@@ -36,17 +37,21 @@ def unshortlist_old_proposer(project: Project):
@login_required
@staff_only
def projects():
allow_edit = True if datetime.utcnow() <= DEADLINE_FOR_STAFF_CHANGES else False
active_projects: list[Project] = (
Project.query.filter_by(proposer=current_user.username)
.filter(Project.deleted.is_(None))
.all()
)
return render_template("pages/staff/projects.html", projects=active_projects)
return render_template(
"pages/staff/projects.html", projects=active_projects, allow_edit=allow_edit
)
@bp.route("/projects/create", methods=["GET", "POST"])
@login_required
@staff_only
@only_before_deadline_for_staff
def create_project():
form = ProjectForm()
if form.validate_on_submit():
......@@ -67,6 +72,7 @@ def create_project():
@bp.route("/projects/<project_id>/delete")
@login_required
@staff_only
@only_before_deadline_for_staff
def delete_project(project_id):
if project := Project.query.get(project_id):
project.deleted = datetime.utcnow()
......@@ -79,6 +85,7 @@ def delete_project(project_id):
@bp.route("/projects/<project_id>/edit", methods=["GET", "POST"])
@login_required
@staff_only
@only_before_deadline_for_staff
def edit_project(project_id):
# show_box is a boolean used to decide if we show the text box for student full name. by default this is not shown
show_box = False
......@@ -114,6 +121,24 @@ def edit_project(project_id):
return redirect(url_for("staff.projects"))
@bp.route("/projects/<project_id>")
@login_required
@staff_only
def view_project(project_id):
if project := Project.query.get(project_id):
username = project.proposer
person = Person.query.filter(Person.username == username).first() or Person(
username=username, firstname="", lastname=""
)
return render_template(
"pages/staff/project-view.html", project=project, person=person
)
flash(messages.PROJECT_NOT_FOUND)
return redirect(url_for("staff.projects"))
@bp.route("/projects/shortlisted")
@login_required
@staff_only
......@@ -146,6 +171,7 @@ def projects_ranking():
@bp.route("/projects/rankings", methods=["PUT"])
@login_required
@staff_only
@only_before_deadline_for_staff
def update_ranking():
shortlisting_ids = request.json
current_shortlist: list[Shortlisting] = Shortlisting.query.join(Project).filter(
......
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