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

Feat: support checking deadline per category when creating or deleting a project.

parent 1efe055b
No related branches found
No related tags found
1 merge request!18Support specific deadline for each category of project.
Pipeline #381094 failed
This commit is part of merge request !18. Comments created here will be created in the context of that merge request.
import sys
from datetime import datetime
from flask import Blueprint, flash, redirect, render_template, request, url_for
......@@ -64,7 +63,6 @@ def projects():
.filter(Project.deleted.is_(None))
.all()
)
sys.stderr.write(str(allow_edit))
return render_template(
"pages/staff/projects.html",
own_projects=own_projects,
......@@ -74,10 +72,14 @@ def projects():
)
def is_deadline_expired_for_staff(category_code):
category = Category.query.get(category_code)
return datetime.utcnow() > category.deadline_for_staff_change
@bp.route("/projects/create", methods=["GET", "POST"])
@login_required
@staff_only
@only_before_deadline_for_staff
def create_project():
category_codes: list[str] = (
Person.query.filter_by(username=current_user.username).first().categories
......@@ -117,10 +119,13 @@ def create_project():
proposed_start_date=form.proposed_start_date.data,
duration_in_weeks=form.duration_in_weeks.data,
)
db.session.add(project)
db.session.commit()
if project.on_behalf:
shortlist_proposer(project)
if is_deadline_expired_for_staff(form.category.data):
flash(messages.DEADLINE_EXPIRED_FOR_STAFF)
else:
db.session.add(project)
db.session.commit()
if project.on_behalf:
shortlist_proposer(project)
return redirect(url_for("staff.projects"))
elif request.method == "POST":
if form.category.data not in category_codes:
......@@ -133,20 +138,18 @@ def create_project():
@bp.route("/projects/<project_id>/delete")
@login_required
@staff_only
@only_before_deadline_for_staff
def delete_project(project_id):
can_delete = True
category_codes: list[str] = (
Person.query.filter_by(username=current_user.username).first().categories
)
project = Project.query.get(project_id)
if not project:
can_delete = False
elif project.category not in category_codes:
can_delete = False
elif project.proposer != current_user.username:
can_delete = False
if can_delete:
if (project is not None) and is_deadline_expired_for_staff(project.category):
flash(messages.DEADLINE_EXPIRED_FOR_STAFF)
elif (
(project is not None)
and (project.category in category_codes)
and (project.proposer == current_user.username)
):
project.deleted = datetime.utcnow()
db.session.commit()
else:
......
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