From afc6959b13a495879e8a9728d052c86fd04882d0 Mon Sep 17 00:00:00 2001 From: Etty Date: Thu, 28 Dec 2023 15:40:40 +0100 Subject: [PATCH 1/4] Remove old traveling_from field --- backend/grants/admin.py | 12 ++++-------- backend/grants/models.py | 11 ++++------- frontend/src/locale/index.ts | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/backend/grants/admin.py b/backend/grants/admin.py index 57a284ec82..9dc08ced01 100644 --- a/backend/grants/admin.py +++ b/backend/grants/admin.py @@ -39,7 +39,6 @@ "why", "notes", "travelling_from", - "traveling_from", "conference__code", "created", ) @@ -352,7 +351,6 @@ class Meta: "why", "notes", "travelling_from", - "traveling_from", "country_type", "applicant_message", "applicant_reply_sent_at", @@ -389,7 +387,6 @@ class GrantAdmin(ExportMixin, admin.ModelAdmin): "occupation", "grant_type", "interested_in_volunteering", - "traveling_from", ) search_fields = ( "email", @@ -454,7 +451,6 @@ class GrantAdmin(ExportMixin, admin.ModelAdmin): "need_visa", "need_accommodation", "travelling_from", - "traveling_from", "why", "python_usage", "been_to_other_events", @@ -483,8 +479,8 @@ def user_display_name(self, obj): description="C", ) def country(self, obj): - if obj.traveling_from: - country = countries.get(code=obj.traveling_from) + if obj.travelling_from: + country = countries.get(code=obj.travelling_from) if country: return country.emoji @@ -575,10 +571,10 @@ def get_queryset(self, request): return self.qs def changelist_view(self, request, extra_context=None): - qs = self.get_queryset(request).order_by("traveling_from") + qs = self.get_queryset(request).order_by("travelling_from") results = [] - for country_code, group in groupby(list(qs), key=lambda k: k.traveling_from): + for country_code, group in groupby(list(qs), key=lambda k: k.travelling_from): country = countries.get(code=country_code) if not country: continue diff --git a/backend/grants/models.py b/backend/grants/models.py index cf8f42a094..f42f3436c3 100644 --- a/backend/grants/models.py +++ b/backend/grants/models.py @@ -90,16 +90,13 @@ class ApprovedType(models.TextChoices): grant_type = models.CharField( _("grant type"), choices=GrantType.choices, max_length=10 ) - traveling_from = models.CharField( - _("Traveling from"), + travelling_from = models.CharField( + _("Travelling from"), max_length=100, blank=True, null=True, choices=[(country.code, country.name) for country in countries], ) - travelling_from = models.CharField( - _("Travelling from"), max_length=200 - ) # OLD FIELD needs_funds_for_travel = models.BooleanField(_("Needs funds for travel")) need_visa = models.BooleanField(_("Need visa/invitation letter?"), default=False) need_accommodation = models.BooleanField(_("Need accommodation"), default=False) @@ -207,8 +204,8 @@ def __str__(self): return f"{self.full_name}" def save(self, *args, **kwargs): - if self.traveling_from: - country = countries.get(code=self.traveling_from) + if self.travelling_from: + country = countries.get(code=self.travelling_from) assert country if country.code == "IT": self.country_type = Grant.CountryType.italy diff --git a/frontend/src/locale/index.ts b/frontend/src/locale/index.ts index 3a4d4ccc6e..c5265afb4f 100644 --- a/frontend/src/locale/index.ts +++ b/frontend/src/locale/index.ts @@ -668,7 +668,7 @@ We look forward to reading about you and hope to see you at PyCon Italia 2024! "grants.form.fields.grantType.values.speaker": "Speaker", "grants.form.fields.travellingFrom": "Where are you travelling from?", "grants.form.fields.travellingFrom.description": - "Please indicate the city and country you will be traveling from to attend the conference.", + "Please indicate the city and country you will be travelling from to attend the conference.", "grants.form.fields.needsFundsForTravel": "Do you need financial aid for travelling to PyCon Italia?", "grants.form.fields.needsFundsForTravel.description": From b7ace6520713745f32c34b6ab84fd39832b6904f Mon Sep 17 00:00:00 2001 From: Etty Date: Thu, 28 Dec 2023 17:24:31 +0100 Subject: [PATCH 2/4] Update country filter --- backend/countries/filters.py | 53 ++++ backend/grants/admin.py | 6 +- ...13_remove_grant_traveling_from_and_more.py | 277 ++++++++++++++++++ 3 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 backend/countries/filters.py create mode 100644 backend/grants/migrations/0013_remove_grant_traveling_from_and_more.py diff --git a/backend/countries/filters.py b/backend/countries/filters.py new file mode 100644 index 0000000000..19593215ff --- /dev/null +++ b/backend/countries/filters.py @@ -0,0 +1,53 @@ +from django.contrib.admin import FieldListFilter + +from countries import countries + + +class CountryFilter(FieldListFilter): + """ + Custom filter for Country fields in Django Admin. + + This filter will display only the countries that are actually used in the + objects of the model. + Each country is displayed with its name and emoji. + """ + + def __init__(self, field, request, params, model, model_admin, field_path): + self.lookup_kwarg = "%s__exact" % field_path + self.lookup_val = request.GET.get(self.lookup_kwarg) + self.field_generic = "%s__" % field_path + super().__init__(field, request, params, model, model_admin, field_path) + + def expected_parameters(self): + """ + Return the expected parameters for the filter. + + This is used by Django admin to build the correct query string. + """ + return [self.lookup_kwarg] + + def choices(self, changelist): + """ + Generate the choices for the filter. + + This method retrieves the countries actually used in the model instances + and yields the choices for the filter. + """ + # Retrieve the distinct country codes used in the model + used_countries = set( + changelist.model.objects.values_list(self.field_path, flat=True) + ) + + # Map these codes to their corresponding names and emojis + country_choices = [ + (country.code, f"{country.name} {country.emoji}") + for country in countries + if country.code in used_countries + ] + + for code, name in country_choices: + yield { + "selected": self.lookup_val == str(code), + "query_string": changelist.get_query_string({self.lookup_kwarg: code}), + "display": name, + } diff --git a/backend/grants/admin.py b/backend/grants/admin.py index 9dc08ced01..126ddf3ae7 100644 --- a/backend/grants/admin.py +++ b/backend/grants/admin.py @@ -3,7 +3,7 @@ from datetime import timedelta from itertools import groupby from typing import Dict, List, Optional - +from countries.filters import CountryFilter from django import forms from django.contrib import admin, messages from django.db.models.query import QuerySet @@ -26,6 +26,7 @@ from .models import Grant, GrantRecap + EXPORT_GRANTS_FIELDS = ( "name", "full_name", @@ -387,6 +388,7 @@ class GrantAdmin(ExportMixin, admin.ModelAdmin): "occupation", "grant_type", "interested_in_volunteering", + ("travelling_from", CountryFilter), ) search_fields = ( "email", @@ -574,7 +576,7 @@ def changelist_view(self, request, extra_context=None): qs = self.get_queryset(request).order_by("travelling_from") results = [] - for country_code, group in groupby(list(qs), key=lambda k: k.travelling_from): + for country_code, group in groupby(list(qs), key=lambda k: k.traveling_from): country = countries.get(code=country_code) if not country: continue diff --git a/backend/grants/migrations/0013_remove_grant_traveling_from_and_more.py b/backend/grants/migrations/0013_remove_grant_traveling_from_and_more.py new file mode 100644 index 0000000000..2545457961 --- /dev/null +++ b/backend/grants/migrations/0013_remove_grant_traveling_from_and_more.py @@ -0,0 +1,277 @@ +# Generated by Django 4.2.7 on 2023-12-28 14:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("grants", "0012_grant_community_contribution_grant_github_handle_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="grant", + name="traveling_from", + ), + migrations.AlterField( + model_name="grant", + name="travelling_from", + field=models.CharField( + blank=True, + choices=[ + ("AF", "Afghanistan"), + ("AL", "Albania"), + ("DZ", "Algeria"), + ("AS", "American Samoa"), + ("AD", "Andorra"), + ("AO", "Angola"), + ("AI", "Anguilla"), + ("AQ", "Antarctica"), + ("AG", "Antigua and Barbuda"), + ("AR", "Argentina"), + ("AM", "Armenia"), + ("AW", "Aruba"), + ("AU", "Australia"), + ("AT", "Austria"), + ("AZ", "Azerbaijan"), + ("BS", "Bahamas"), + ("BH", "Bahrain"), + ("BD", "Bangladesh"), + ("BB", "Barbados"), + ("BY", "Belarus"), + ("BE", "Belgium"), + ("BZ", "Belize"), + ("BJ", "Benin"), + ("BM", "Bermuda"), + ("BT", "Bhutan"), + ("BO", "Bolivia, Plurinational State of"), + ("BQ", "Bonaire, Sint Eustatius and Saba"), + ("BA", "Bosnia and Herzegovina"), + ("BW", "Botswana"), + ("BV", "Bouvet Island"), + ("BR", "Brazil"), + ("IO", "British Indian Ocean Territory"), + ("BN", "Brunei Darussalam"), + ("BG", "Bulgaria"), + ("BF", "Burkina Faso"), + ("BI", "Burundi"), + ("CV", "Cabo Verde"), + ("KH", "Cambodia"), + ("CM", "Cameroon"), + ("CA", "Canada"), + ("KY", "Cayman Islands"), + ("CF", "Central African Republic"), + ("TD", "Chad"), + ("CL", "Chile"), + ("CN", "China"), + ("CX", "Christmas Island"), + ("CC", "Cocos (Keeling) Islands"), + ("CO", "Colombia"), + ("KM", "Comoros"), + ("CG", "Congo"), + ("CD", "Congo, The Democratic Republic of the"), + ("CK", "Cook Islands"), + ("CR", "Costa Rica"), + ("HR", "Croatia"), + ("CU", "Cuba"), + ("CW", "Curaçao"), + ("CY", "Cyprus"), + ("CZ", "Czechia"), + ("CI", "Côte d'Ivoire"), + ("DK", "Denmark"), + ("DJ", "Djibouti"), + ("DM", "Dominica"), + ("DO", "Dominican Republic"), + ("EC", "Ecuador"), + ("EG", "Egypt"), + ("SV", "El Salvador"), + ("GQ", "Equatorial Guinea"), + ("ER", "Eritrea"), + ("EE", "Estonia"), + ("SZ", "Eswatini"), + ("ET", "Ethiopia"), + ("FK", "Falkland Islands (Malvinas)"), + ("FO", "Faroe Islands"), + ("FJ", "Fiji"), + ("FI", "Finland"), + ("FR", "France"), + ("GF", "French Guiana"), + ("PF", "French Polynesia"), + ("TF", "French Southern Territories"), + ("GA", "Gabon"), + ("GM", "Gambia"), + ("GE", "Georgia"), + ("DE", "Germany"), + ("GH", "Ghana"), + ("GI", "Gibraltar"), + ("GR", "Greece"), + ("GL", "Greenland"), + ("GD", "Grenada"), + ("GP", "Guadeloupe"), + ("GU", "Guam"), + ("GT", "Guatemala"), + ("GG", "Guernsey"), + ("GN", "Guinea"), + ("GW", "Guinea-Bissau"), + ("GY", "Guyana"), + ("HT", "Haiti"), + ("HM", "Heard Island and McDonald Islands"), + ("VA", "Holy See (Vatican City State)"), + ("HN", "Honduras"), + ("HK", "Hong Kong"), + ("HU", "Hungary"), + ("IS", "Iceland"), + ("IN", "India"), + ("ID", "Indonesia"), + ("IR", "Iran, Islamic Republic of"), + ("IQ", "Iraq"), + ("IE", "Ireland"), + ("IM", "Isle of Man"), + ("IL", "Israel"), + ("IT", "Italy"), + ("JM", "Jamaica"), + ("JP", "Japan"), + ("JE", "Jersey"), + ("JO", "Jordan"), + ("KZ", "Kazakhstan"), + ("KE", "Kenya"), + ("KI", "Kiribati"), + ("KP", "Korea, Democratic People's Republic of"), + ("KR", "Korea, Republic of"), + ("KW", "Kuwait"), + ("KG", "Kyrgyzstan"), + ("LA", "Lao People's Democratic Republic"), + ("LV", "Latvia"), + ("LB", "Lebanon"), + ("LS", "Lesotho"), + ("LR", "Liberia"), + ("LY", "Libya"), + ("LI", "Liechtenstein"), + ("LT", "Lithuania"), + ("LU", "Luxembourg"), + ("MO", "Macao"), + ("MG", "Madagascar"), + ("MW", "Malawi"), + ("MY", "Malaysia"), + ("MV", "Maldives"), + ("ML", "Mali"), + ("MT", "Malta"), + ("MH", "Marshall Islands"), + ("MQ", "Martinique"), + ("MR", "Mauritania"), + ("MU", "Mauritius"), + ("YT", "Mayotte"), + ("MX", "Mexico"), + ("FM", "Micronesia, Federated States of"), + ("MD", "Moldova, Republic of"), + ("MC", "Monaco"), + ("MN", "Mongolia"), + ("ME", "Montenegro"), + ("MS", "Montserrat"), + ("MA", "Morocco"), + ("MZ", "Mozambique"), + ("MM", "Myanmar"), + ("NA", "Namibia"), + ("NR", "Nauru"), + ("NP", "Nepal"), + ("NL", "Netherlands"), + ("NC", "New Caledonia"), + ("NZ", "New Zealand"), + ("NI", "Nicaragua"), + ("NE", "Niger"), + ("NG", "Nigeria"), + ("NU", "Niue"), + ("NF", "Norfolk Island"), + ("MK", "North Macedonia"), + ("MP", "Northern Mariana Islands"), + ("NO", "Norway"), + ("OM", "Oman"), + ("PK", "Pakistan"), + ("PW", "Palau"), + ("PS", "Palestine, State of"), + ("PA", "Panama"), + ("PG", "Papua New Guinea"), + ("PY", "Paraguay"), + ("PE", "Peru"), + ("PH", "Philippines"), + ("PN", "Pitcairn"), + ("PL", "Poland"), + ("PT", "Portugal"), + ("PR", "Puerto Rico"), + ("QA", "Qatar"), + ("RO", "Romania"), + ("RU", "Russian Federation"), + ("RW", "Rwanda"), + ("RE", "Réunion"), + ("BL", "Saint Barthélemy"), + ("SH", "Saint Helena, Ascension and Tristan da Cunha"), + ("KN", "Saint Kitts and Nevis"), + ("LC", "Saint Lucia"), + ("MF", "Saint Martin (French part)"), + ("PM", "Saint Pierre and Miquelon"), + ("VC", "Saint Vincent and the Grenadines"), + ("WS", "Samoa"), + ("SM", "San Marino"), + ("ST", "Sao Tome and Principe"), + ("SA", "Saudi Arabia"), + ("SN", "Senegal"), + ("RS", "Serbia"), + ("SC", "Seychelles"), + ("SL", "Sierra Leone"), + ("SG", "Singapore"), + ("SX", "Sint Maarten (Dutch part)"), + ("SK", "Slovakia"), + ("SI", "Slovenia"), + ("SB", "Solomon Islands"), + ("SO", "Somalia"), + ("ZA", "South Africa"), + ("GS", "South Georgia and the South Sandwich Islands"), + ("SS", "South Sudan"), + ("ES", "Spain"), + ("LK", "Sri Lanka"), + ("SD", "Sudan"), + ("SR", "Suriname"), + ("SJ", "Svalbard and Jan Mayen"), + ("SE", "Sweden"), + ("CH", "Switzerland"), + ("SY", "Syrian Arab Republic"), + ("TW", "Taiwan, Province of China"), + ("TJ", "Tajikistan"), + ("TZ", "Tanzania, United Republic of"), + ("TH", "Thailand"), + ("TL", "Timor-Leste"), + ("TG", "Togo"), + ("TK", "Tokelau"), + ("TO", "Tonga"), + ("TT", "Trinidad and Tobago"), + ("TN", "Tunisia"), + ("TM", "Turkmenistan"), + ("TC", "Turks and Caicos Islands"), + ("TV", "Tuvalu"), + ("TR", "Türkiye"), + ("UG", "Uganda"), + ("UA", "Ukraine"), + ("AE", "United Arab Emirates"), + ("GB", "United Kingdom"), + ("US", "United States"), + ("UM", "United States Minor Outlying Islands"), + ("UY", "Uruguay"), + ("UZ", "Uzbekistan"), + ("VU", "Vanuatu"), + ("VE", "Venezuela, Bolivarian Republic of"), + ("VN", "Viet Nam"), + ("VG", "Virgin Islands, British"), + ("VI", "Virgin Islands, U.S."), + ("WF", "Wallis and Futuna"), + ("EH", "Western Sahara"), + ("YE", "Yemen"), + ("ZM", "Zambia"), + ("ZW", "Zimbabwe"), + ("AX", "Åland Islands"), + ], + max_length=100, + null=True, + verbose_name="Travelling from", + ), + ), + ] From de6c00beab8936a74b67d484c4c2b31e2295c2b9 Mon Sep 17 00:00:00 2001 From: Etty Date: Thu, 28 Dec 2023 18:40:27 +0100 Subject: [PATCH 3/4] Remove only travelling_from --- backend/api/grants/mutations.py | 8 +- backend/api/grants/tests/test_send_grant.py | 8 +- backend/api/grants/tests/test_update_grant.py | 10 +- backend/api/grants/types.py | 4 +- backend/grants/admin.py | 16 +- ...13_remove_grant_traveling_from_and_more.py | 277 ------------------ .../0013_remove_grant_travelling_from.py | 16 + backend/grants/models.py | 8 +- backend/grants/tests/factories.py | 2 +- 9 files changed, 44 insertions(+), 305 deletions(-) delete mode 100644 backend/grants/migrations/0013_remove_grant_traveling_from_and_more.py create mode 100644 backend/grants/migrations/0013_remove_grant_travelling_from.py diff --git a/backend/api/grants/mutations.py b/backend/api/grants/mutations.py index 8966cc6166..e0a4e3bc7b 100644 --- a/backend/api/grants/mutations.py +++ b/backend/api/grants/mutations.py @@ -41,7 +41,7 @@ class _GrantErrors: need_accommodation: list[str] = strawberry.field(default_factory=list) why: list[str] = strawberry.field(default_factory=list) notes: list[str] = strawberry.field(default_factory=list) - travelling_from: list[str] = strawberry.field(default_factory=list) + traveling_from: list[str] = strawberry.field(default_factory=list) non_field_errors: list[str] = strawberry.field(default_factory=list) website: list[str] = strawberry.field(default_factory=list) twitter_handle: list[str] = strawberry.field(default_factory=list) @@ -65,7 +65,7 @@ def validate(self, conference: Conference, user: User) -> GrantErrors: max_length_fields = { "name": 300, "full_name": 300, - "travelling_from": 200, + "traveling_from": 200, "twitter_handle": 15, "github_handle": 39, } @@ -114,7 +114,7 @@ class SendGrantInput(BaseGrantInput): need_accommodation: bool why: str notes: str - travelling_from: str + traveling_from: str website: str twitter_handle: str github_handle: str @@ -149,7 +149,7 @@ class UpdateGrantInput(BaseGrantInput): need_accommodation: bool why: str notes: str - travelling_from: str + traveling_from: str website: str twitter_handle: str github_handle: str diff --git a/backend/api/grants/tests/test_send_grant.py b/backend/api/grants/tests/test_send_grant.py index 394ceeebf6..36c94dadb1 100644 --- a/backend/api/grants/tests/test_send_grant.py +++ b/backend/api/grants/tests/test_send_grant.py @@ -32,7 +32,7 @@ def _send_grant(client, grant_factory, conference, **kwargs): validationNeedAccommodation: needAccommodation validationWhy: why validationNotes: notes - validationTravellingFrom: travellingFrom + validationTravellingFrom: travelingFrom validationWebsite: website validationTwitterHandle: twitterHandle validationGithubHandle: githubHandle @@ -62,7 +62,7 @@ def _send_grant(client, grant_factory, conference, **kwargs): "needAccommodation": grant.need_accommodation, "why": grant.why, "notes": grant.notes, - "travellingFrom": grant.travelling_from, + "travelingFrom": grant.traveling_from, "website": grant.website, "twitterHandle": grant.twitter_handle, "githubHandle": grant.github_handle, @@ -170,7 +170,7 @@ def test_cannot_send_grant_outside_allowed_values( grant_factory, conference, name="Marcotte" * 50, - travellingFrom="Very long location" * 50, + travelingFrom="Very long location" * 50, ) assert response["data"]["sendGrant"]["__typename"] == "GrantErrors" @@ -178,7 +178,7 @@ def test_cannot_send_grant_outside_allowed_values( "name: Cannot be more than 300 chars" ] assert response["data"]["sendGrant"]["errors"]["validationTravellingFrom"] == [ - "travelling_from: Cannot be more than 200 chars" + "traveling_from: Cannot be more than 200 chars" ] diff --git a/backend/api/grants/tests/test_update_grant.py b/backend/api/grants/tests/test_update_grant.py index d94ac4b76c..4337978546 100644 --- a/backend/api/grants/tests/test_update_grant.py +++ b/backend/api/grants/tests/test_update_grant.py @@ -31,7 +31,7 @@ def _update_grant(graphql_client, grant, **kwargs): validationNeedAccommodation: needAccommodation validationWhy: why validationNotes: notes - validationTravellingFrom: travellingFrom + validationTravellingFrom: travelingFrom validationWebsite: website validationTwitterHandle: twitterHandle validationGithubHandle: githubHandle @@ -61,7 +61,7 @@ def _update_grant(graphql_client, grant, **kwargs): "needAccommodation": grant.need_accommodation, "why": grant.why, "notes": grant.notes, - "travellingFrom": grant.travelling_from, + "travelingFrom": grant.traveling_from, "website": grant.website, "twitterHandle": grant.twitter_handle, "githubHandle": grant.github_handle, @@ -104,7 +104,7 @@ def test_update_grant(graphql_client, user, conference_factory, grant_factory): needAccommodation=True, why="why not", notes="🧸", - travellingFrom="London", + travelingFrom="London", website="https://marcotte.house", twitterHandle="@marcottebear", githubHandle="marcottebear", @@ -203,7 +203,7 @@ def test_cannot_update_submission_with_lang_outside_allowed_values( graphql_client, grant=grant, name="Marcotte" * 50, - travellingFrom="Very long location" * 50, + travelingFrom="Very long location" * 50, ) assert response["data"]["updateGrant"]["__typename"] == "GrantErrors" @@ -211,5 +211,5 @@ def test_cannot_update_submission_with_lang_outside_allowed_values( "name: Cannot be more than 300 chars" ] assert response["data"]["updateGrant"]["errors"]["validationTravellingFrom"] == [ - "travelling_from: Cannot be more than 200 chars" + "traveling_from: Cannot be more than 200 chars" ] diff --git a/backend/api/grants/types.py b/backend/api/grants/types.py index cc1d9f8c06..3e4b3f3bed 100644 --- a/backend/api/grants/types.py +++ b/backend/api/grants/types.py @@ -33,7 +33,7 @@ class Grant: need_accommodation: bool why: str notes: str - travelling_from: str + traveling_from: str applicant_reply_deadline: Optional[datetime] applicant_message: Optional[str] website: str @@ -64,7 +64,7 @@ def from_model(cls, grant: GrantModel) -> Grant: need_accommodation=grant.need_accommodation, why=grant.why, notes=grant.notes, - travelling_from=grant.travelling_from, + traveling_from=grant.traveling_from, applicant_reply_deadline=grant.applicant_reply_deadline, applicant_message=grant.applicant_message, website=grant.website, diff --git a/backend/grants/admin.py b/backend/grants/admin.py index 126ddf3ae7..2dcc67ef18 100644 --- a/backend/grants/admin.py +++ b/backend/grants/admin.py @@ -39,7 +39,7 @@ "needs_funds_for_travel", "why", "notes", - "travelling_from", + "traveling_from", "conference__code", "created", ) @@ -351,7 +351,7 @@ class Meta: "needs_funds_for_travel", "why", "notes", - "travelling_from", + "traveling_from", "country_type", "applicant_message", "applicant_reply_sent_at", @@ -388,12 +388,12 @@ class GrantAdmin(ExportMixin, admin.ModelAdmin): "occupation", "grant_type", "interested_in_volunteering", - ("travelling_from", CountryFilter), + ("traveling_from", CountryFilter), ) search_fields = ( "email", "full_name", - "travelling_from", + "traveling_from", "been_to_other_events", "why", "notes", @@ -452,7 +452,7 @@ class GrantAdmin(ExportMixin, admin.ModelAdmin): "needs_funds_for_travel", "need_visa", "need_accommodation", - "travelling_from", + "traveling_from", "why", "python_usage", "been_to_other_events", @@ -481,8 +481,8 @@ def user_display_name(self, obj): description="C", ) def country(self, obj): - if obj.travelling_from: - country = countries.get(code=obj.travelling_from) + if obj.traveling_from: + country = countries.get(code=obj.traveling_from) if country: return country.emoji @@ -573,7 +573,7 @@ def get_queryset(self, request): return self.qs def changelist_view(self, request, extra_context=None): - qs = self.get_queryset(request).order_by("travelling_from") + qs = self.get_queryset(request).order_by("traveling_from") results = [] for country_code, group in groupby(list(qs), key=lambda k: k.traveling_from): diff --git a/backend/grants/migrations/0013_remove_grant_traveling_from_and_more.py b/backend/grants/migrations/0013_remove_grant_traveling_from_and_more.py deleted file mode 100644 index 2545457961..0000000000 --- a/backend/grants/migrations/0013_remove_grant_traveling_from_and_more.py +++ /dev/null @@ -1,277 +0,0 @@ -# Generated by Django 4.2.7 on 2023-12-28 14:34 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("grants", "0012_grant_community_contribution_grant_github_handle_and_more"), - ] - - operations = [ - migrations.RemoveField( - model_name="grant", - name="traveling_from", - ), - migrations.AlterField( - model_name="grant", - name="travelling_from", - field=models.CharField( - blank=True, - choices=[ - ("AF", "Afghanistan"), - ("AL", "Albania"), - ("DZ", "Algeria"), - ("AS", "American Samoa"), - ("AD", "Andorra"), - ("AO", "Angola"), - ("AI", "Anguilla"), - ("AQ", "Antarctica"), - ("AG", "Antigua and Barbuda"), - ("AR", "Argentina"), - ("AM", "Armenia"), - ("AW", "Aruba"), - ("AU", "Australia"), - ("AT", "Austria"), - ("AZ", "Azerbaijan"), - ("BS", "Bahamas"), - ("BH", "Bahrain"), - ("BD", "Bangladesh"), - ("BB", "Barbados"), - ("BY", "Belarus"), - ("BE", "Belgium"), - ("BZ", "Belize"), - ("BJ", "Benin"), - ("BM", "Bermuda"), - ("BT", "Bhutan"), - ("BO", "Bolivia, Plurinational State of"), - ("BQ", "Bonaire, Sint Eustatius and Saba"), - ("BA", "Bosnia and Herzegovina"), - ("BW", "Botswana"), - ("BV", "Bouvet Island"), - ("BR", "Brazil"), - ("IO", "British Indian Ocean Territory"), - ("BN", "Brunei Darussalam"), - ("BG", "Bulgaria"), - ("BF", "Burkina Faso"), - ("BI", "Burundi"), - ("CV", "Cabo Verde"), - ("KH", "Cambodia"), - ("CM", "Cameroon"), - ("CA", "Canada"), - ("KY", "Cayman Islands"), - ("CF", "Central African Republic"), - ("TD", "Chad"), - ("CL", "Chile"), - ("CN", "China"), - ("CX", "Christmas Island"), - ("CC", "Cocos (Keeling) Islands"), - ("CO", "Colombia"), - ("KM", "Comoros"), - ("CG", "Congo"), - ("CD", "Congo, The Democratic Republic of the"), - ("CK", "Cook Islands"), - ("CR", "Costa Rica"), - ("HR", "Croatia"), - ("CU", "Cuba"), - ("CW", "Curaçao"), - ("CY", "Cyprus"), - ("CZ", "Czechia"), - ("CI", "Côte d'Ivoire"), - ("DK", "Denmark"), - ("DJ", "Djibouti"), - ("DM", "Dominica"), - ("DO", "Dominican Republic"), - ("EC", "Ecuador"), - ("EG", "Egypt"), - ("SV", "El Salvador"), - ("GQ", "Equatorial Guinea"), - ("ER", "Eritrea"), - ("EE", "Estonia"), - ("SZ", "Eswatini"), - ("ET", "Ethiopia"), - ("FK", "Falkland Islands (Malvinas)"), - ("FO", "Faroe Islands"), - ("FJ", "Fiji"), - ("FI", "Finland"), - ("FR", "France"), - ("GF", "French Guiana"), - ("PF", "French Polynesia"), - ("TF", "French Southern Territories"), - ("GA", "Gabon"), - ("GM", "Gambia"), - ("GE", "Georgia"), - ("DE", "Germany"), - ("GH", "Ghana"), - ("GI", "Gibraltar"), - ("GR", "Greece"), - ("GL", "Greenland"), - ("GD", "Grenada"), - ("GP", "Guadeloupe"), - ("GU", "Guam"), - ("GT", "Guatemala"), - ("GG", "Guernsey"), - ("GN", "Guinea"), - ("GW", "Guinea-Bissau"), - ("GY", "Guyana"), - ("HT", "Haiti"), - ("HM", "Heard Island and McDonald Islands"), - ("VA", "Holy See (Vatican City State)"), - ("HN", "Honduras"), - ("HK", "Hong Kong"), - ("HU", "Hungary"), - ("IS", "Iceland"), - ("IN", "India"), - ("ID", "Indonesia"), - ("IR", "Iran, Islamic Republic of"), - ("IQ", "Iraq"), - ("IE", "Ireland"), - ("IM", "Isle of Man"), - ("IL", "Israel"), - ("IT", "Italy"), - ("JM", "Jamaica"), - ("JP", "Japan"), - ("JE", "Jersey"), - ("JO", "Jordan"), - ("KZ", "Kazakhstan"), - ("KE", "Kenya"), - ("KI", "Kiribati"), - ("KP", "Korea, Democratic People's Republic of"), - ("KR", "Korea, Republic of"), - ("KW", "Kuwait"), - ("KG", "Kyrgyzstan"), - ("LA", "Lao People's Democratic Republic"), - ("LV", "Latvia"), - ("LB", "Lebanon"), - ("LS", "Lesotho"), - ("LR", "Liberia"), - ("LY", "Libya"), - ("LI", "Liechtenstein"), - ("LT", "Lithuania"), - ("LU", "Luxembourg"), - ("MO", "Macao"), - ("MG", "Madagascar"), - ("MW", "Malawi"), - ("MY", "Malaysia"), - ("MV", "Maldives"), - ("ML", "Mali"), - ("MT", "Malta"), - ("MH", "Marshall Islands"), - ("MQ", "Martinique"), - ("MR", "Mauritania"), - ("MU", "Mauritius"), - ("YT", "Mayotte"), - ("MX", "Mexico"), - ("FM", "Micronesia, Federated States of"), - ("MD", "Moldova, Republic of"), - ("MC", "Monaco"), - ("MN", "Mongolia"), - ("ME", "Montenegro"), - ("MS", "Montserrat"), - ("MA", "Morocco"), - ("MZ", "Mozambique"), - ("MM", "Myanmar"), - ("NA", "Namibia"), - ("NR", "Nauru"), - ("NP", "Nepal"), - ("NL", "Netherlands"), - ("NC", "New Caledonia"), - ("NZ", "New Zealand"), - ("NI", "Nicaragua"), - ("NE", "Niger"), - ("NG", "Nigeria"), - ("NU", "Niue"), - ("NF", "Norfolk Island"), - ("MK", "North Macedonia"), - ("MP", "Northern Mariana Islands"), - ("NO", "Norway"), - ("OM", "Oman"), - ("PK", "Pakistan"), - ("PW", "Palau"), - ("PS", "Palestine, State of"), - ("PA", "Panama"), - ("PG", "Papua New Guinea"), - ("PY", "Paraguay"), - ("PE", "Peru"), - ("PH", "Philippines"), - ("PN", "Pitcairn"), - ("PL", "Poland"), - ("PT", "Portugal"), - ("PR", "Puerto Rico"), - ("QA", "Qatar"), - ("RO", "Romania"), - ("RU", "Russian Federation"), - ("RW", "Rwanda"), - ("RE", "Réunion"), - ("BL", "Saint Barthélemy"), - ("SH", "Saint Helena, Ascension and Tristan da Cunha"), - ("KN", "Saint Kitts and Nevis"), - ("LC", "Saint Lucia"), - ("MF", "Saint Martin (French part)"), - ("PM", "Saint Pierre and Miquelon"), - ("VC", "Saint Vincent and the Grenadines"), - ("WS", "Samoa"), - ("SM", "San Marino"), - ("ST", "Sao Tome and Principe"), - ("SA", "Saudi Arabia"), - ("SN", "Senegal"), - ("RS", "Serbia"), - ("SC", "Seychelles"), - ("SL", "Sierra Leone"), - ("SG", "Singapore"), - ("SX", "Sint Maarten (Dutch part)"), - ("SK", "Slovakia"), - ("SI", "Slovenia"), - ("SB", "Solomon Islands"), - ("SO", "Somalia"), - ("ZA", "South Africa"), - ("GS", "South Georgia and the South Sandwich Islands"), - ("SS", "South Sudan"), - ("ES", "Spain"), - ("LK", "Sri Lanka"), - ("SD", "Sudan"), - ("SR", "Suriname"), - ("SJ", "Svalbard and Jan Mayen"), - ("SE", "Sweden"), - ("CH", "Switzerland"), - ("SY", "Syrian Arab Republic"), - ("TW", "Taiwan, Province of China"), - ("TJ", "Tajikistan"), - ("TZ", "Tanzania, United Republic of"), - ("TH", "Thailand"), - ("TL", "Timor-Leste"), - ("TG", "Togo"), - ("TK", "Tokelau"), - ("TO", "Tonga"), - ("TT", "Trinidad and Tobago"), - ("TN", "Tunisia"), - ("TM", "Turkmenistan"), - ("TC", "Turks and Caicos Islands"), - ("TV", "Tuvalu"), - ("TR", "Türkiye"), - ("UG", "Uganda"), - ("UA", "Ukraine"), - ("AE", "United Arab Emirates"), - ("GB", "United Kingdom"), - ("US", "United States"), - ("UM", "United States Minor Outlying Islands"), - ("UY", "Uruguay"), - ("UZ", "Uzbekistan"), - ("VU", "Vanuatu"), - ("VE", "Venezuela, Bolivarian Republic of"), - ("VN", "Viet Nam"), - ("VG", "Virgin Islands, British"), - ("VI", "Virgin Islands, U.S."), - ("WF", "Wallis and Futuna"), - ("EH", "Western Sahara"), - ("YE", "Yemen"), - ("ZM", "Zambia"), - ("ZW", "Zimbabwe"), - ("AX", "Åland Islands"), - ], - max_length=100, - null=True, - verbose_name="Travelling from", - ), - ), - ] diff --git a/backend/grants/migrations/0013_remove_grant_travelling_from.py b/backend/grants/migrations/0013_remove_grant_travelling_from.py new file mode 100644 index 0000000000..2299879c25 --- /dev/null +++ b/backend/grants/migrations/0013_remove_grant_travelling_from.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.7 on 2023-12-28 17:31 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("grants", "0012_grant_community_contribution_grant_github_handle_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="grant", + name="travelling_from", + ), + ] diff --git a/backend/grants/models.py b/backend/grants/models.py index f42f3436c3..8843b7c25a 100644 --- a/backend/grants/models.py +++ b/backend/grants/models.py @@ -90,8 +90,8 @@ class ApprovedType(models.TextChoices): grant_type = models.CharField( _("grant type"), choices=GrantType.choices, max_length=10 ) - travelling_from = models.CharField( - _("Travelling from"), + traveling_from = models.CharField( + _("Traveling from"), max_length=100, blank=True, null=True, @@ -204,8 +204,8 @@ def __str__(self): return f"{self.full_name}" def save(self, *args, **kwargs): - if self.travelling_from: - country = countries.get(code=self.travelling_from) + if self.traveling_from: + country = countries.get(code=self.traveling_from) assert country if country.code == "IT": self.country_type = Grant.CountryType.italy diff --git a/backend/grants/tests/factories.py b/backend/grants/tests/factories.py index e380a0dc0d..f38d74a756 100644 --- a/backend/grants/tests/factories.py +++ b/backend/grants/tests/factories.py @@ -31,7 +31,7 @@ class Meta: needs_funds_for_travel = factory.Faker("boolean") why = factory.Faker("text") notes = factory.Faker("text") - travelling_from = factory.Faker("country") + traveling_from = factory.Faker("country") website = factory.Faker("url") twitter_handle = "@handle" github_handle = factory.Faker("user_name") From 7bf8bca86d426e5e23ac641e73e1c9a1a0acfe89 Mon Sep 17 00:00:00 2001 From: Etty Date: Thu, 28 Dec 2023 19:18:17 +0100 Subject: [PATCH 4/4] Rename traveling_from to travelling_from --- backend/api/grants/mutations.py | 8 ++++---- backend/api/grants/tests/test_send_grant.py | 8 ++++---- backend/api/grants/tests/test_update_grant.py | 10 +++++----- backend/api/grants/types.py | 4 ++-- backend/grants/admin.py | 18 +++++++++--------- ...ant_traveling_from_grant_travelling_from.py | 17 +++++++++++++++++ backend/grants/models.py | 8 ++++---- backend/grants/tests/factories.py | 3 ++- 8 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 backend/grants/migrations/0014_rename_grant_traveling_from_grant_travelling_from.py diff --git a/backend/api/grants/mutations.py b/backend/api/grants/mutations.py index e0a4e3bc7b..8966cc6166 100644 --- a/backend/api/grants/mutations.py +++ b/backend/api/grants/mutations.py @@ -41,7 +41,7 @@ class _GrantErrors: need_accommodation: list[str] = strawberry.field(default_factory=list) why: list[str] = strawberry.field(default_factory=list) notes: list[str] = strawberry.field(default_factory=list) - traveling_from: list[str] = strawberry.field(default_factory=list) + travelling_from: list[str] = strawberry.field(default_factory=list) non_field_errors: list[str] = strawberry.field(default_factory=list) website: list[str] = strawberry.field(default_factory=list) twitter_handle: list[str] = strawberry.field(default_factory=list) @@ -65,7 +65,7 @@ def validate(self, conference: Conference, user: User) -> GrantErrors: max_length_fields = { "name": 300, "full_name": 300, - "traveling_from": 200, + "travelling_from": 200, "twitter_handle": 15, "github_handle": 39, } @@ -114,7 +114,7 @@ class SendGrantInput(BaseGrantInput): need_accommodation: bool why: str notes: str - traveling_from: str + travelling_from: str website: str twitter_handle: str github_handle: str @@ -149,7 +149,7 @@ class UpdateGrantInput(BaseGrantInput): need_accommodation: bool why: str notes: str - traveling_from: str + travelling_from: str website: str twitter_handle: str github_handle: str diff --git a/backend/api/grants/tests/test_send_grant.py b/backend/api/grants/tests/test_send_grant.py index 36c94dadb1..394ceeebf6 100644 --- a/backend/api/grants/tests/test_send_grant.py +++ b/backend/api/grants/tests/test_send_grant.py @@ -32,7 +32,7 @@ def _send_grant(client, grant_factory, conference, **kwargs): validationNeedAccommodation: needAccommodation validationWhy: why validationNotes: notes - validationTravellingFrom: travelingFrom + validationTravellingFrom: travellingFrom validationWebsite: website validationTwitterHandle: twitterHandle validationGithubHandle: githubHandle @@ -62,7 +62,7 @@ def _send_grant(client, grant_factory, conference, **kwargs): "needAccommodation": grant.need_accommodation, "why": grant.why, "notes": grant.notes, - "travelingFrom": grant.traveling_from, + "travellingFrom": grant.travelling_from, "website": grant.website, "twitterHandle": grant.twitter_handle, "githubHandle": grant.github_handle, @@ -170,7 +170,7 @@ def test_cannot_send_grant_outside_allowed_values( grant_factory, conference, name="Marcotte" * 50, - travelingFrom="Very long location" * 50, + travellingFrom="Very long location" * 50, ) assert response["data"]["sendGrant"]["__typename"] == "GrantErrors" @@ -178,7 +178,7 @@ def test_cannot_send_grant_outside_allowed_values( "name: Cannot be more than 300 chars" ] assert response["data"]["sendGrant"]["errors"]["validationTravellingFrom"] == [ - "traveling_from: Cannot be more than 200 chars" + "travelling_from: Cannot be more than 200 chars" ] diff --git a/backend/api/grants/tests/test_update_grant.py b/backend/api/grants/tests/test_update_grant.py index 4337978546..5d4703d02c 100644 --- a/backend/api/grants/tests/test_update_grant.py +++ b/backend/api/grants/tests/test_update_grant.py @@ -31,7 +31,7 @@ def _update_grant(graphql_client, grant, **kwargs): validationNeedAccommodation: needAccommodation validationWhy: why validationNotes: notes - validationTravellingFrom: travelingFrom + validationTravellingFrom: travellingFrom validationWebsite: website validationTwitterHandle: twitterHandle validationGithubHandle: githubHandle @@ -61,7 +61,7 @@ def _update_grant(graphql_client, grant, **kwargs): "needAccommodation": grant.need_accommodation, "why": grant.why, "notes": grant.notes, - "travelingFrom": grant.traveling_from, + "travellingFrom": grant.travelling_from, "website": grant.website, "twitterHandle": grant.twitter_handle, "githubHandle": grant.github_handle, @@ -104,7 +104,7 @@ def test_update_grant(graphql_client, user, conference_factory, grant_factory): needAccommodation=True, why="why not", notes="🧸", - travelingFrom="London", + travellingFrom="GB", website="https://marcotte.house", twitterHandle="@marcottebear", githubHandle="marcottebear", @@ -203,7 +203,7 @@ def test_cannot_update_submission_with_lang_outside_allowed_values( graphql_client, grant=grant, name="Marcotte" * 50, - travelingFrom="Very long location" * 50, + travellingFrom="Very long location" * 50, ) assert response["data"]["updateGrant"]["__typename"] == "GrantErrors" @@ -211,5 +211,5 @@ def test_cannot_update_submission_with_lang_outside_allowed_values( "name: Cannot be more than 300 chars" ] assert response["data"]["updateGrant"]["errors"]["validationTravellingFrom"] == [ - "traveling_from: Cannot be more than 200 chars" + "travelling_from: Cannot be more than 200 chars" ] diff --git a/backend/api/grants/types.py b/backend/api/grants/types.py index 3e4b3f3bed..cc1d9f8c06 100644 --- a/backend/api/grants/types.py +++ b/backend/api/grants/types.py @@ -33,7 +33,7 @@ class Grant: need_accommodation: bool why: str notes: str - traveling_from: str + travelling_from: str applicant_reply_deadline: Optional[datetime] applicant_message: Optional[str] website: str @@ -64,7 +64,7 @@ def from_model(cls, grant: GrantModel) -> Grant: need_accommodation=grant.need_accommodation, why=grant.why, notes=grant.notes, - traveling_from=grant.traveling_from, + travelling_from=grant.travelling_from, applicant_reply_deadline=grant.applicant_reply_deadline, applicant_message=grant.applicant_message, website=grant.website, diff --git a/backend/grants/admin.py b/backend/grants/admin.py index 2dcc67ef18..813e41f499 100644 --- a/backend/grants/admin.py +++ b/backend/grants/admin.py @@ -39,7 +39,7 @@ "needs_funds_for_travel", "why", "notes", - "traveling_from", + "travelling_from", "conference__code", "created", ) @@ -351,7 +351,7 @@ class Meta: "needs_funds_for_travel", "why", "notes", - "traveling_from", + "travelling_from", "country_type", "applicant_message", "applicant_reply_sent_at", @@ -388,12 +388,12 @@ class GrantAdmin(ExportMixin, admin.ModelAdmin): "occupation", "grant_type", "interested_in_volunteering", - ("traveling_from", CountryFilter), + ("travelling_from", CountryFilter), ) search_fields = ( "email", "full_name", - "traveling_from", + "travelling_from", "been_to_other_events", "why", "notes", @@ -452,7 +452,7 @@ class GrantAdmin(ExportMixin, admin.ModelAdmin): "needs_funds_for_travel", "need_visa", "need_accommodation", - "traveling_from", + "travelling_from", "why", "python_usage", "been_to_other_events", @@ -481,8 +481,8 @@ def user_display_name(self, obj): description="C", ) def country(self, obj): - if obj.traveling_from: - country = countries.get(code=obj.traveling_from) + if obj.travelling_from: + country = countries.get(code=obj.travelling_from) if country: return country.emoji @@ -573,10 +573,10 @@ def get_queryset(self, request): return self.qs def changelist_view(self, request, extra_context=None): - qs = self.get_queryset(request).order_by("traveling_from") + qs = self.get_queryset(request).order_by("travelling_from") results = [] - for country_code, group in groupby(list(qs), key=lambda k: k.traveling_from): + for country_code, group in groupby(list(qs), key=lambda k: k.travelling_from): country = countries.get(code=country_code) if not country: continue diff --git a/backend/grants/migrations/0014_rename_grant_traveling_from_grant_travelling_from.py b/backend/grants/migrations/0014_rename_grant_traveling_from_grant_travelling_from.py new file mode 100644 index 0000000000..47bbaa29eb --- /dev/null +++ b/backend/grants/migrations/0014_rename_grant_traveling_from_grant_travelling_from.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.7 on 2023-12-28 18:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("grants", "0013_remove_grant_travelling_from"), + ] + + operations = [ + migrations.RenameField( + model_name='grant', + old_name='traveling_from', + new_name='travelling_from', + ), + ] diff --git a/backend/grants/models.py b/backend/grants/models.py index 8843b7c25a..f42f3436c3 100644 --- a/backend/grants/models.py +++ b/backend/grants/models.py @@ -90,8 +90,8 @@ class ApprovedType(models.TextChoices): grant_type = models.CharField( _("grant type"), choices=GrantType.choices, max_length=10 ) - traveling_from = models.CharField( - _("Traveling from"), + travelling_from = models.CharField( + _("Travelling from"), max_length=100, blank=True, null=True, @@ -204,8 +204,8 @@ def __str__(self): return f"{self.full_name}" def save(self, *args, **kwargs): - if self.traveling_from: - country = countries.get(code=self.traveling_from) + if self.travelling_from: + country = countries.get(code=self.travelling_from) assert country if country.code == "IT": self.country_type = Grant.CountryType.italy diff --git a/backend/grants/tests/factories.py b/backend/grants/tests/factories.py index f38d74a756..42bec0fda5 100644 --- a/backend/grants/tests/factories.py +++ b/backend/grants/tests/factories.py @@ -6,6 +6,7 @@ from grants.models import Grant from helpers.constants import GENDERS from users.tests.factories import UserFactory +from countries import countries @register @@ -31,7 +32,7 @@ class Meta: needs_funds_for_travel = factory.Faker("boolean") why = factory.Faker("text") notes = factory.Faker("text") - traveling_from = factory.Faker("country") + travelling_from = factory.fuzzy.FuzzyChoice([country.code for country in countries]) website = factory.Faker("url") twitter_handle = "@handle" github_handle = factory.Faker("user_name")