#NEWLINE# @ get ( '/s/topics/{topic_id}/posts' ) #NEWLINE# def get_posts_route( request , topic_id ) : #NEWLINE# #INDENT# '\n    Get a reverse chronological listing of posts for given topic.\n    Includes topic meta data and posts (or proposals or votes).\n    Paginates.\n    ' #NEWLINE# db_conn = request [ 'db_conn' ] #NEWLINE# topic = Topic . get ( db_conn , id = topic_id ) #NEWLINE# if ( not topic ) : #NEWLINE# #INDENT# return ( 404 , { #NEWLINE# #INDENT# 'errors' : [ { #NEWLINE# #INDENT# 'name' : 'topic_id' , #NEWLINE# 'message' : c ( 'no_topic' ) , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'ref' : 'pgnNbqSP1VUWkOYq8MVGPrSS' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# entity_kind = topic [ 'entity' ] [ 'kind' ] #NEWLINE# entity = get_latest_accepted ( db_conn , entity_kind , topic [ 'entity' ] [ 'id' ] ) #NEWLINE# posts = get_posts_facade ( diffs , limit = ( request [ 'params' ] . get ( 'limit' ) or 10 ) , skip = ( request [ 'params' ] . get ( 'skip' ) or 0 ) , topic_id = topic_id ) #NEWLINE# diffs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# entity_versions = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for post_ in posts : #NEWLINE# #INDENT# if ( post_ [ 'kind' ] == 'proposal' ) : #NEWLINE# #INDENT# entity_version = entity_versions [ post_ [ 'id' ] ] = get_version ( db_conn , post_ [ 'entity_version' ] [ 'kind' ] , post_ [ 'entity_version' ] [ 'id' ] ) #NEWLINE# previous_version = get_version ( db_conn , post_ [ 'entity_version' ] [ 'kind' ] , entity_version [ 'previous_id' ] ) #NEWLINE# if previous_version : #NEWLINE# #INDENT# diffs [ post_ [ 'id' ] ] = object_diff ( previous_version . deliver ( ) , entity_version . deliver ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# users = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for post_ in posts : #NEWLINE# #INDENT# user_id = post_ [ 'user_id' ] #NEWLINE# if ( user_id not in users ) : #NEWLINE# #INDENT# user = User . get ( db_conn , id = user_id ) #NEWLINE# if user : #NEWLINE# #INDENT# users [ user_id ] = { #NEWLINE# #INDENT# 'name' : user [ 'name' ] , #NEWLINE# 'avatar' : user . get_avatar ( 48 ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# output = { #NEWLINE# #INDENT# 'topic' : topic . deliver ( ) , #NEWLINE# 'posts' : [ p . deliver ( ) for p in posts ] , #NEWLINE# 'entity_versions' : { p : ev . deliver ( 'view' ) for ( p , ev ) in entity_versions . items ( ) } , #NEWLINE# 'users' : users , #NEWLINE# #UNINDENT# } #NEWLINE# if entity : #NEWLINE# #INDENT# output [ entity_kind ] = entity . deliver ( ) #NEWLINE# #UNINDENT# return ( 200 , output )