Partition and serialize task orders need on funding page
This commit is contained in:
parent
8cc46c9e05
commit
a6a53525f8
@ -88,12 +88,21 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
|||||||
else:
|
else:
|
||||||
return Status.PENDING
|
return Status.PENDING
|
||||||
|
|
||||||
|
@property
|
||||||
|
def display_status(self):
|
||||||
|
return self.status.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def budget(self):
|
def budget(self):
|
||||||
return sum(
|
return sum(
|
||||||
filter(None, [self.clin_01, self.clin_02, self.clin_03, self.clin_04])
|
filter(None, [self.clin_01, self.clin_02, self.clin_03, self.clin_04])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def balance(self):
|
||||||
|
# TODO: somehow calculate the remaining balance. For now, assume $0 spent
|
||||||
|
return self.budget
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def portfolio_name(self):
|
def portfolio_name(self):
|
||||||
return self.portfolio.name
|
return self.portfolio.name
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from flask import g, render_template
|
from flask import g, render_template, url_for
|
||||||
|
|
||||||
from . import portfolios_bp
|
from . import portfolios_bp
|
||||||
from atst.domain.task_orders import TaskOrders
|
from atst.domain.task_orders import TaskOrders
|
||||||
@ -12,13 +12,34 @@ from atst.models.task_order import Status as TaskOrderStatus
|
|||||||
def portfolio_task_orders(portfolio_id):
|
def portfolio_task_orders(portfolio_id):
|
||||||
portfolio = Portfolios.get(g.current_user, portfolio_id)
|
portfolio = Portfolios.get(g.current_user, portfolio_id)
|
||||||
task_orders_by_status = defaultdict(list)
|
task_orders_by_status = defaultdict(list)
|
||||||
|
serialize_task_order = lambda task_order: {
|
||||||
|
key: getattr(task_order, key)
|
||||||
|
for key in [
|
||||||
|
"id",
|
||||||
|
"budget",
|
||||||
|
"time_created",
|
||||||
|
"start_date",
|
||||||
|
"end_date",
|
||||||
|
"display_status",
|
||||||
|
"balance",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
for task_order in portfolio.task_orders:
|
for task_order in portfolio.task_orders:
|
||||||
task_orders_by_status[task_order.status].append(task_order)
|
serialized_task_order = serialize_task_order(task_order)
|
||||||
|
serialized_task_order["url"] = url_for(
|
||||||
|
"portfolios.view_task_order",
|
||||||
|
portfolio_id=portfolio.id,
|
||||||
|
task_order_id=task_order.id,
|
||||||
|
)
|
||||||
|
task_orders_by_status[task_order.status].append(serialized_task_order)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"portfolios/task_orders/index.html",
|
"portfolios/task_orders/index.html",
|
||||||
portfolio=portfolio,
|
portfolio=portfolio,
|
||||||
pending_task_orders=task_orders_by_status.get(TaskOrderStatus.PENDING, []),
|
pending_task_orders=task_orders_by_status.get(TaskOrderStatus.PENDING, []),
|
||||||
|
active_task_orders=task_orders_by_status.get(TaskOrderStatus.ACTIVE, []),
|
||||||
|
expired_task_orders=task_orders_by_status.get(TaskOrderStatus.EXPIRED, []),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user