Invoice addresses: Ask for a state in some countries (#1362)

* Invoice addresses: Ask for a state in some countries

* API, tests, noscript

* Fix shredder tests

* Add test for addresses with long state names
This commit is contained in:
Raphael Michel
2019-08-09 09:55:46 +02:00
committed by GitHub
parent 547f71aac6
commit d919605d79
19 changed files with 367 additions and 27 deletions

View File

@@ -0,0 +1,16 @@
import pycountry
from django.http import JsonResponse
from pretix.base.settings import COUNTRIES_WITH_STATE_IN_ADDRESS
def states(request):
cc = request.GET.get("country", "DE")
if cc not in COUNTRIES_WITH_STATE_IN_ADDRESS:
return JsonResponse({'data': []})
types, form = COUNTRIES_WITH_STATE_IN_ADDRESS[cc]
statelist = [s for s in pycountry.subdivisions.get(country_code=cc) if s.type in types]
return JsonResponse({'data': [
{'name': s.name, 'code': s.code[3:]}
for s in sorted(statelist, key=lambda s: s.name)
]})