Coverage for lino/modlib/countries/models.py : 68%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: UTF-8 -*- # Copyright 2008-2016 Luc Saffre # License: BSD (see file COPYING for details)
.. autosummary::
"""
"""A list of frequent countries used by some demo fixtures."""
"""A "country" or "nation". """
max_length=4, primary_key=True, verbose_name=_("ISO code"), help_text=_("""\ The two-letter code for this country as defined by ISO 3166-1. For countries that no longer exist it may be a 4-letter code.""")) #~ name = models.CharField(max_length=200) #~ name = d.BabelCharField(max_length=200,verbose_name=_("Designation"))
max_length=4, blank=True, verbose_name=_("Short code"), help_text=_("""A short abbreviation for regional usage. Obsolete."""))
max_length=3, blank=True, verbose_name=_("ISO-3 code"), help_text=_("The three-letter code for this country " "as defined by ISO 3166-1."))
cd = getattr(CountryDrivers, self.isocode, None) if cd is not None: return cd.region_types + cd.city_types return list(PlaceTypes.items())
def get_actual_countries(cls): return cls.objects.all()
"""The table of all countries."""
A country is a geographic entity considered a "nation". """) #~ label = _("Countries") isocode name short_code countries.PlacesByCountry """ isocode short_code name """
"""Any kind of named geographic region (except those who have an entry in :class:`Country`.
"""
'country', 'parent', 'name', 'type', 'zip_code')
# parent = models.ForeignKey( # 'self', # blank=True, null=True, # verbose_name=_("Part of"), # help_text=_("The superordinate geographic place " # "of which this place is a part."))
# def get_parents(self, *grandparents): # if self.parent_id: # return self.parent.get_parents(self, *grandparents) # return [self] + list(grandparents)
def type_choices(cls, country): if country is not None: allowed = country.allowed_city_types() return [(i, t) for i, t in PlaceTypes.choices if i in allowed] return PlaceTypes.choices
""" Extends the default behaviour (which would simply diplay this city in the current language) by also adding the name in other languages and the type between parentheses. """ names = [self.name] for lng in settings.SITE.BABEL_LANGS: n = getattr(self, 'name' + lng.suffix) if n and n not in names: names.append(n) #~ s += ' / ' + n if len(names) == 1: s = names[0] else: s = ' / '.join(names) # s = "%s (%s)" % (names[0], ', '.join(names[1:])) if True: # TODO: attribute per type? s += " (%s)" % str(self.type) return s
def get_cities(cls, country): if country is None: cd = None flt = models.Q() else: cd = getattr(CountryDrivers, country.isocode, None) flt = models.Q(country=country)
#~ types = [PlaceTypes.blank_item] 20120829 types = [None] if cd: types += cd.city_types #~ flt = flt & models.Q(type__in=cd.city_types) else: types += [v for v in list(PlaceTypes.items()) if v.value >= '50'] #~ flt = flt & models.Q(type__gte=PlaceTypes.get_by_value('50')) flt = flt & models.Q(type__in=types) #~ flt = flt | models.Q(type=PlaceTypes.blank_item) return cls.objects.filter(flt).order_by('name')
#~ if country is not None: #~ cd = getattr(CountryDrivers,country.isocode,None) #~ if cd: #~ return Place.objects.filter( #~ country=country, #~ type__in=cd.city_types).order_by('name') #~ return country.place_set.order_by('name') #~ return cls.city.field.rel.model.objects.order_by('name')
Place, 'parent', verbose_name=_("Part of"), help_text=_("The superordinate geographic place " "of which this place is a part."))
The table of known geographical places. A geographical place can be a city, a town, a suburb, a province, a lake... any named geographic entity, except for countries because these have their own table. """)
name country type parent zip_code id PlacesByPlace """
"""The name of a geographical place (:attr:`lino.modlib.countries.models.Place.name`) should not consist of only digits.
"""
if obj.name.isdigit(): yield (False, _("Name contains only digits."))
|