#NEWLINE# def addon_to_dict( addon , disco = False , src = 'api' ) : #NEWLINE# #INDENT# '\n    Renders an addon in JSON for the API.\n    ' #NEWLINE# def url( u , **kwargs ) : #NEWLINE# #INDENT# return ( settings . SITE_URL + urlparams ( u , ** kwargs ) ) #NEWLINE# #UNINDENT# v = addon . current_version #NEWLINE# if disco : #NEWLINE# #INDENT# learnmore = ( settings . SERVICES_URL + reverse ( 'discovery.addons.detail' , args = [ addon . slug ] ) ) #NEWLINE# learnmore = urlparams ( learnmore , src = 'discovery-personalrec' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# learnmore = url ( addon . get_url_path ( ) , src = src ) #NEWLINE# #UNINDENT# d = { #NEWLINE# #INDENT# 'id' : addon . id , #NEWLINE# 'name' : ( unicode ( addon . name ) if addon . name else None ) , #NEWLINE# 'guid' : addon . guid , #NEWLINE# 'status' : amo . STATUS_CHOICES_API [ addon . status ] , #NEWLINE# 'type' : amo . ADDON_SLUGS_UPDATE [ addon . type ] , #NEWLINE# 'authors' : [ { #NEWLINE# #INDENT# 'id' : a . id , #NEWLINE# 'name' : unicode ( a . name ) , #NEWLINE# 'link' : absolutify ( a . get_url_path ( src = src ) ) , #NEWLINE# #UNINDENT# } for a in addon . listed_authors ] , #NEWLINE# 'summary' : ( strip_tags ( unicode ( addon . summary ) ) if addon . summary else None ) , #NEWLINE# 'description' : strip_tags ( unicode ( addon . description ) ) , #NEWLINE# 'icon' : addon . icon_url , #NEWLINE# 'learnmore' : learnmore , #NEWLINE# 'reviews' : url ( addon . reviews_url ) , #NEWLINE# 'total_dls' : addon . total_downloads , #NEWLINE# 'weekly_dls' : addon . weekly_downloads , #NEWLINE# 'adu' : addon . average_daily_users , #NEWLINE# 'created' : epoch ( addon . created ) , #NEWLINE# 'last_updated' : epoch ( addon . last_updated ) , #NEWLINE# 'homepage' : ( unicode ( addon . homepage ) if addon . homepage else None ) , #NEWLINE# 'support' : ( unicode ( addon . support_url ) if addon . support_url else None ) , #NEWLINE# #UNINDENT# } #NEWLINE# if addon . is_persona ( ) : #NEWLINE# #INDENT# d [ 'theme' ] = addon . persona . theme_data #NEWLINE# #UNINDENT# if v : #NEWLINE# #INDENT# d [ 'version' ] = v . version #NEWLINE# d [ 'platforms' ] = [ unicode ( a . name ) for a in v . supported_platforms ] #NEWLINE# d [ 'compatible_apps' ] = v . compatible_apps . values ( ) #NEWLINE# #UNINDENT# if addon . eula : #NEWLINE# #INDENT# d [ 'eula' ] = unicode ( addon . eula ) #NEWLINE# #UNINDENT# if addon . developer_comments : #NEWLINE# #INDENT# d [ 'dev_comments' ] = unicode ( addon . developer_comments ) #NEWLINE# #UNINDENT# if addon . takes_contributions : #NEWLINE# #INDENT# contribution = { #NEWLINE# #INDENT# 'link' : url ( addon . contribution_url , src = src ) , #NEWLINE# 'meet_developers' : url ( addon . meet_the_dev_url ( ) , src = src ) , #NEWLINE# 'suggested_amount' : addon . suggested_amount , #NEWLINE# #UNINDENT# } #NEWLINE# d [ 'contribution' ] = contribution #NEWLINE# #UNINDENT# if ( addon . type == amo . ADDON_PERSONA ) : #NEWLINE# #INDENT# d [ 'previews' ] = [ addon . persona . preview_url ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# d [ 'previews' ] = [ p . as_dict ( src = src ) for p in addon . all_previews ] #NEWLINE# #UNINDENT# return d