cities_light.contrib

For django-ajax-selects

Couples cities_light and django-ajax-selects.

Register the lookups in settings.AJAX_LOOKUP_CHANNELS, add:

'cities_light_country': ('cities_light.lookups', 'CountryLookup'),
'cities_light_city': ('cities_light.lookups', 'CityLookup'),
class cities_light.contrib.ajax_selects_lookups.CityLookup[source]

Lookup channel for City, hits name and search_names.

model

alias of City

class cities_light.contrib.ajax_selects_lookups.CountryLookup[source]

Lookup channel for Country, hits name and name_ascii.

model

alias of Country

class cities_light.contrib.ajax_selects_lookups.RegionLookup[source]

Lookup channel for Region, hits name and name_ascii.

model

alias of Region

class cities_light.contrib.ajax_selects_lookups.StandardLookupChannel[source]

Honnestly I’m not sure why this is here.

format_item_display(obj)[source]

(HTML) formatted item for displaying item in the selected deck area

format_match(obj)[source]

(HTML) formatted item for displaying item in the dropdown

For djangorestframework

The contrib contains support for v1, v2 and v3 of django restframework.

Django REST framework 3

This contrib package defines list and detail endpoints for City, Region and Country. If rest_framework (v3) is installed, all you have to do is add this url include:

url(r'^cities_light/api/', include('cities_light.contrib.restframework3')),

This will configure six endpoints:

^cities/$ [name='cities-light-api-city-list']
^cities/(?P<pk>[^/]+)/$ [name='cities-light-api-city-detail']
^countries/$ [name='cities-light-api-country-list']
^countries/(?P<pk>[^/]+)/$ [name='cities-light-api-country-detail']
^regions/$ [name='cities-light-api-region-list']
^regions/(?P<pk>[^/]+)/$ [name='cities-light-api-region-detail']
All list endpoints support search with a query parameter q::
/cities/?q=london

For Region and Country endpoints, the search will be within name_ascii field while for City it will search in search_names field. HyperlinkedModelSerializer is used for these models and therefore every response object contains url to self field and urls for related models. You can configure pagination using the standard rest_framework pagination settings in your project settings.py.

Couple djangorestframework and cities_light.

It defines a urlpatterns variables, with the following urls:

  • cities-light-api-city-list
  • cities-light-api-city-detail
  • cities-light-api-region-list
  • cities-light-api-region-detail
  • cities-light-api-country-list
  • cities-light-api-country-detail

If rest_framework (v3) is installed, all you have to do is add this url include:

url(r'^cities_light/api/', include('cities_light.contrib.restframework3')),

And that’s all !

Ideas for contributions

  • templatetag to render a city’s map using some external service
  • flag images, maybe with django-countryflags
  • currencies
  • generate po files when parsing alternate names