mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 06:43:12 -04:00
Make organisations natively sortable
This commit is contained in:
@@ -116,7 +116,7 @@ def add_organisation_from_nhs_local_service(service_id):
|
|||||||
|
|
||||||
form = AddNHSLocalOrganisationForm(organisation_choices=[
|
form = AddNHSLocalOrganisationForm(organisation_choices=[
|
||||||
(organisation.id, organisation.name)
|
(organisation.id, organisation.name)
|
||||||
for organisation in AllOrganisations()
|
for organisation in sorted(AllOrganisations())
|
||||||
if organisation.organisation_type == Organisation.TYPE_NHS_LOCAL
|
if organisation.organisation_type == Organisation.TYPE_NHS_LOCAL
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -60,3 +60,9 @@ class PaginatedModelList(ModelList):
|
|||||||
self.items = response[self.response_key]
|
self.items = response[self.response_key]
|
||||||
self.prev_page = response.get('links', {}).get('prev', None)
|
self.prev_page = response.get('links', {}).get('prev', None)
|
||||||
self.next_page = response.get('links', {}).get('next', None)
|
self.next_page = response.get('links', {}).get('next', None)
|
||||||
|
|
||||||
|
|
||||||
|
class SortByNameMixin():
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.name.lower() < other.name.lower()
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
from flask import abort
|
from flask import abort
|
||||||
from werkzeug.utils import cached_property
|
from werkzeug.utils import cached_property
|
||||||
|
|
||||||
from app.models import JSONModel, ModelList, SerialisedModelCollection
|
from app.models import (
|
||||||
|
JSONModel,
|
||||||
|
ModelList,
|
||||||
|
SerialisedModelCollection,
|
||||||
|
SortByNameMixin,
|
||||||
|
)
|
||||||
from app.notify_client.email_branding_client import email_branding_client
|
from app.notify_client.email_branding_client import email_branding_client
|
||||||
from app.notify_client.letter_branding_client import letter_branding_client
|
from app.notify_client.letter_branding_client import letter_branding_client
|
||||||
from app.notify_client.organisations_api_client import organisations_client
|
from app.notify_client.organisations_api_client import organisations_client
|
||||||
|
|
||||||
|
|
||||||
class Organisation(JSONModel):
|
class Organisation(JSONModel, SortByNameMixin):
|
||||||
|
|
||||||
TYPE_CENTRAL = 'central'
|
TYPE_CENTRAL = 'central'
|
||||||
TYPE_LOCAL = 'local'
|
TYPE_LOCAL = 'local'
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from flask import abort, current_app
|
|||||||
from notifications_utils.serialised_model import SerialisedModelCollection
|
from notifications_utils.serialised_model import SerialisedModelCollection
|
||||||
from werkzeug.utils import cached_property
|
from werkzeug.utils import cached_property
|
||||||
|
|
||||||
from app.models import JSONModel
|
from app.models import JSONModel, SortByNameMixin
|
||||||
from app.models.contact_list import ContactLists
|
from app.models.contact_list import ContactLists
|
||||||
from app.models.job import (
|
from app.models.job import (
|
||||||
ImmediateJobs,
|
ImmediateJobs,
|
||||||
@@ -27,7 +27,7 @@ from app.notify_client.template_folder_api_client import (
|
|||||||
from app.utils import get_default_sms_sender
|
from app.utils import get_default_sms_sender
|
||||||
|
|
||||||
|
|
||||||
class Service(JSONModel):
|
class Service(JSONModel, SortByNameMixin):
|
||||||
|
|
||||||
ALLOWED_PROPERTIES = {
|
ALLOWED_PROPERTIES = {
|
||||||
'active',
|
'active',
|
||||||
@@ -78,9 +78,6 @@ class Service(JSONModel):
|
|||||||
def from_id(cls, service_id):
|
def from_id(cls, service_id):
|
||||||
return cls(service_api_client.get_service(service_id)['data'])
|
return cls(service_api_client.get_service(service_id)['data'])
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
return self.name.lower() < other.name.lower()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def permissions(self):
|
def permissions(self):
|
||||||
return self._dict.get('permissions', self.TEMPLATE_TYPES)
|
return self._dict.get('permissions', self.TEMPLATE_TYPES)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<nav class="browse-list">
|
<nav class="browse-list">
|
||||||
<ul>
|
<ul>
|
||||||
{% for org in organisations %}
|
{% for org in organisations|sort %}
|
||||||
<li class="browse-list-item">
|
<li class="browse-list-item">
|
||||||
<a href="{{ url_for('main.organisation_dashboard', org_id=org.id) }}" class="govuk-link govuk-link--no-visited-state">{{ org.name }}</a>
|
<a href="{{ url_for('main.organisation_dashboard', org_id=org.id) }}" class="govuk-link govuk-link--no-visited-state">{{ org.name }}</a>
|
||||||
{% if not org.active %}
|
{% if not org.active %}
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ def test_organisation_page_shows_all_organisations(
|
|||||||
mocker
|
mocker
|
||||||
):
|
):
|
||||||
orgs = [
|
orgs = [
|
||||||
{'id': '1', 'name': 'Test 1', 'active': True, 'count_of_live_services': 0},
|
{'id': 'A3', 'name': 'Test 3', 'active': True, 'count_of_live_services': 0},
|
||||||
{'id': '2', 'name': 'Test 2', 'active': True, 'count_of_live_services': 1},
|
{'id': 'B1', 'name': 'Test 1', 'active': True, 'count_of_live_services': 1},
|
||||||
{'id': '3', 'name': 'Test 3', 'active': False, 'count_of_live_services': 2},
|
{'id': 'C2', 'name': 'Test 2', 'active': False, 'count_of_live_services': 2},
|
||||||
]
|
]
|
||||||
|
|
||||||
get_organisations = mocker.patch(
|
get_organisations = mocker.patch(
|
||||||
@@ -39,15 +39,31 @@ def test_organisation_page_shows_all_organisations(
|
|||||||
page.select_one('h1').text
|
page.select_one('h1').text
|
||||||
) == "Organisations"
|
) == "Organisations"
|
||||||
|
|
||||||
expected_hints = ('0 live services', '1 live service', '2 live services')
|
assert [
|
||||||
|
(
|
||||||
for index, org in enumerate(orgs):
|
normalize_spaces(link.text),
|
||||||
assert page.select('.browse-list-item a')[index].text == org['name']
|
normalize_spaces(hint.text),
|
||||||
if not org['active']:
|
link['href'],
|
||||||
assert page.select_one('.table-field-status-default,heading-medium').text == '- archived'
|
) for link, hint in zip(
|
||||||
assert normalize_spaces(page.select('.browse-list-hint')[index].text) == (
|
page.select('.browse-list-item a'),
|
||||||
expected_hints[index]
|
page.select('.browse-list-item .browse-list-hint'),
|
||||||
)
|
)
|
||||||
|
] == [
|
||||||
|
('Test 1', '1 live service', url_for(
|
||||||
|
'main.organisation_dashboard', org_id='B1'
|
||||||
|
)),
|
||||||
|
('Test 2', '2 live services', url_for(
|
||||||
|
'main.organisation_dashboard', org_id='C2'
|
||||||
|
)),
|
||||||
|
('Test 3', '0 live services', url_for(
|
||||||
|
'main.organisation_dashboard', org_id='A3'
|
||||||
|
)),
|
||||||
|
]
|
||||||
|
|
||||||
|
archived = page.select_one('.table-field-status-default.heading-medium')
|
||||||
|
assert normalize_spaces(archived.text) == '- archived'
|
||||||
|
assert normalize_spaces(archived.parent.text) == 'Test 2 - archived 2 live services'
|
||||||
|
|
||||||
assert normalize_spaces(
|
assert normalize_spaces(
|
||||||
page.select_one('a.govuk-button--secondary').text
|
page.select_one('a.govuk-button--secondary').text
|
||||||
) == 'New organisation'
|
) == 'New organisation'
|
||||||
@@ -276,8 +292,8 @@ def test_nhs_local_can_create_own_organisations(
|
|||||||
mocker.patch(
|
mocker.patch(
|
||||||
'app.models.organisation.AllOrganisations.client_method',
|
'app.models.organisation.AllOrganisations.client_method',
|
||||||
return_value=[
|
return_value=[
|
||||||
organisation_json('t1', 'Trust 1', organisation_type='nhs_local'),
|
|
||||||
organisation_json('t2', 'Trust 2', organisation_type='nhs_local'),
|
organisation_json('t2', 'Trust 2', organisation_type='nhs_local'),
|
||||||
|
organisation_json('t1', 'Trust 1', organisation_type='nhs_local'),
|
||||||
organisation_json('gp1', 'GP 1', organisation_type='nhs_gp'),
|
organisation_json('gp1', 'GP 1', organisation_type='nhs_gp'),
|
||||||
organisation_json('c1', 'Central 1'),
|
organisation_json('c1', 'Central 1'),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user