The lino_xl.lib.statbel.countries plugin

This page is a tested document and the following instructions are used for initialization:

>>> from lino import startup
>>> startup('lino_welfare.projects.gerd.settings.doctests')
>>> from lino.api.doctest import *
>>> from django.db.models import Q
>>> dd.plugins.countries
lino_xl.lib.statbel.countries (extends_models=['Country', 'Place'], needs_plugins=['lino.modlib.office', 'lino_xl.lib.xl'])

Refugee statuses and former country

The demo database comes with 224 known countries, but some of them are not real countries because they actually represent for example a refugee status or a former country.

Lino knows them because their actual_country field points to another (the “real”) country.

>>> countries.Country.objects.all().count()
224
>>> countries.Country.objects.filter(actual_country__isnull=True).count()
220
>>> countries.Country.objects.filter(actual_country__isnull=False).count()
4
>>> rt.show(countries.Countries,
...     filter=Q(actual_country__isnull=False),
...     column_names="isocode name inscode actual_country actual_country__isocode")
========== ============================================ ========== ================ ==========
 ISO-Code   Bezeichnung                                  INS code   Actual country   ISO-Code
---------- -------------------------------------------- ---------- ---------------- ----------
 BYAA       Byelorussian SSR Soviet Socialist Republic              Belarus          BY
 DDDE       German Democratic Republic                   170        Deutschland      DE
 DEDE       German Federal Republic                      103        Deutschland      DE
 SUHH       USSR, Union of Soviet Socialist Republics               Russland         RU
========== ============================================ ========== ================ ==========

The following database fields refer to a country:

>>> for m, f in rt.models.countries.Country._lino_ddh.fklist:
...     print ("{} {}".format(dd.full_model_name(m), f.name))
addresses.Address country
contacts.Partner country
countries.Country actual_country
countries.Place country
cv.Experience country
cv.Study country
cv.Training country
pcsw.Client birth_country
pcsw.Client nationality
>>> kw = dict()
>>> fields = 'count rows'
>>> demo_get(
...    'rolf', 'choices/addresses/Address/country', fields, 220, **kw)
>>> demo_get(
...    'rolf', 'choices/contacts/Partners/country', fields, 220, **kw)
>>> demo_get(
...    'rolf', 'choices/pcsw/Clients/country', fields, 220, **kw)
>>> demo_get(
...    'rolf', 'choices/countries/Countries/actual_country', fields, 220, **kw)
>>> demo_get(
...    'rolf', 'choices/cv/Training/country', fields, 220, **kw)

The following fields have the full list, including fake countries)

>>> demo_get(
...    'rolf', 'choices/pcsw/Clients/nationality', fields, 224, **kw)
>>> demo_get(
...    'rolf', 'choices/countries/Places/country', fields, 224, **kw)