Updated functionalities
This commit is contained in:
+19
-7
@@ -10,7 +10,7 @@ Access matrix:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request, abort
|
||||
from flask_login import login_required, current_user
|
||||
from app import db
|
||||
from app.models.project import Project, CustomerAssignment
|
||||
@@ -72,7 +72,9 @@ def create():
|
||||
@login_required
|
||||
@project_manager_required
|
||||
def view(project_id):
|
||||
project = Project.query.get_or_404(project_id)
|
||||
project = db.session.get(Project, project_id)
|
||||
if project is None:
|
||||
abort(404)
|
||||
facilities = project.facilities.order_by(Facility.name).all()
|
||||
assignments = (
|
||||
CustomerAssignment.query
|
||||
@@ -95,7 +97,9 @@ def view(project_id):
|
||||
@login_required
|
||||
@supervisor_required
|
||||
def edit(project_id):
|
||||
project = Project.query.get_or_404(project_id)
|
||||
project = db.session.get(Project, project_id)
|
||||
if project is None:
|
||||
abort(404)
|
||||
form = ProjectForm(obj=project)
|
||||
pm_users = User.query.filter_by(role='project_manager', active=True).order_by(User.username).all()
|
||||
form.project_manager_id.choices = [(0, '— None —')] + [(u.id, u.username) for u in pm_users]
|
||||
@@ -123,7 +127,9 @@ def edit(project_id):
|
||||
@login_required
|
||||
@admin_required
|
||||
def delete(project_id):
|
||||
project = Project.query.get_or_404(project_id)
|
||||
project = db.session.get(Project, project_id)
|
||||
if project is None:
|
||||
abort(404)
|
||||
|
||||
if project.facilities.count() > 0:
|
||||
flash(f'Cannot delete "{project.name}" — it has linked facilities. '
|
||||
@@ -147,7 +153,9 @@ def delete(project_id):
|
||||
@login_required
|
||||
@admin_required
|
||||
def add_assignment(project_id):
|
||||
project = Project.query.get_or_404(project_id)
|
||||
project = db.session.get(Project, project_id)
|
||||
if project is None:
|
||||
abort(404)
|
||||
form = CustomerAssignmentForm()
|
||||
|
||||
# Customer users only
|
||||
@@ -205,9 +213,13 @@ def add_assignment(project_id):
|
||||
@login_required
|
||||
@admin_required
|
||||
def remove_assignment(assignment_id):
|
||||
assignment = CustomerAssignment.query.get_or_404(assignment_id)
|
||||
assignment = db.session.get(CustomerAssignment, assignment_id)
|
||||
if assignment is None:
|
||||
abort(404)
|
||||
project_id = assignment.project_id
|
||||
project = Project.query.get_or_404(project_id)
|
||||
project = db.session.get(Project, project_id)
|
||||
if project is None:
|
||||
abort(404)
|
||||
user = db.session.get(User, assignment.user_id)
|
||||
|
||||
username = user.username if user else f'user_id={assignment.user_id}'
|
||||
|
||||
Reference in New Issue
Block a user