mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-14 06:55:08 +02:00
adjusted code for correct version of django
This commit is contained in:
parent
4a104b6ff6
commit
5da8119f86
3 changed files with 25 additions and 40 deletions
|
@ -34,7 +34,7 @@ from django_fsm import TransitionNotAllowed # type: ignore
|
|||
from django.utils.safestring import mark_safe
|
||||
from django.utils.html import escape
|
||||
from django.contrib.auth.forms import UserChangeForm, UsernameField
|
||||
from django.contrib.admin.views.main import ChangeList, IGNORED_PARAMS
|
||||
from django.contrib.admin.views.main import IGNORED_PARAMS
|
||||
from django_admin_multiple_choice_list_filter.list_filters import MultipleChoiceListFilter
|
||||
from import_export import resources
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
|
@ -46,27 +46,6 @@ from django.utils.translation import gettext_lazy as _
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CustomChangeListForPortfolioFiltering(ChangeList):
|
||||
"""CustomChangeList so that portfolio can be passed in a url, but not appear
|
||||
in the list of filters on the right side of the page."""
|
||||
|
||||
def get_filters_params(self, params=None):
|
||||
"""
|
||||
Return all params except IGNORED_PARAMS.
|
||||
"""
|
||||
params = params or self.params
|
||||
lookup_params = params.copy() # a dictionary of the query string
|
||||
# Remove all the parameters that are globally and systematically
|
||||
# ignored.
|
||||
# Remove portfolio so that it does not error as an invalid
|
||||
# filter parameter.
|
||||
ignored_params = list(IGNORED_PARAMS) + ["portfolio"]
|
||||
for ignored in ignored_params:
|
||||
if ignored in lookup_params:
|
||||
del lookup_params[ignored]
|
||||
return lookup_params
|
||||
|
||||
|
||||
class FsmModelResource(resources.ModelResource):
|
||||
"""ModelResource is extended to support importing of tables which
|
||||
have FSMFields. ModelResource is extended with the following changes
|
||||
|
@ -450,6 +429,22 @@ class MultiFieldSortableChangeList(admin.views.main.ChangeList):
|
|||
|
||||
return ordering
|
||||
|
||||
def get_filters_params(self, params=None):
|
||||
"""
|
||||
Return all params except IGNORED_PARAMS.
|
||||
"""
|
||||
params = params or self.params
|
||||
lookup_params = params.copy() # a dictionary of the query string
|
||||
# Remove all the parameters that are globally and systematically
|
||||
# ignored.
|
||||
# Remove portfolio so that it does not error as an invalid
|
||||
# filter parameter.
|
||||
ignored_params = list(IGNORED_PARAMS) + ["portfolio"]
|
||||
for ignored in ignored_params:
|
||||
if ignored in lookup_params:
|
||||
del lookup_params[ignored]
|
||||
return lookup_params
|
||||
|
||||
|
||||
class CustomLogEntryAdmin(LogEntryAdmin):
|
||||
"""Overwrite the generated LogEntry admin class"""
|
||||
|
@ -2282,12 +2277,6 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
qs = qs.filter(portfolio=portfolio_id)
|
||||
return qs
|
||||
|
||||
def get_changelist(self, request, **kwargs):
|
||||
"""
|
||||
Return the ChangeList class for use on the changelist page.
|
||||
"""
|
||||
return CustomChangeListForPortfolioFiltering
|
||||
|
||||
|
||||
class TransitionDomainAdmin(ListHeaderAdmin):
|
||||
"""Custom transition domain admin class."""
|
||||
|
@ -2752,12 +2741,6 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
qs = qs.filter(domain_info__portfolio=portfolio_id)
|
||||
return qs
|
||||
|
||||
def get_changelist(self, request, **kwargs):
|
||||
"""
|
||||
Return the ChangeList class for use on the changelist page.
|
||||
"""
|
||||
return CustomChangeListForPortfolioFiltering
|
||||
|
||||
|
||||
class DraftDomainResource(resources.ModelResource):
|
||||
"""defines how each field in the referenced model should be mapped to the corresponding fields in the
|
||||
|
|
|
@ -2107,9 +2107,7 @@ class TestPortfolioAdmin(TestCase):
|
|||
domain_2.save()
|
||||
|
||||
domains = self.admin.domains(self.portfolio)
|
||||
self.assertIn("domain1.gov", domains)
|
||||
self.assertIn("domain2.gov", domains)
|
||||
self.assertIn('<ul class="add-list-reset">', domains)
|
||||
self.assertIn("2 Domains", domains)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_domain_requests_display(self):
|
||||
|
@ -2118,6 +2116,4 @@ class TestPortfolioAdmin(TestCase):
|
|||
completed_domain_request(name="request2.gov", portfolio=self.portfolio)
|
||||
|
||||
domain_requests = self.admin.domain_requests(self.portfolio)
|
||||
self.assertIn("request1.gov", domain_requests)
|
||||
self.assertIn("request2.gov", domain_requests)
|
||||
self.assertIn('<ul class="add-list-reset">', domain_requests)
|
||||
self.assertIn("2 Domain Requests", domain_requests)
|
||||
|
|
|
@ -4,6 +4,8 @@ from registrar.models import FederalAgency, SeniorOfficial, User
|
|||
from django.contrib.auth import get_user_model
|
||||
from registrar.tests.common import create_superuser, create_user
|
||||
|
||||
from api.tests.common import less_console_noise_decorator
|
||||
|
||||
|
||||
class GetSeniorOfficialJsonTest(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -26,6 +28,7 @@ class GetSeniorOfficialJsonTest(TestCase):
|
|||
SeniorOfficial.objects.all().delete()
|
||||
FederalAgency.objects.all().delete()
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_get_senior_official_json_authenticated_superuser(self):
|
||||
"""Test that a superuser can fetch the senior official information."""
|
||||
p = "adminpass"
|
||||
|
@ -38,6 +41,7 @@ class GetSeniorOfficialJsonTest(TestCase):
|
|||
self.assertEqual(data["last_name"], "Doe")
|
||||
self.assertEqual(data["title"], "Director")
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_get_senior_official_json_authenticated_analyst(self):
|
||||
"""Test that an analyst user can fetch the senior official's information."""
|
||||
p = "userpass"
|
||||
|
@ -50,6 +54,7 @@ class GetSeniorOfficialJsonTest(TestCase):
|
|||
self.assertEqual(data["last_name"], "Doe")
|
||||
self.assertEqual(data["title"], "Director")
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_get_senior_official_json_unauthenticated(self):
|
||||
"""Test that an unauthenticated user receives a 403 with an error message."""
|
||||
p = "password"
|
||||
|
@ -57,6 +62,7 @@ class GetSeniorOfficialJsonTest(TestCase):
|
|||
response = self.client.get(self.api_url, {"agency_name": "Test Agency"})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_get_senior_official_json_not_found(self):
|
||||
"""Test that a request for a non-existent agency returns a 404 with an error message."""
|
||||
p = "adminpass"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue