<s> from __future__ import absolute_import <EOL> from freight . models import App , Repository <EOL> from . base import Serializer <EOL> from . manager import add <EOL> @ add ( App ) <EOL> class AppSerializer ( Serializer ) : <EOL> def serialize ( self , item , attrs ) : <EOL> env_map = { } <EOL> for env , env_data in item . environments . iteritems ( ) : <EOL> env_map [ env ] = { <EOL> '<STR_LIT>' : env_data . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> if not env_map : <EOL> env_map [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if item . repository_id : <EOL> repo = Repository . query . filter ( Repository . id == item . repository_id ) . first ( ) . url <EOL> else : <EOL> repo = None <EOL> return { <EOL> '<STR_LIT:id>' : str ( item . id ) , <EOL> '<STR_LIT:name>' : item . name , <EOL> '<STR_LIT>' : env_map , <EOL> '<STR_LIT>' : repo , <EOL> } </s>
