<s> import logging <EOL> from itertools import chain <EOL> import simplejson <EOL> from molly . geolocation . providers import BaseGeolocationProvider <EOL> from molly . apps . places . models import Entity , EntityName <EOL> logger = logging . getLogger ( __name__ ) <EOL> class PlacesGeolocationProvider ( BaseGeolocationProvider ) : <EOL> def __init__ ( self , search_identifiers = None ) : <EOL> self . search_identifiers = search_identifiers <EOL> def geocode ( self , query ) : <EOL> entities = Entity . objects . all ( ) <EOL> if self . search_identifiers : <EOL> entities = entities . filter ( <EOL> _identifiers__scheme__in = self . search_identifiers , <EOL> _identifiers__value__iexact = query , <EOL> location__isnull = False <EOL> ) <EOL> else : <EOL> entities = entities . filter ( <EOL> _identifiers__value__iexact = query , <EOL> location__isnull = False <EOL> ) <EOL> entities = chain ( <EOL> Entity . objects . filter ( names__title__iexact = query , <EOL> location__isnull = False ) , <EOL> entities , <EOL> ) <EOL> for entity in entities : <EOL> yield { <EOL> '<STR_LIT:name>' : entity . title , <EOL> '<STR_LIT:location>' : tuple ( entity . location ) , <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> } </s>
