Full cleanup / refactor

This commit is contained in:
CocoByte 2024-12-18 22:29:06 -07:00
parent 79bc7102e1
commit 7e4d8e34ad
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
26 changed files with 199 additions and 134 deletions

View file

@ -99,30 +99,69 @@ def portfolio_permissions(request):
def is_widescreen_mode(request):
widescreen_paths = [] # If this list is meant to include specific paths, populate it.
widescreen_paths = [
"/domain-request/",
] # If this list is meant to include specific paths, populate it.
portfolio_widescreen_paths = [
"/domains/",
"/requests/",
"/request/",
"/no-organization-requests/",
"/no-organization-domains/",
"/domain-request/",
"/members/"
]
# widescreen_paths can be a bear as it trickles down sub-urls. exclude_paths gives us a way out.
exclude_paths = [
"/domains/edit",
"/admin/"
]
# Check if the current path matches a widescreen path or the root path.
is_widescreen = any(path in request.path for path in widescreen_paths) or request.path == "/"
is_widescreen = (
any(path in request.path for path in widescreen_paths)
or request.path == "/" )
# Check if the user is an organization user and the path matches portfolio paths.
is_portfolio_widescreen = (
hasattr(request.user, "is_org_user")
and request.user.is_org_user(request)
and any(path in request.path for path in portfolio_widescreen_paths)
and not any(exclude_path in request.path for exclude_path in exclude_paths)
)
is_excluded = any(exclude_path in request.path for exclude_path in exclude_paths)
# Return a dictionary with the widescreen mode status.
return {"is_widescreen_mode": is_widescreen or is_portfolio_widescreen}
return {"is_widescreen_mode": (is_widescreen or is_portfolio_widescreen or get_is_widescreen_left_justified(request)) and not is_excluded}
def get_is_widescreen_left_justified(request):
include_paths = [
"/user-profile",
"/request/",
"/domain/",
]
portfolio_include_paths = [
"/organization/",
"/senior-official/",
"/member/",
"/members/new-member",
]
exclude_paths = [
]
is_excluded = any(exclude_path in request.path for exclude_path in exclude_paths)
# Check if the current path matches a path in included_paths or the root path.
is_widescreen_left_justified = any(path in request.path for path in include_paths)
# Check if the user is an organization user and the path matches portfolio_only paths.
is_portfolio_widescreen_left_justified = (
hasattr(request.user, "is_org_user")
and request.user.is_org_user(request)
and any(path in request.path for path in portfolio_include_paths)
)
return (is_widescreen_left_justified or is_portfolio_widescreen_left_justified) and not is_excluded
def is_widescreen_left_justified(request):
# Return a dictionary with the widescreen mode status.
return {"is_widescreen_left_justified": get_is_widescreen_left_justified(request)}