core.bones.selectcountry

A bone representing a country selection input field in a web application or form.

The SelectCountryBone is designed to provide a user-friendly way to select a country from a predefined list of countries. It inherits from the BaseBone class and extends it to support country-specific functionalities, such as displaying country names and handling country codes (e.g., ISO 3166-1 alpha-2 or alpha-3).

Module Contents

Classes

SelectCountryBone

A bone representing a country selection input field in a web application or form.

Attributes

ISO3CODES

ISO 3166-1 alpha-3 (commonly referred to as ISO3) is a part of the ISO 3166 standard, which defines three-letter

ISO2CODES

The ISO 2 country code (also known as ISO 3166-1 alpha-2) is an international standard consisting of two-letter

ISO3TOISO2

A Map of ISO3 to ISO2 country codes

ISO2TOISO3

A built Map of ISO2 to ISO3 country codes

core.bones.selectcountry.ISO3CODES

ISO 3166-1 alpha-3 (commonly referred to as ISO3) is a part of the ISO 3166 standard, which defines three-letter codes to represent countries.

core.bones.selectcountry.ISO2CODES

The ISO 2 country code (also known as ISO 3166-1 alpha-2) is an international standard consisting of two-letter codes used to identify countries.

core.bones.selectcountry.ISO3TOISO2

A Map of ISO3 to ISO2 country codes

core.bones.selectcountry.ISO2TOISO3

A built Map of ISO2 to ISO3 country codes

class core.bones.selectcountry.SelectCountryBone(*, codes=ISO2, values=None, **kwargs)

Bases: viur.core.bones.select.SelectBone

A bone representing a country selection input field in a web application or form.

The SelectCountryBone is designed to provide a user-friendly way to select a country from a predefined list of countries. It inherits from the BaseBone class and extends it to support country-specific functionalities, such as displaying country names and handling country codes (e.g., ISO 3166-1 alpha-2 or alpha-3).

Params List[str] countries:

A list of countries supported by the bone, typically represented by their codes.

Initializes a new SelectBone.

Parameters:
  • defaultValue – key(s) of the values which will be checked by default.

  • values – dict of key->value pairs from which the user can choose from – or a callable that returns a dict.

  • translation_key_prefix – A prefix for the key of the translation object. It is empty by default, so that only the label (dict value) from the values is used. A static string or dynamic method can be used (like translation_key_prefix_bonename).

  • kwargs – Additional keyword arguments that will be passed to the superclass’ __init__ method.

type = 'select.country'
ISO2 = 2
ISO3 = 3
singleValueUnserialize(val)

Unserializes a single value, converting ISO country codes between ISO 3166-1 alpha-2 and alpha-3 if necessary.

This method takes a country code string (either ISO 3166-1 alpha-2 or alpha-3) and checks if a conversion is needed based on the self.codes attribute. If a conversion is required, it attempts to perform the conversion using the ISO3TOISO2 or ISO2TOISO3 dictionaries. If the conversion is successful, the converted code is returned; otherwise, the original value is returned.

Params val:

The value to be unserialized, typically a string representing an ISO country code.

Returns:

The unserialized value, either the original or converted ISO country code.