Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
[api] allow search for 2-char insee codes for departements and regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-Crow committed Nov 26, 2021
1 parent b84009d commit 378688f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
47 changes: 26 additions & 21 deletions francedata/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,32 @@ def search_subdivisions(request, query: str, category: str = None, year: int = N
epcis_year_entry = regions_year_entry
communes_year_entry = regions_year_entry

if len(query) < 3 and (category == "communes" or return_all_categories):
shortnamed_communes = [
"by",
"bu",
"eu",
"gy",
"oz",
"oo",
"py",
"ri",
"ry",
"sy",
"ur",
"us",
"uz",
"y",
]
if query in shortnamed_communes:
communes_raw = Commune.objects.filter(
name__unaccent__iexact=query, years__exact=communes_year_entry
)
if len(query) < 3:
if category == "communes" or return_all_categories:
shortnamed_communes = [
"by",
"bu",
"eu",
"gy",
"oz",
"oo",
"py",
"ri",
"ry",
"sy",
"ur",
"us",
"uz",
"y",
]
if query in shortnamed_communes:
communes_raw = Commune.objects.filter(
name__unaccent__iexact=query, years__exact=communes_year_entry
)
if query.isnumeric() and (category == "departements" or return_all_categories):
departements_raw = Departement.objects.filter(insee=query)
if query.isnumeric() and (category == "regions" or return_all_categories):
regions_raw = Region.objects.filter(insee=query)
else:
if category == "regions" or return_all_categories:
regions_raw = Region.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Sylvain Boissel <[email protected]>"]
description = "A Django app to provide a database structure, API and import scripts to manage French communes, intercommunalités, départements and régions, with their structure and data from Insee and the DGCL."
license = "AGPL-3"
name = "django-francedata"
version = "0.14.1"
version = "0.14.2"

classifiers = [
"Development Status :: 3 - Alpha",
Expand Down

0 comments on commit 378688f

Please sign in to comment.