Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions hypha/apply/dashboard/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
def get_paf_for_review(user, is_paf_approval_sequential):
"""Return a list of paf approvals ready for user's review"""

user_groups = list(user.groups.all())
paf_approvals = PAFApprovals.objects.annotate(
roles_count=Count("paf_reviewer_role__user_roles")
).filter(
roles_count=len(list(user.groups.all())),
roles_count=len(user_groups),
approved=False,
)

for role in user.groups.all():
for role in user_groups:
paf_approvals = paf_approvals.filter(paf_reviewer_role__user_roles__id=role.id)

if is_paf_approval_sequential:
Expand Down
22 changes: 16 additions & 6 deletions hypha/apply/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ def awaiting_reviews(self, submissions):
}

def active_invoices(self):
invoices = Invoice.objects.filter(
project__lead=self.request.user,
).in_progress()
invoices = (
Invoice.objects.filter(
project__lead=self.request.user,
)
.in_progress()
.select_related("project", "by")
)

return {
"count": invoices.count(),
Expand All @@ -160,13 +164,18 @@ def projects(self):
data=self.request.GET or None, request=self.request, queryset=projects
)

filtered_qs = filterset.qs

limit = 10
limited_qs = list(filtered_qs[: limit + 1])
has_more = len(limited_qs) > limit
table_data = limited_qs[:limit]

return {
"count": projects.count(),
"count": filtered_qs.count(),
"filterset": filterset,
"table": ProjectsDashboardTable(data=projects[:limit], prefix="project-"),
"display_more": projects.count() > limit,
"table": ProjectsDashboardTable(data=table_data, prefix="project-"),
"display_more": has_more,
"url": reverse("apply:projects:all"),
}

Expand Down Expand Up @@ -492,6 +501,7 @@ def active_invoices(self):
)
return {"count": active_invoices.count(), "data": active_invoices}

# todo: if we don't need, we can remove these historical tables
def historical_project_data(self):
historical_projects = (
Project.objects.filter(user=self.request.user).complete().for_table()
Expand Down
10 changes: 6 additions & 4 deletions hypha/apply/projects/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ def in_progress(self):
return self.exclude(status__in=[DECLINED, PAID])

def approved_by_staff(self):
return self.filter(status=APPROVED_BY_STAFF)
return self.filter(status=APPROVED_BY_STAFF).select_related("project", "by")

def approved_by_finance_1(self):
return self.filter(status=APPROVED_BY_FINANCE)
return self.filter(status=APPROVED_BY_FINANCE).select_related("project", "by")

def waiting_to_convert(self):
return self.filter(status=APPROVED_BY_FINANCE)
return self.filter(status=APPROVED_BY_FINANCE).select_related("project", "by")

def for_finance_1(self):
return self.filter(status__in=[APPROVED_BY_STAFF, APPROVED_BY_FINANCE])
return self.filter(
status__in=[APPROVED_BY_STAFF, APPROVED_BY_FINANCE]
).select_related("project", "by")

def rejected(self):
return self.filter(status=DECLINED).order_by("-requested_at")
Expand Down
2 changes: 2 additions & 0 deletions hypha/apply/projects/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ def for_table(self):
.with_outstanding_reports()
.select_related(
"report_config",
"submission",
"submission__page",
"lead",
"user",
)
)

Expand Down
17 changes: 12 additions & 5 deletions hypha/apply/todo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,20 @@ def remove_tasks_of_related_obj(related_obj):


def get_tasks_for_user(user):
user_tasks = Task.objects.filter(user=user).annotate(
group_count=Count("user_group")
user_groups = list(user.groups.all())

user_tasks = (
Task.objects.filter(user=user)
.annotate(group_count=Count("user_group"))
.select_related("user", "related_content_type")
)
user_group_tasks = Task.objects.annotate(group_count=Count("user_group")).filter(
group_count=len(user.groups.all())
user_group_tasks = (
Task.objects.annotate(group_count=Count("user_group"))
.filter(group_count=len(user_groups))
.select_related("user", "related_content_type")
.prefetch_related("user_group")
)
for group in user.groups.all():
for group in user_groups:
user_group_tasks = user_group_tasks.filter(user_group__id=group.id)

return user_tasks.union(user_group_tasks).order_by("-created_at")
Expand Down
Loading