Skip to content

Commit

Permalink
Fix middle name import
Browse files Browse the repository at this point in the history
  • Loading branch information
kuboschek committed Oct 22, 2024
1 parent adcb8e9 commit 0e80960
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion registry/management/commands/import_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ def __init__(self):

self.register(["birthday_de"], "birthday", self._parse_birthday_de)
self.register(["birthday_us"], "birthday", self._parse_birthday_us)
self.register(["birthday_dmy_us"], "birthday", self._parse_birthday_dmy_us)
self.register(["birthday_excel"], "birthday", self._parse_birthday_excel)
self.register(["title"], "gender", self._parse_title)
self.register(["name_1_3"], "given_name", self._parse_given_name)
self.register(["name_1_3"], "middle_name", self._parse_middle_name)
self.register(["name_1_3"], "family_name", self._parse_family_name)
self.register(["sex"], "gender", self._parse_sex)

self.register(["name_1"], "given_name", self._parse_required)
self.register(["name_2"], "family_name", self._parse_required)
Expand All @@ -72,6 +75,9 @@ def _parse_birthday_us(self, birthday_us) -> datetime:
def _parse_birthday_excel(self, birthday_us) -> datetime:
return datetime.strptime(birthday_us, "%Y-%m-%d")

def _parse_birthday_dmy_us(self, birthday_dmy_us) -> datetime:
return datetime.strptime(birthday_us, "%d/%m/%Y")

def _parse_title(self, title: str) -> GenderField:
title = title.lower().strip()
if title == "mr.":
Expand All @@ -81,6 +87,15 @@ def _parse_title(self, title: str) -> GenderField:

return GenderField.UNSPECIFIED

def _parse_sex(self, sex: str) -> GenderField:
sex = sex.lower().strip()
if sex == "ma":
return GenderField.MALE
elif sex == "fe":
return GenderField.FEMALE

return GenderField.UNSPECIFIED

def _parse_email(self, value: str) -> str:
value = self._parse_required(value.strip())
self.registration._validate_email(value)
Expand All @@ -92,7 +107,11 @@ def _parse_given_name(self, value: str) -> str:

def _parse_middle_name(self, value: str) -> str:
value = self._parse_required(value.strip())
return " ".join(value.split(" ")[1:])
return " ".join(value.split(" ")[1:-1])

def _parse_family_name(self, value: str) -> str:
value = self._parse_required(value.strip())
return value.split(" ")[-1]

def _parse_required(self, value: str) -> str:
if value == "":
Expand All @@ -113,6 +132,10 @@ def _parse_optional(self, value: str) -> Optional[str]:
"Czech Republic": "Czechia",
}

def _parse_nationalities(self, countries: str) -> Optional[list[CountryField]]:
nationalities = countries.split(",")


def _parse_country(self, country: str) -> Optional[CountryField]:
if country == "":
return None
Expand Down

0 comments on commit 0e80960

Please sign in to comment.