<s> from django import VERSION as DJANGO_VERSION <EOL> from django . conf . urls . defaults import * <EOL> from django . conf . urls import patterns <EOL> from django . contrib import admin <EOL> from django . views . generic import ListView <EOL> from cities . models import Country , Region , City , District , PostalCode <EOL> class PlaceListView ( ListView ) : <EOL> template_name = "<STR_LIT>" <EOL> def get_queryset ( self ) : <EOL> if not self . args or not self . args [ <NUM_LIT:0> ] : <EOL> self . place = None <EOL> return Country . objects . all ( ) <EOL> args = self . args [ <NUM_LIT:0> ] . split ( "<STR_LIT:/>" ) <EOL> country = Country . objects . get ( slug = args [ <NUM_LIT:0> ] ) <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> self . place = country <EOL> return Region . objects . filter ( country = country ) . order_by ( '<STR_LIT:name>' ) <EOL> region = Region . objects . get ( country = country , slug = args [ <NUM_LIT:1> ] ) <EOL> if len ( args ) == <NUM_LIT:2> : <EOL> self . place = region <EOL> return City . objects . filter ( region = region ) . order_by ( '<STR_LIT:name>' ) <EOL> city = City . objects . get ( region = region , slug = args [ <NUM_LIT:2> ] ) <EOL> self . place = city <EOL> return District . objects . filter ( city = city ) . order_by ( '<STR_LIT:name>' ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( PlaceListView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . place <EOL> if hasattr ( self . place , '<STR_LIT:location>' ) : <EOL> context [ '<STR_LIT>' ] = City . objects . distance ( self . place . location ) . exclude ( id = self . place . id ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:10> ] <EOL> context [ '<STR_LIT>' ] = PostalCode . objects . distance ( self . place . location ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:10> ] <EOL> return context <EOL> admin . autodiscover ( ) <EOL> if DJANGO_VERSION < ( <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT:0> ) : <EOL> urlpatterns = patterns ( <EOL> '<STR_LIT>' , <EOL> ( r'<STR_LIT>' , include ( admin . site . urls ) ) , <EOL> ( r'<STR_LIT>' , PlaceListView . as_view ( ) ) , <EOL> ) <EOL> else : <EOL> urlpatterns = [ <EOL> ( r'<STR_LIT>' , include ( admin . site . urls ) ) , <EOL> ( r'<STR_LIT>' , PlaceListView . as_view ( ) ) , <EOL> ] </s>
