-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
ECIL-342 CPTPP country group, banner for CFS apps and submit validation
- Loading branch information
1 parent
740dbcb
commit cf8c8b3
Showing
13 changed files
with
1,562 additions
and
1,344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.db.models import QuerySet | ||
|
||
from .models import Country | ||
|
||
|
||
def comma_separator(sequence: list) -> str: | ||
if not sequence: | ||
return "" | ||
if len(sequence) == 1: | ||
return sequence[0] | ||
return "{} and {}".format(", ".join(sequence[:-1]), sequence[-1]) | ||
|
||
|
||
def get_cptpp_countries_list() -> str: | ||
cptpp = Country.util.get_cptpp_countries().values_list("name", flat=True) | ||
return comma_separator(list(cptpp)) | ||
|
||
|
||
def get_selected_cptpp_countries(countries: QuerySet["Country"]) -> QuerySet["Country"]: | ||
country_pks = countries.values_list("pk", flat=True) | ||
return Country.util.get_cptpp_countries().filter(pk__in=country_pks) | ||
|
||
|
||
def get_selected_cptpp_countries_list(countries: QuerySet["Country"]) -> str: | ||
selected_countries = get_selected_cptpp_countries(countries) | ||
return comma_separator(list(selected_countries.values_list("name", flat=True))) |
Oops, something went wrong.