authentik.policies.geoip.serializer_fields
Workaround for https://github.com/SmileyChris/django-countries/issues/441
1"""Workaround for https://github.com/SmileyChris/django-countries/issues/441""" 2 3from django_countries.serializer_fields import CountryField 4from drf_spectacular.utils import extend_schema_field, inline_serializer 5from rest_framework import serializers 6 7DETAILED_COUNTRY_SCHEMA = { 8 "code": CountryField(), 9 "name": serializers.CharField(), 10} 11 12 13@extend_schema_field( 14 inline_serializer( 15 "DetailedCountryField", 16 DETAILED_COUNTRY_SCHEMA, 17 ) 18) 19class DetailedCountryField(CountryField): 20 def __init__(self): 21 super().__init__(country_dict=True)
DETAILED_COUNTRY_SCHEMA =
{'_declared_fields': {'code': CountryField(), 'name': CharField()}}
@extend_schema_field(inline_serializer('DetailedCountryField', DETAILED_COUNTRY_SCHEMA))
class
DetailedCountryField14@extend_schema_field( 15 inline_serializer( 16 "DetailedCountryField", 17 DETAILED_COUNTRY_SCHEMA, 18 ) 19) 20class DetailedCountryField(CountryField): 21 def __init__(self): 22 super().__init__(country_dict=True)
DetailedCountryField(*args, **kwargs)
621 def __new__(cls, *args, **kwargs): 622 """ 623 When a field is instantiated, we store the arguments that were used, 624 so that we can present a helpful representation of the object. 625 """ 626 instance = super().__new__(cls) 627 instance._args = args 628 instance._kwargs = kwargs 629 return instance
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.