<s> from rest_framework . renderers import JSONRenderer <EOL> from django . conf import settings <EOL> from wq . db . default_settings import SRID as DEFAULT_SRID <EOL> class JSONRenderer ( JSONRenderer ) : <EOL> def render ( self , data , accepted_media_type = None , renderer_context = None ) : <EOL> if renderer_context and '<STR_LIT>' in renderer_context : <EOL> if not renderer_context [ '<STR_LIT>' ] . is_ajax ( ) : <EOL> renderer_context [ '<STR_LIT>' ] = <NUM_LIT:4> <EOL> return super ( JSONRenderer , self ) . render ( <EOL> data , accepted_media_type , renderer_context <EOL> ) <EOL> class GeoJSONRenderer ( JSONRenderer ) : <EOL> media_type = '<STR_LIT>' <EOL> format = '<STR_LIT>' <EOL> def render ( self , data , * args , ** kwargs ) : <EOL> if isinstance ( data , list ) : <EOL> features , simple = self . render_features ( data ) <EOL> data = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : features <EOL> } <EOL> elif "<STR_LIT:list>" in data and isinstance ( data [ '<STR_LIT:list>' ] , list ) : <EOL> features , simple = self . render_features ( data [ '<STR_LIT:list>' ] ) <EOL> data [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> data [ '<STR_LIT>' ] = features <EOL> del data [ '<STR_LIT:list>' ] <EOL> else : <EOL> data , simple = self . render_feature ( data ) <EOL> if not simple and getattr ( settings , '<STR_LIT>' , None ) != DEFAULT_SRID : <EOL> data [ '<STR_LIT>' ] = { <EOL> '<STR_LIT:type>' : '<STR_LIT:name>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' % settings . SRID <EOL> } <EOL> } <EOL> return super ( GeoJSONRenderer , self ) . render ( data , * args , ** kwargs ) <EOL> def render_feature ( self , obj ) : <EOL> feature = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : obj <EOL> } <EOL> simple = False <EOL> if '<STR_LIT:id>' in obj : <EOL> feature [ '<STR_LIT:id>' ] = obj [ '<STR_LIT:id>' ] <EOL> del obj [ '<STR_LIT:id>' ] <EOL> if '<STR_LIT>' in obj and '<STR_LIT>' in obj : <EOL> feature [ '<STR_LIT>' ] = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ obj [ '<STR_LIT>' ] , obj [ '<STR_LIT>' ] ] <EOL> } <EOL> del obj [ '<STR_LIT>' ] <EOL> del obj [ '<STR_LIT>' ] <EOL> simple = True <EOL> else : <EOL> for key , val in obj . items ( ) : <EOL> if isinstance ( val , dict ) and '<STR_LIT:type>' in val : <EOL> feature [ '<STR_LIT>' ] = val <EOL> del obj [ key ] <EOL> if '<STR_LIT>' in obj : <EOL> feature [ '<STR_LIT>' ] = obj [ '<STR_LIT>' ] <EOL> feature [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> del obj [ '<STR_LIT>' ] <EOL> return feature , simple <EOL> def render_features ( self , objs ) : <EOL> features = [ ] <EOL> has_simple = False <EOL> for obj in objs : <EOL> feature , simple = self . render_feature ( obj ) <EOL> if simple : <EOL> has_simple = True <EOL> if feature [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] is not None : <EOL> features . append ( feature ) <EOL> else : <EOL> features . append ( feature ) <EOL> return features , has_simple </s>
