Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] #2852 property to portfolio related fields - [HOTGOV] #2963

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
12 changes: 6 additions & 6 deletions src/registrar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,13 +1694,13 @@ def queryset(self, request, queryset):
"last_submitted_date",
"last_status_update",
"status",
"generic_org_type",
"federal_type",
"federal_agency",
"organization_name",
"custom_election_board",
"city",
"state_territory",
"converted_generic_org_type",
"converted_organization_name",
"converted_federal_agency",
"converted_federal_type",
"converted_city",
"converted_state_territory",
"investigator",
]

Expand Down
70 changes: 70 additions & 0 deletions src/registrar/models/domain_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,3 +1332,73 @@ def _form_complete(self, request):
if not is_complete or not self._is_general_form_complete(request):
return False
return True

@property
def converted_organization_name(self):
""" "returns the organization field if the domain request is in a portfolio
otherwise it returns the organization name from the domain request object itself"""
if self.portfolio:
return self.portfolio.organization_name
return self.organization_name

@property
def converted_generic_org_type(self):
""" "returns the organization type if the domain request is in a portfolio
otherwise it returns the organization type from the domain request object itself"""
if self.portfolio:
return self.portfolio.organization_type
return self.generic_org_type

@property
def converted_federal_agency(self):
if self.portfolio:
return self.portfolio.federal_agency
return self.federal_agency

@property
def converted_federal_type(self):
if self.portfolio:
return self.portfolio.federal_type
return self.federal_type

@property
def converted_senior_official(self):
if self.portfolio:
return self.portfolio.senior_official
return self.senior_official

@property
def converted_address_line1(self):
if self.portfolio:
return self.portfolio.address_line1
return self.address_line1

@property
def converted_address_line2(self):
if self.portfolio:
return self.portfolio.address_line2
return self.address_line2

@property
def converted_city(self):
if self.portfolio:
return self.portfolio.city
return self.city

@property
def converted_state_territory(self):
if self.portfolio:
return self.portfolio.state_territory
return self.state_territory

@property
def converted_zipcode(self):
if self.portfolio:
return self.portfolio.zipcode
return self.zipcode

@property
def converted_urbanization(self):
if self.portfolio:
return self.portfolio.urbanization
return self.urbanization
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h2 class="text-primary-darker"> Summary of your domain request </h2>

{% block request_summary %}
{% with heading_level='h3' %}
{% with org_type=DomainRequest.get_generic_org_type_display %}
{% with org_type=DomainRequest.converted_generic_org_type %}
{% include "includes/summary_item.html" with title='Type of organization' value=org_type heading_level=heading_level %}
{% endwith %}

Expand All @@ -164,7 +164,7 @@ <h2 class="text-primary-darker"> Summary of your domain request </h2>
{% endif %}

{% if DomainRequest.get_federal_type_display %}
{% include "includes/summary_item.html" with title='Federal government branch' value=DomainRequest.get_federal_type_display heading_level=heading_level %}
{% include "includes/summary_item.html" with title='Federal government branch' value=DomainRequest.converted_federal_type heading_level=heading_level %}
{% endif %}

{% if DomainRequest.is_election_board %}
Expand All @@ -173,7 +173,7 @@ <h2 class="text-primary-darker"> Summary of your domain request </h2>
{% endwith %}
{% endif %}

{% if DomainRequest.organization_name %}
{% if DomainRequest.converted_organization_name %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asaki222 isn't this on the request form? Or am I reading this wrong? For your ticket the idea is that you will only change the ones for django admin, not every domain request form peice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abroddrick I didn't get a chance to comb through it(this is a rough draft), and clean it up yet. I was just focusing on getting a general working solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abroddrick Removed!

{% include "includes/summary_item.html" with title='Organization' value=DomainRequest address='true' heading_level=heading_level %}
{% endif %}

Expand Down
32 changes: 16 additions & 16 deletions src/registrar/templates/includes/organization_address.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<address>
{% if organization.federal_agency %}
{{ organization.federal_agency }}<br />
{% if organization.converted_federal_agency %}
{{ organization.converted_federal_agency }}<br />
{% endif %}
{% if organization.organization_name %}
{{ organization.organization_name }}
{% if organization.converted_organization_name %}
{{ organization.converted_organization_name }}
{% endif %}
{% if organization.address_line1 %}
<br />{{ organization.address_line1 }}
{% if organization.converted_address_line1 %}
<br />{{ organization.converted_address_line1 }}
{% endif %}
{% if organization.address_line2 %}
<br />{{ organization.address_line2 }}
{% if organization.converted_address_line2 %}
<br />{{ organization.converted_address_line2 }}
{% endif %}
{% if organization.city %}
<br />{{ organization.city }}{% if organization.state_territory %},&nbsp;
{% if organization.converted_city %}
<br />{{ organization.converted_city}}{% if organization.converted_state_territory %},&nbsp;
{% else %}<br />
{% endif %}
{% endif %}
{% if organization.state_territory %}
{{ organization.state_territory }}
{% if organization.converted_state_territory %}
{{ organization.converted_state_territory }}
{% endif %}
{% if organization.zipcode %}
<br />{{ organization.zipcode }}
{% if organization.converted_zipcode %}
<br />{{ organization.converted_zipcode }}
{% endif %}
{% if organization.urbanization %}
<br />{{ organization.urbanization }}
{% if organization.converted_urbanization %}
<br />{{ organization.converted_urbanization }}
{% endif %}
</address>
8 changes: 4 additions & 4 deletions src/registrar/templates/includes/request_review_steps.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
{% endif %}

{% if step == Step.ORGANIZATION_TYPE %}
{% if domain_request.generic_org_type is not None %}
{% with title=form_titles|get_item:step value=domain_request.get_generic_org_type_display|default:"<span class='text-bold text-secondary-dark'>Incomplete</span>"|safe %}
{% if domain_request.converted_generic_org_type is not None %}
{% with title=form_titles|get_item:step value=domain_request.converted_generic_org_type_display|default:"<span class='text-bold text-secondary-dark'>Incomplete</span>"|safe %}
{% include "includes/summary_item.html" with title=title value=value heading_level=heading_level editable=is_editable edit_link=domain_request_url %}
{% endwith %}
{% else %}
Expand All @@ -29,7 +29,7 @@


{% if step == Step.ORGANIZATION_FEDERAL %}
{% with title=form_titles|get_item:step value=domain_request.get_federal_type_display|default:"<span class='text-bold text-secondary-dark'>Incomplete</span>"|safe %}
{% with title=form_titles|get_item:step value=domain_request.converted_federal_type|default:"<span class='text-bold text-secondary-dark'>Incomplete</span>"|safe %}
{% include "includes/summary_item.html" with title=title value=value heading_level=heading_level editable=is_editable edit_link=domain_request_url %}
{% endwith %}
{% endif %}
Expand All @@ -41,7 +41,7 @@
{% endif %}

{% if step == Step.ORGANIZATION_CONTACT %}
{% if domain_request.organization_name %}
{% if domain_request.converted_organization_name %}
{% with title=form_titles|get_item:step value=domain_request %}
{% include "includes/summary_item.html" with title=title value=value heading_level=heading_level editable=is_editable edit_link=domain_request_url address='true' %}
{% endwith %}
Expand Down
4 changes: 2 additions & 2 deletions src/registrar/templates/includes/request_status_manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h2 class="text-primary-darker"> Summary of your domain request </h2>

{% block request_summary %}
{% with heading_level='h3' %}
{% with org_type=DomainRequest.get_generic_org_type_display %}
{% with org_type=DomainRequest.converted_generic_org_type_display %}
{% include "includes/summary_item.html" with title='Type of organization' value=org_type heading_level=heading_level %}
{% endwith %}

Expand All @@ -173,7 +173,7 @@ <h2 class="text-primary-darker"> Summary of your domain request </h2>
{% endwith %}
{% endif %}

{% if DomainRequest.organization_name %}
{% if DomainRequest.converted_organization_name %}
{% include "includes/summary_item.html" with title='Organization' value=DomainRequest address='true' heading_level=heading_level %}
{% endif %}

Expand Down
24 changes: 21 additions & 3 deletions src/registrar/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def assert_table_sorted(self, o_index, sort_fields):
"""
# 'o' is a search param defined by the current index position in the
# table, plus one.
print(" we are in table sorted right now")
dummy_request = self.factory.get(
self.url,
{"o": o_index},
Expand All @@ -186,21 +187,38 @@ def assert_table_sorted(self, o_index, sort_fields):

# Mock a user request
dummy_request = self._mock_user_request_for_factory(dummy_request)

print("sort fields", sort_fields)
expected_sort_order = list(self.model.objects.order_by(*sort_fields))

print("this is the expected sort order", expected_sort_order)
# Use changelist_view to get the sorted queryset
response = self.admin.changelist_view(dummy_request)
print("Response from get request from changelist", response)
print("rendering content", response.render())
response.render() # Render the response before accessing its content
returned_sort_order = list(response.context_data["cl"].result_list)

print("returned sort order", returned_sort_order)
print("expected sort order", expected_sort_order)
print("length of expected", len(expected_sort_order))
print("lenght of returned", len(returned_sort_order))

print("expected sort order dict")
for obj in expected_sort_order:
print(obj.__dict__)
print(dir(obj))

print("returned sort order dict")
for obj in returned_sort_order:
print(obj.__dict__)
print(dir(obj))

self.assertEqual(expected_sort_order, returned_sort_order)

def _mock_user_request_for_factory(self, request):
"""Adds sessionmiddleware when using factory to associate session information"""
middleware = SessionMiddleware(lambda req: req)
middleware.process_request(request)
request.session.save()
print(" we are in mock user request for factory, here is the returned requset", request)
return request

def get_table_delete_confirmation_page(self, selected_across: str, index: str):
Expand Down
1 change: 1 addition & 0 deletions src/registrar/tests/test_admin_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def test_creator_sortable(self):
)

# Assert that sorting in reverse works correctly
print("working there is a thingy")
self.test_helper.assert_table_sorted(
"-13",
(
Expand Down
Loading