mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Fix url path bug
This commit is contained in:
parent
b5b2d69344
commit
eb3850458b
4 changed files with 55 additions and 6 deletions
|
@ -598,9 +598,11 @@ class DomainRequest(TimeStampedModel):
|
||||||
|
|
||||||
def get_first_status_set_date(self, status):
|
def get_first_status_set_date(self, status):
|
||||||
"""Returns the date when the domain request was first set to the given status."""
|
"""Returns the date when the domain request was first set to the given status."""
|
||||||
log_entry = LogEntry.objects.filter(
|
log_entry = (
|
||||||
content_type__model="domainrequest", object_pk=self.pk, changes__status__1=status
|
LogEntry.objects.filter(content_type__model="domainrequest", object_pk=self.pk, changes__status__1=status)
|
||||||
).order_by("-timestamp").first()
|
.order_by("-timestamp")
|
||||||
|
.first()
|
||||||
|
)
|
||||||
return log_entry.timestamp.date() if log_entry else None
|
return log_entry.timestamp.date() if log_entry else None
|
||||||
|
|
||||||
def get_first_status_started_date(self):
|
def get_first_status_started_date(self):
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
from urllib.parse import urlparse, urlunparse, urlencode
|
from urllib.parse import urlparse, urlunparse, urlencode
|
||||||
|
from django.urls import resolve, Resolver404
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -315,3 +316,21 @@ def convert_queryset_to_dict(queryset, is_model=True, key="id"):
|
||||||
request_dict = {value[key]: value for value in queryset}
|
request_dict = {value[key]: value for value in queryset}
|
||||||
|
|
||||||
return request_dict
|
return request_dict
|
||||||
|
|
||||||
|
|
||||||
|
def get_url_name(path):
|
||||||
|
"""
|
||||||
|
Given a URL path, returns the corresponding URL name defined in urls.py.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
path (str): The URL path to resolve.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str or None: The URL name if it exists, otherwise None.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
match = resolve(path)
|
||||||
|
return match.url_name
|
||||||
|
except Resolver404:
|
||||||
|
logger.error(f"No matching URL name found for path: {path}")
|
||||||
|
return None
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
{% url 'domain-requests' as url %}
|
{% url 'domain-requests' as url %}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="usa-accordion__button usa-nav__link{% if 'request'|in_path:request.path %} usa-current{% endif %}"
|
class="usa-accordion__button usa-nav__link{% if path|is_domain_request_subpage %} usa-current{% endif %}"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
aria-controls="basic-nav-section-two"
|
aria-controls="basic-nav-section-two"
|
||||||
>
|
>
|
||||||
|
@ -80,13 +80,13 @@
|
||||||
<!-- user has view but no edit permissions -->
|
<!-- user has view but no edit permissions -->
|
||||||
{% elif has_any_requests_portfolio_permission %}
|
{% elif has_any_requests_portfolio_permission %}
|
||||||
{% url 'domain-requests' as url %}
|
{% url 'domain-requests' as url %}
|
||||||
<a href="{{ url }}" class="usa-nav-link{% if 'request'|in_path:request.path %} usa-current{% endif %}">
|
<a href="{{ url }}" class="usa-nav-link{% if path|is_domain_request_subpage %} usa-current{% endif %}">
|
||||||
Domain requests
|
Domain requests
|
||||||
</a>
|
</a>
|
||||||
<!-- user does not have permissions -->
|
<!-- user does not have permissions -->
|
||||||
{% else %}
|
{% else %}
|
||||||
{% url 'no-portfolio-requests' as url %}
|
{% url 'no-portfolio-requests' as url %}
|
||||||
<a href="{{ url }}" class="usa-nav-link{% if 'request'|in_path:request.path %} usa-current{% endif %}">
|
<a href="{{ url }}" class="usa-nav-link{% if path|is_domain_request_subpage %} usa-current{% endif %}">
|
||||||
Domain requests
|
Domain requests
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -3,6 +3,9 @@ from django import template
|
||||||
import re
|
import re
|
||||||
from registrar.models.domain_request import DomainRequest
|
from registrar.models.domain_request import DomainRequest
|
||||||
from phonenumber_field.phonenumber import PhoneNumber
|
from phonenumber_field.phonenumber import PhoneNumber
|
||||||
|
from registrar.views.domain_request import DomainRequestWizard
|
||||||
|
|
||||||
|
from registrar.models.utility.generic_helper import get_url_name
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -174,3 +177,28 @@ def has_contact_info(user):
|
||||||
@register.filter
|
@register.filter
|
||||||
def model_name_lowercase(instance):
|
def model_name_lowercase(instance):
|
||||||
return instance.__class__.__name__.lower()
|
return instance.__class__.__name__.lower()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter(name="is_domain_request_subpage")
|
||||||
|
def is_domain_request_subpage(path):
|
||||||
|
"""Checks if the given page is a subpage of domain requests.
|
||||||
|
Takes a path name, like '/requests/'."""
|
||||||
|
# Since our pages aren't unified under a common path, we need this approach for now.
|
||||||
|
|
||||||
|
url_names = [
|
||||||
|
"domain-requests",
|
||||||
|
"no-portfolio-requests",
|
||||||
|
"domain-request-status",
|
||||||
|
"domain-request-withdraw-confirmation",
|
||||||
|
"domain-request-withdrawn",
|
||||||
|
"domain-request-delete",
|
||||||
|
]
|
||||||
|
|
||||||
|
# The domain request wizard pages don't have a defined path,
|
||||||
|
# so we need to check directly on it.
|
||||||
|
wizard_paths = [
|
||||||
|
DomainRequestWizard.EDIT_URL_NAME,
|
||||||
|
DomainRequestWizard.URL_NAMESPACE,
|
||||||
|
DomainRequestWizard.NEW_URL_NAME,
|
||||||
|
]
|
||||||
|
return get_url_name(path) in url_names or any(wizard in path for wizard in wizard_paths)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue