mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-18 05:30:21 -04:00
Sort contact lists appropriately
On the uploads page this should be newest first, same as the scheduled and immediate jobs on this page. On the _choose_ page this should be alphabetical, same as choosing a template.
This commit is contained in:
@@ -42,7 +42,7 @@ from app.main.forms import (
|
||||
SetSenderForm,
|
||||
get_placeholder_form_instance,
|
||||
)
|
||||
from app.models.contact_list import ContactList, ContactLists
|
||||
from app.models.contact_list import ContactList, ContactListsAlphabetical
|
||||
from app.models.user import Users
|
||||
from app.s3_client.s3_csv_client import (
|
||||
s3download,
|
||||
@@ -506,7 +506,7 @@ def choose_from_contact_list(service_id, template_id):
|
||||
)
|
||||
return render_template(
|
||||
'views/send-contact-list.html',
|
||||
contact_lists=ContactLists(
|
||||
contact_lists=ContactListsAlphabetical(
|
||||
current_service.id,
|
||||
template_type=template.template_type,
|
||||
),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from functools import partial
|
||||
from os import path
|
||||
|
||||
from flask import abort, current_app
|
||||
@@ -130,10 +131,23 @@ class ContactLists(ModelList):
|
||||
|
||||
client_method = contact_list_api_client.get_contact_lists
|
||||
model = ContactList
|
||||
sort_function = partial(
|
||||
sorted,
|
||||
key=lambda item: item['created_at'],
|
||||
reverse=True,
|
||||
)
|
||||
|
||||
def __init__(self, service_id, template_type=None):
|
||||
super().__init__(service_id)
|
||||
self.items = [
|
||||
self.items = self.sort_function([
|
||||
item for item in self.items
|
||||
if template_type in {item['template_type'], None}
|
||||
]
|
||||
])
|
||||
|
||||
|
||||
class ContactListsAlphabetical(ContactLists):
|
||||
|
||||
sort_function = partial(
|
||||
sorted,
|
||||
key=lambda item: item['original_file_name'].lower(),
|
||||
)
|
||||
|
||||
@@ -717,7 +717,6 @@ def test_uploads_page_shows_scheduled_jobs(
|
||||
def test_uploads_page_shows_contact_lists_first(
|
||||
mocker,
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mock_get_no_uploads,
|
||||
mock_get_jobs,
|
||||
mock_get_contact_lists,
|
||||
@@ -730,16 +729,16 @@ def test_uploads_page_shows_contact_lists_first(
|
||||
(
|
||||
'File Status'
|
||||
),
|
||||
(
|
||||
'EmergencyContactList.xls '
|
||||
'Uploaded 13 March at 10:59am '
|
||||
'100 saved email addresses'
|
||||
),
|
||||
(
|
||||
'phone number list.csv '
|
||||
'Uploaded 13 March at 1:00pm '
|
||||
'123 saved phone numbers'
|
||||
),
|
||||
(
|
||||
'EmergencyContactList.xls '
|
||||
'Uploaded 13 March at 10:59am '
|
||||
'100 saved email addresses'
|
||||
),
|
||||
(
|
||||
'even_later.csv '
|
||||
'Sending 1 January 2016 at 11:09pm '
|
||||
@@ -754,7 +753,7 @@ def test_uploads_page_shows_contact_lists_first(
|
||||
assert page.select_one('.file-list-filename-large')['href'] == url_for(
|
||||
'main.contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
contact_list_id=fake_uuid,
|
||||
contact_list_id='d7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad',
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user