Skip to content

ESoCC: Populate the Country table #5158

@AlexVelezLl

Description

@AlexVelezLl

This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

In #5145 we will introduce a new Country model for storing countries that submissions will target.

We haven't populated this table yet, and we will do this in the scope of this issue.

Technical requirements

We will be utilizing the list of countries provided by pycountry. Therefore, we will need to install this new package and add it to our requirements.in file, then run pip-compile requirements.in to freeze it in our requirements.txt file.

The pycountry package does not support Kosovo which is present in our frontend's country list. Consequently, at the module level in the loadconstants.py file, we will add this country to pycountry's list by following the pycountry guidance:

pycountry.countries.add_entry(alpha_2="XK", alpha_3="XXK", name="Kosovo", numeric="926")

Next, within our loadconstants command, create a new CountryGenerator class that inherits from ConstantGenerator.

  • Point its model field to the new Country model.
  • Point its default_list property to pycountry.countries.
  • Override the id_field property and set it to code, which is the primary key (PK) field in the Country model.
  • Override the get_dict method to return only the code and name of the country in dictionary format.

Finally, we will instantiate this CountryGenerator class, retrieve the generated list, and add it to the CONSTANTS array, that will then be inserted to the database when running the loadconstants command.

Acceptance criteria

  • The countries constants are now loaded to the database after running make migrate in Studio.

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions