Display TOs grouped by status
This commit is contained in:
@@ -64,10 +64,14 @@ class TaskOrders(BaseDomainClass):
|
||||
db.session.commit()
|
||||
|
||||
@classmethod
|
||||
def sort(cls, task_orders: [TaskOrder]) -> [TaskOrder]:
|
||||
# Sorts a list of task orders on two keys: status (primary) and time_created (secondary)
|
||||
by_time_created = sorted(task_orders, key=lambda to: to.time_created)
|
||||
by_status = sorted(by_time_created, key=lambda to: SORT_ORDERING.get(to.status))
|
||||
def sort_by_status(cls, task_orders):
|
||||
by_status = {}
|
||||
for status in SORT_ORDERING:
|
||||
by_status[status] = []
|
||||
|
||||
for task_order in task_orders:
|
||||
by_status[task_order.status].append(task_order)
|
||||
|
||||
return by_status
|
||||
|
||||
@classmethod
|
||||
|
@@ -20,12 +20,7 @@ class Status(Enum):
|
||||
UNSIGNED = "Not signed"
|
||||
|
||||
|
||||
SORT_ORDERING = {
|
||||
status: order
|
||||
for (order, status) in enumerate(
|
||||
[Status.DRAFT, Status.ACTIVE, Status.UPCOMING, Status.EXPIRED, Status.UNSIGNED]
|
||||
)
|
||||
}
|
||||
SORT_ORDERING = [Status.ACTIVE, Status.DRAFT, Status.UPCOMING, Status.EXPIRED, Status.UNSIGNED]
|
||||
|
||||
|
||||
class TaskOrder(Base, mixins.TimestampsMixin):
|
||||
|
@@ -28,14 +28,8 @@ def review_task_order(task_order_id):
|
||||
@user_can(Permissions.VIEW_PORTFOLIO_FUNDING, message="view portfolio funding")
|
||||
def portfolio_funding(portfolio_id):
|
||||
portfolio = Portfolios.get(g.current_user, portfolio_id)
|
||||
task_orders = TaskOrders.sort(portfolio.task_orders)
|
||||
label_colors = {
|
||||
TaskOrderStatus.DRAFT: "warning",
|
||||
TaskOrderStatus.ACTIVE: "success",
|
||||
TaskOrderStatus.UPCOMING: "info",
|
||||
TaskOrderStatus.EXPIRED: "error",
|
||||
TaskOrderStatus.UNSIGNED: "purple",
|
||||
}
|
||||
task_orders = TaskOrders.sort_by_status(portfolio.task_orders)
|
||||
# TODO: Get expended amount from the CSP
|
||||
return render_template(
|
||||
"task_orders/index.html", task_orders=task_orders, label_colors=label_colors
|
||||
"task_orders/index.html", task_orders=task_orders
|
||||
)
|
||||
|
Reference in New Issue
Block a user