Skip to content

Commit 122d6cf

Browse files
committed
fix(registration): order signups by signup order in excel
Also display full name as <last_name> <first_name> Refs LINK-2200
1 parent 24e5d07 commit 122d6cf

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

registrations/exports.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, registration: Registration) -> None:
2020
.select_related(
2121
"contact_person", "signup_group__contact_person", "protected_data"
2222
)
23-
.order_by("attendee_status", "first_name", "last_name")
23+
.order_by("attendee_status", "id")
2424
.only(
2525
"first_name",
2626
"last_name",
@@ -44,7 +44,12 @@ def __init__(self, registration: Registration) -> None:
4444
@staticmethod
4545
def _get_columns() -> list[dict]:
4646
return [
47-
{"header": _("Name"), "accessor": "full_name"},
47+
{
48+
"header": _("Name"),
49+
"accessor": lambda signup: (
50+
f"{signup.last_name or ''} {signup.first_name or ''}".strip()
51+
),
52+
},
4853
{
4954
"header": _("Date of birth"),
5055
"accessor": "date_of_birth",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import pytest
2+
3+
from registrations.exports import RegistrationSignUpsExportXLSX
4+
from registrations.models import SignUp
5+
from registrations.tests.factories import SignUpContactPersonFactory, SignUpFactory
6+
7+
8+
@pytest.fixture
9+
def signup_registration(registration):
10+
signup_1 = SignUpFactory(
11+
registration=registration,
12+
first_name="John",
13+
last_name="Doe",
14+
phone_number="123456789",
15+
attendee_status=SignUp.AttendeeStatus.ATTENDING,
16+
)
17+
SignUpContactPersonFactory(
18+
signup=signup_1, email="contact1@example.com", phone_number="123456789"
19+
)
20+
21+
signup_2 = SignUpFactory(
22+
registration=registration,
23+
first_name="Jane",
24+
last_name="Smith",
25+
phone_number="987654321",
26+
attendee_status=SignUp.AttendeeStatus.ATTENDING,
27+
)
28+
SignUpContactPersonFactory(
29+
signup=signup_2, email="contact2@example.com", phone_number="987654321"
30+
)
31+
32+
signup_3 = SignUpFactory(
33+
registration=registration,
34+
first_name="Wait",
35+
last_name="Listed",
36+
phone_number="3254454",
37+
attendee_status=SignUp.AttendeeStatus.WAITING_LIST,
38+
)
39+
SignUpContactPersonFactory(
40+
signup=signup_3, email="contact2@example.com", phone_number="45645637"
41+
)
42+
43+
return registration
44+
45+
46+
@pytest.mark.django_db
47+
def test_signup_order(signup_registration):
48+
registration = signup_registration
49+
exporter = RegistrationSignUpsExportXLSX(registration)
50+
table_data = exporter._get_signups_table_data()
51+
52+
assert table_data[0][0] == "Doe John"
53+
assert table_data[1][0] == "Smith Jane"
54+
assert table_data[2][0] == "Listed Wait"
55+
56+
57+
@pytest.mark.django_db
58+
def test_attendee_name_format(signup_registration):
59+
registration = signup_registration
60+
exporter = RegistrationSignUpsExportXLSX(registration)
61+
table_data = exporter._get_signups_table_data()
62+
63+
assert table_data[0][0] == "Doe John"

0 commit comments

Comments
 (0)