mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
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:
16
src/pretix/base/views/js_helpers.py
Normal file
16
src/pretix/base/views/js_helpers.py
Normal 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)
|
||||
]})
|
||||
Reference in New Issue
Block a user