-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic extention of `django_countries`: ``` In [1]: from django_countries.fields import Country In [2]: Country("BE").subregion Out[2]: 'QO' In [3]: Country("BE").region Out[3]: 'XE' ``` Ability to get countries by region and subregion: ``` In [7]: from django_countries_regions import regions In [8]: regions.get_countries_by_subregion("QN") Out[8]: ['AL', 'AD', 'BA', 'HR', 'GI', 'GR', 'VA', 'IT', 'MT', 'ME', 'MK', 'PT', 'SM', 'RS', 'SI', 'ES'] ```
- Loading branch information
Showing
11 changed files
with
2,342 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Publish Python Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.10", "3.11", "3.12"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: pip | ||
cache-dependency-path: pyproject.toml | ||
- name: Install dependencies | ||
run: | | ||
pip install '.[test]' | ||
- name: Run tests | ||
run: | | ||
pytest | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: [test] | ||
environment: release | ||
permissions: | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
cache: pip | ||
cache-dependency-path: pyproject.toml | ||
- name: Install dependencies | ||
run: | | ||
pip install setuptools wheel build | ||
- name: Build | ||
run: | | ||
python -m build | ||
- name: Publish | ||
uses: pypa/gh-action-pypi-publish@release/v1 |
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,27 @@ | ||
name: Test | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: pip | ||
cache-dependency-path: pyproject.toml | ||
- name: Install dependencies | ||
run: | | ||
pip install '.[test]' | ||
- name: Run tests | ||
run: | | ||
pytest |
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 |
---|---|---|
|
@@ -32,4 +32,3 @@ repos: | |
rev: "v0.3.5" | ||
hooks: | ||
- id: ruff | ||
|
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 @@ | ||
3.10 |
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,35 @@ | ||
# django-countries-regions | ||
|
||
[![PyPI](https://img.shields.io/pypi/v/django-countries-regions.svg)](https://pypi.org/project/django-countries-regions/) | ||
[![Tests](https://github.com/InternetSociety/django-countries-regions/actions/workflows/test.yml/badge.svg)](https://github.com/InternetSociety/django-countries-regions/actions/workflows/test.yml) | ||
[![Changelog](https://img.shields.io/github/v/release/InternetSociety/django-countries-regions?include_prereleases&label=changelog)](https://github.com/InternetSociety/django-countries-regions/releases) | ||
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/InternetSociety/django-countries-regions/blob/main/LICENSE) | ||
|
||
Adds region and subregion data to django-countries | ||
|
||
## Installation | ||
|
||
Install this library using `pip`: | ||
```bash | ||
pip install django-countries-regions | ||
``` | ||
## Usage | ||
|
||
Usage instructions go here. | ||
|
||
## Development | ||
|
||
To contribute to this library, first checkout the code. Then create a new virtual environment: | ||
```bash | ||
cd django-countries-regions | ||
python -m venv venv | ||
source venv/bin/activate | ||
``` | ||
Now install the dependencies and test dependencies: | ||
```bash | ||
pip install -e '.[test]' | ||
``` | ||
To run the tests: | ||
```bash | ||
pytest | ||
``` |
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,41 @@ | ||
from django_countries_regions.country_regions import COUNTRY_REGIONS | ||
from django_countries_regions.regions import REGIONS, SUBREGIONS | ||
|
||
|
||
# TODO: Would returning `(region_code, region_name)` be more useful? | ||
def get_country_region(country_code, region=True): | ||
code_to_use = "iso_region_alpha2_code" if region else "iso_subregion_alpha2_code" | ||
return COUNTRY_REGIONS[country_code][code_to_use] | ||
|
||
|
||
def get_country_subregion(country_code): | ||
return get_country_region(country_code, region=False) | ||
|
||
|
||
class Regions(): | ||
""" | ||
An object that can query an ISO list of geographical regions and subregions and return a list of countries in | ||
that region. | ||
""" | ||
|
||
def get_countries_by_region(self, region_code, region=True): | ||
if region: | ||
return REGIONS[region_code]["countries"] | ||
else: | ||
return SUBREGIONS[region_code]["countries"] | ||
|
||
def get_countries_by_subregion(self, region_code): | ||
return self.get_countries_by_region(region_code, region=False) | ||
|
||
def get_region_name(self, region_code): | ||
if region_code: | ||
return REGIONS[region_code]["name"] | ||
return None | ||
|
||
def get_subregion_name(self, region_code): | ||
if region_code: | ||
return SUBREGIONS[region_code]["name"] | ||
return None | ||
|
||
|
||
regions = Regions() |
Oops, something went wrong.