<s> """<STR_LIT>""" <EOL> from osgeo import ogr <EOL> from django import template <EOL> from geokey . categories . models import Field , LookupField , MultipleLookupField <EOL> register = template . Library ( ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def kml_geom ( place ) : <EOL> geometry = place . get ( '<STR_LIT:location>' ) . get ( '<STR_LIT>' ) <EOL> json_geom = ogr . CreateGeometryFromJson ( str ( geometry ) ) <EOL> kml_geom = json_geom . ExportToKML ( ) <EOL> return kml_geom <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def kml_name ( place ) : <EOL> name = '<STR_LIT>' <EOL> if place : <EOL> display_field = place . get ( '<STR_LIT>' ) <EOL> if display_field : <EOL> name = display_field . get ( '<STR_LIT:value>' ) <EOL> return name <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def kml_desc ( place ) : <EOL> properties = place . get ( '<STR_LIT>' ) <EOL> media = place . get ( '<STR_LIT>' ) <EOL> comments = place . get ( '<STR_LIT>' ) <EOL> description = '<STR_LIT>' <EOL> if properties : <EOL> description += '<STR_LIT>' <EOL> for key in properties : <EOL> name = key <EOL> value = properties [ key ] <EOL> try : <EOL> field = Field . objects . get ( <EOL> key = key , <EOL> category_id = place . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) . get ( '<STR_LIT:id>' ) <EOL> ) <EOL> name = field . name . encode ( '<STR_LIT:utf-8>' ) <EOL> if value is not None : <EOL> if isinstance ( field , LookupField ) : <EOL> value = field . lookupvalues . get ( pk = value ) . name <EOL> elif isinstance ( field , MultipleLookupField ) : <EOL> values = field . lookupvalues . filter ( <EOL> pk__in = value <EOL> ) <EOL> value = '<STR_LIT>' . join ( [ v . name for v in values ] ) <EOL> except Field . DoesNotExist : <EOL> pass <EOL> if type ( value ) in [ str , unicode ] : <EOL> value = value . encode ( '<STR_LIT:utf-8>' ) <EOL> if properties [ key ] is not None : <EOL> description = '<STR_LIT>' . format ( <EOL> desc = description , <EOL> name = name , <EOL> value = value <EOL> ) <EOL> description += '<STR_LIT>' <EOL> if media : <EOL> description += '<STR_LIT>' <EOL> for file in media : <EOL> if file [ '<STR_LIT>' ] == '<STR_LIT>' or file [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if file [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> file [ '<STR_LIT:url>' ] = file [ '<STR_LIT:url>' ] . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> description += '<STR_LIT>' . format ( <EOL> name = file [ '<STR_LIT:name>' ] , <EOL> desc = '<STR_LIT>' % file [ '<STR_LIT:description>' ] if file [ '<STR_LIT:description>' ] else '<STR_LIT>' , <EOL> url = file [ '<STR_LIT:url>' ] , <EOL> thumbnail_url = file [ '<STR_LIT>' ] <EOL> ) <EOL> elif file [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> description += '<STR_LIT>' . format ( <EOL> name = file [ '<STR_LIT:name>' ] , <EOL> desc = '<STR_LIT>' % file [ '<STR_LIT:description>' ] if file [ '<STR_LIT:description>' ] else '<STR_LIT>' , <EOL> url = file [ '<STR_LIT:url>' ] <EOL> ) <EOL> description += '<STR_LIT>' <EOL> if comments : <EOL> def render_comments ( comments ) : <EOL> description = '<STR_LIT>' <EOL> for comment in comments : <EOL> description += '<STR_LIT>' . format ( <EOL> name = comment [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> text = '<STR_LIT>' % comment [ '<STR_LIT:text>' ] if comment [ '<STR_LIT:text>' ] else '<STR_LIT>' <EOL> ) <EOL> if len ( comment [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> description += render_comments ( comment [ '<STR_LIT>' ] ) <EOL> description += '<STR_LIT>' <EOL> description += '<STR_LIT>' <EOL> return description <EOL> description += render_comments ( comments ) <EOL> description += '<STR_LIT>' <EOL> return description <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def kml_style ( place ) : <EOL> colour = place . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) <EOL> colour = colour . replace ( '<STR_LIT:#>' , '<STR_LIT>' ) <EOL> return colour </s>
