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:
Chris Hill-Scott
2020-03-16 11:05:26 +00:00
parent 050f98fea6
commit b99216173e
3 changed files with 24 additions and 11 deletions

View File

@@ -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,
),

View File

@@ -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(),
)