mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 20:18:38 +02:00
formatted code for readability
This commit is contained in:
parent
1cd6fdda15
commit
d469041a8e
2 changed files with 19 additions and 20 deletions
|
@ -246,13 +246,7 @@ def is_members_subpage(path):
|
|||
"""Checks if the given page is a subpage of members.
|
||||
Takes a path name, like '/organization/'."""
|
||||
# Since our pages aren't unified under a common path, we need this approach for now.
|
||||
url_names = [
|
||||
"members",
|
||||
"member",
|
||||
"member-permissions",
|
||||
"invitedmember",
|
||||
"invitedmember-permissions"
|
||||
]
|
||||
url_names = ["members", "member", "member-permissions", "invitedmember", "invitedmember-permissions"]
|
||||
return get_url_name(path) in url_names
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
|||
@login_required
|
||||
def get_portfolio_members_json(request):
|
||||
"""Fetch members (permissions and invitations) for the given portfolio."""
|
||||
|
||||
|
||||
portfolio = request.GET.get("portfolio")
|
||||
|
||||
# Two initial querysets which will be combined
|
||||
|
@ -23,7 +23,7 @@ def get_portfolio_members_json(request):
|
|||
|
||||
# Get total across both querysets before applying filters
|
||||
unfiltered_total = permissions.count() + invitations.count()
|
||||
|
||||
|
||||
permissions = apply_search_term(permissions, request)
|
||||
invitations = apply_search_term(permissions, request)
|
||||
|
||||
|
@ -49,6 +49,7 @@ def get_portfolio_members_json(request):
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
def initial_permissions_search(portfolio):
|
||||
"""Perform initial search for permissions before applying any filters."""
|
||||
permissions = UserPortfolioPermission.objects.filter(portfolio=portfolio)
|
||||
|
@ -65,17 +66,18 @@ def initial_permissions_search(portfolio):
|
|||
# If email is present and not blank, use email
|
||||
When(Q(user__email__isnull=False) & ~Q(user__email=""), then=F("user__email")),
|
||||
# If first name or last name is present, use concatenation of first_name + " " + last_name
|
||||
When(Q(user__first_name__isnull=False) | Q(user__last_name__isnull=False),
|
||||
then=Concat(
|
||||
Coalesce(F("user__first_name"), Value("")),
|
||||
Value(" "),
|
||||
Coalesce(F("user__last_name"), Value(""))
|
||||
)
|
||||
When(
|
||||
Q(user__first_name__isnull=False) | Q(user__last_name__isnull=False),
|
||||
then=Concat(
|
||||
Coalesce(F("user__first_name"), Value("")),
|
||||
Value(" "),
|
||||
Coalesce(F("user__last_name"), Value("")),
|
||||
),
|
||||
),
|
||||
# If neither, use an empty string
|
||||
default=Value(""),
|
||||
output_field=CharField(),
|
||||
),
|
||||
# If neither, use an empty string
|
||||
default=Value(""),
|
||||
output_field=CharField()
|
||||
),
|
||||
source=Value("permission", output_field=CharField()),
|
||||
)
|
||||
.values(
|
||||
|
@ -92,6 +94,7 @@ def initial_permissions_search(portfolio):
|
|||
)
|
||||
return permissions
|
||||
|
||||
|
||||
def initial_invitations_search(portfolio):
|
||||
"""Perform initial invitations search before applying any filters."""
|
||||
invitations = PortfolioInvitation.objects.filter(portfolio=portfolio)
|
||||
|
@ -116,7 +119,7 @@ def initial_invitations_search(portfolio):
|
|||
"source",
|
||||
)
|
||||
return invitations
|
||||
|
||||
|
||||
|
||||
def apply_search_term(queryset, request):
|
||||
"""Apply search term to the queryset."""
|
||||
|
@ -129,6 +132,7 @@ def apply_search_term(queryset, request):
|
|||
)
|
||||
return queryset
|
||||
|
||||
|
||||
def apply_sorting(queryset, request):
|
||||
"""Apply sorting to the queryset."""
|
||||
sort_by = request.GET.get("sort_by", "id") # Default to 'id'
|
||||
|
@ -142,6 +146,7 @@ def apply_sorting(queryset, request):
|
|||
queryset = queryset.order_by(sort_by)
|
||||
return queryset
|
||||
|
||||
|
||||
def serialize_members(request, portfolio, item, user):
|
||||
# Check if the user can edit other users
|
||||
user_can_edit_other_users = any(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue