Skip to content

Commit 8ede0e7

Browse files
authored
Grants form: add Nationality and Departure City questions (#4195)
1 parent f08a731 commit 8ede0e7

File tree

20 files changed

+575
-138
lines changed

20 files changed

+575
-138
lines changed

backend/api/grants/mutations.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class _GrantErrors:
4444
need_accommodation: list[str] = strawberry.field(default_factory=list)
4545
why: list[str] = strawberry.field(default_factory=list)
4646
notes: list[str] = strawberry.field(default_factory=list)
47-
travelling_from: list[str] = strawberry.field(default_factory=list)
47+
departure_country: list[str] = strawberry.field(default_factory=list)
48+
nationality: list[str] = strawberry.field(default_factory=list)
49+
departure_city: list[str] = strawberry.field(default_factory=list)
4850
non_field_errors: list[str] = strawberry.field(default_factory=list)
4951
participant_bio: list[str] = strawberry.field(default_factory=list)
5052
participant_website: list[str] = strawberry.field(default_factory=list)
@@ -68,17 +70,16 @@ def validate(self, conference: Conference, user: User) -> GrantErrors:
6870
errors.add_error("non_field_errors", "The grants form is not open!")
6971

7072
max_length_fields = {
71-
"name": 300,
7273
"full_name": 300,
73-
"travelling_from": 200,
74-
"twitter_handle": 15,
75-
"github_handle": 39,
74+
"name": 300,
75+
"departure_country": 100,
76+
"nationality": 100,
77+
"departure_city": 100,
7678
}
7779
for field, max_length in max_length_fields.items():
7880
value = getattr(self, field, "")
7981

80-
if len(value) > max_length:
81-
print(field)
82+
if value and len(value) > max_length:
8283
errors.add_error(
8384
field,
8485
f"{field}: Cannot be more than {max_length} chars",
@@ -118,7 +119,9 @@ class SendGrantInput(BaseGrantInput):
118119
need_accommodation: bool
119120
why: str
120121
notes: str
121-
travelling_from: str
122+
departure_country: str | None = None
123+
nationality: str
124+
departure_city: str | None = None
122125

123126
participant_bio: str
124127
participant_website: str
@@ -155,7 +158,9 @@ class UpdateGrantInput(BaseGrantInput):
155158
need_accommodation: bool
156159
why: str
157160
notes: str
158-
travelling_from: str
161+
departure_country: str | None = None
162+
nationality: str
163+
departure_city: str | None = None
159164

160165
participant_bio: str
161166
participant_website: str
@@ -233,7 +238,9 @@ def send_grant(self, info: Info, input: SendGrantInput) -> SendGrantResult:
233238
"need_accommodation": input.need_accommodation,
234239
"why": input.why,
235240
"notes": input.notes,
236-
"travelling_from": input.travelling_from,
241+
"departure_country": input.departure_country,
242+
"nationality": input.nationality,
243+
"departure_city": input.departure_city,
237244
}
238245
)
239246

backend/api/grants/tests/test_send_grant.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def _send_grant(client, conference, conference_code=None, **kwargs):
3838
validationNeedAccommodation: needAccommodation
3939
validationWhy: why
4040
validationNotes: notes
41-
validationTravellingFrom: travellingFrom
41+
validationDepartureCountry: departureCountry
42+
validationNationality: nationality
43+
validationDepartureCity: departureCity
4244
validationParticipantBio: participantBio
4345
validationParticipantWebsite: participantWebsite
4446
validationParticipantTwitterHandle: participantTwitterHandle
@@ -69,7 +71,9 @@ def _send_grant(client, conference, conference_code=None, **kwargs):
6971
"needAccommodation": grant.need_accommodation,
7072
"why": grant.why,
7173
"notes": grant.notes,
72-
"travellingFrom": grant.travelling_from,
74+
"departureCountry": grant.departure_country,
75+
"nationality": grant.nationality,
76+
"departureCity": grant.departure_city,
7377
"participantBio": "my bio",
7478
"participantWebsite": "http://website.it",
7579
"participantTwitterHandle": "handle",
@@ -214,15 +218,23 @@ def test_cannot_send_grant_outside_allowed_values(
214218
graphql_client,
215219
conference,
216220
name="Marcotte" * 50,
217-
travellingFrom="Very long location" * 50,
221+
departureCountry="Very long location" * 50,
222+
nationality="Freedonia" * 50,
223+
departureCity="Emerald City " * 50,
218224
)
219225

220226
assert response["data"]["sendGrant"]["__typename"] == "GrantErrors"
221227
assert response["data"]["sendGrant"]["errors"]["validationName"] == [
222228
"name: Cannot be more than 300 chars"
223229
]
224-
assert response["data"]["sendGrant"]["errors"]["validationTravellingFrom"] == [
225-
"travelling_from: Cannot be more than 200 chars"
230+
assert response["data"]["sendGrant"]["errors"]["validationDepartureCountry"] == [
231+
"departure_country: Cannot be more than 100 chars"
232+
]
233+
assert response["data"]["sendGrant"]["errors"]["validationNationality"] == [
234+
"nationality: Cannot be more than 100 chars"
235+
]
236+
assert response["data"]["sendGrant"]["errors"]["validationDepartureCity"] == [
237+
"departure_city: Cannot be more than 100 chars"
226238
]
227239

228240

backend/api/grants/tests/test_update_grant.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def _update_grant(graphql_client, grant, **kwargs):
3434
validationNeedAccommodation: needAccommodation
3535
validationWhy: why
3636
validationNotes: notes
37-
validationTravellingFrom: travellingFrom
37+
validationDepartureCountry: departureCountry
38+
validationNationality: nationality
39+
validationDepartureCity: departureCity
3840
validationParticipantBio: participantBio
3941
validationParticipantWebsite: participantWebsite
4042
validationParticipantTwitterHandle: participantTwitterHandle
@@ -65,7 +67,9 @@ def _update_grant(graphql_client, grant, **kwargs):
6567
"needAccommodation": grant.need_accommodation,
6668
"why": grant.why,
6769
"notes": grant.notes,
68-
"travellingFrom": grant.travelling_from,
70+
"departureCountry": grant.departure_country,
71+
"nationality": grant.nationality,
72+
"departureCity": grant.departure_city,
6973
"participantBio": "bio",
7074
"participantWebsite": "http://website.it",
7175
"participantTwitterHandle": "handle",
@@ -109,7 +113,9 @@ def test_update_grant(graphql_client, user):
109113
needAccommodation=True,
110114
why="why not",
111115
notes="🧸",
112-
travellingFrom="GB",
116+
departureCountry="GB",
117+
nationality="Italian",
118+
departureCity="Rome",
113119
participantFacebookUrl="http://facebook.com/pythonpizza",
114120
participantLinkedinUrl="http://linkedin.com/company/pythonpizza",
115121
)
@@ -205,13 +211,21 @@ def test_cannot_update_submission_with_lang_outside_allowed_values(
205211
graphql_client,
206212
grant=grant,
207213
name="Marcotte" * 50,
208-
travellingFrom="Very long location" * 50,
214+
departureCountry="Very long location" * 50,
215+
nationality="Freedonia" * 50,
216+
departureCity="Emerald City " * 50,
209217
)
210218

211219
assert response["data"]["updateGrant"]["__typename"] == "GrantErrors"
212220
assert response["data"]["updateGrant"]["errors"]["validationName"] == [
213221
"name: Cannot be more than 300 chars"
214222
]
215-
assert response["data"]["updateGrant"]["errors"]["validationTravellingFrom"] == [
216-
"travelling_from: Cannot be more than 200 chars"
223+
assert response["data"]["updateGrant"]["errors"]["validationDepartureCountry"] == [
224+
"departure_country: Cannot be more than 100 chars"
225+
]
226+
assert response["data"]["updateGrant"]["errors"]["validationNationality"] == [
227+
"nationality: Cannot be more than 100 chars"
228+
]
229+
assert response["data"]["updateGrant"]["errors"]["validationDepartureCity"] == [
230+
"departure_city: Cannot be more than 100 chars"
217231
]

backend/api/grants/types.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class Grant:
3131
need_accommodation: bool
3232
why: str
3333
notes: str
34-
travelling_from: Optional[str]
34+
departure_country: Optional[str]
35+
nationality: Optional[str]
36+
departure_city: Optional[str]
3537
applicant_reply_deadline: Optional[datetime]
3638

3739
@classmethod
@@ -53,6 +55,8 @@ def from_model(cls, grant: GrantModel) -> Grant:
5355
need_accommodation=grant.need_accommodation,
5456
why=grant.why,
5557
notes=grant.notes,
56-
travelling_from=grant.travelling_from,
58+
departure_country=grant.departure_country,
59+
nationality=grant.nationality,
60+
departure_city=grant.departure_city,
5761
applicant_reply_deadline=grant.applicant_reply_deadline,
5862
)

backend/grants/admin.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"needs_funds_for_travel",
4343
"why",
4444
"notes",
45-
"travelling_from",
45+
"departure_country",
4646
"conference__code",
4747
"created",
4848
)
@@ -375,7 +375,9 @@ class Meta:
375375
"needs_funds_for_travel",
376376
"why",
377377
"notes",
378-
"travelling_from",
378+
"nationality",
379+
"departure_country",
380+
"departure_city",
379381
"country_type",
380382
"applicant_reply_sent_at",
381383
"applicant_reply_deadline",
@@ -450,13 +452,13 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
450452
"need_accommodation",
451453
IsProposedSpeakerFilter,
452454
IsConfirmedSpeakerFilter,
453-
("travelling_from", CountryFilter),
455+
("departure_country", CountryFilter),
454456
"user__gender",
455457
)
456458
search_fields = (
457459
"email",
458460
"full_name",
459-
"travelling_from",
461+
"departure_country",
460462
"been_to_other_events",
461463
"why",
462464
"notes",
@@ -514,7 +516,9 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
514516
"needs_funds_for_travel",
515517
"need_visa",
516518
"need_accommodation",
517-
"travelling_from",
519+
"nationality",
520+
"departure_country",
521+
"departure_city",
518522
"why",
519523
"python_usage",
520524
"been_to_other_events",
@@ -540,8 +544,8 @@ def user_display_name(self, obj):
540544
description="C",
541545
)
542546
def country(self, obj):
543-
if obj.travelling_from:
544-
country = countries.get(code=obj.travelling_from)
547+
if obj.departure_country:
548+
country = countries.get(code=obj.departure_country)
545549
if country:
546550
return country.emoji
547551

0 commit comments

Comments
 (0)