#NEWLINE# @ dd . receiver ( dd . pre_analyze ) #NEWLINE# def set_upload_shortcuts( sender , **kw ) : #NEWLINE# #INDENT# 'This is the successor for `quick_upload_buttons`.' #NEWLINE# UploadType = kw . modules . uploads . UploadType #NEWLINE# for i in list ( Shortcuts . items ( ) ) : #NEWLINE# #INDENT# def f( obj , ar ) : #NEWLINE# #INDENT# if ( ( obj is None ) or ( ar is None ) ) : #NEWLINE# #INDENT# return E . div ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# utype = UploadType . objects . get ( shortcut = i ) #NEWLINE# #UNINDENT# except UploadType . DoesNotExist : #NEWLINE# #INDENT# return E . div ( ) #NEWLINE# #UNINDENT# items = [ ] #NEWLINE# target = sender . modules . resolve ( i . target ) #NEWLINE# sar = ar . spawn_request ( actor = target , master_instance = obj , known_values = dict ( type = utype ) ) #NEWLINE# n = sar . get_total_count ( ) #NEWLINE# if ( n == 0 ) : #NEWLINE# #INDENT# iar = target . insert_action . request_from ( sar , master_instance = obj ) #NEWLINE# btn = iar . ar2button ( None , _ ( 'Upload' ) , icon_name = 'page_add' , title = _ ( 'Upload a file from your PC to the server.' ) ) #NEWLINE# items . append ( btn ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( n == 1 ) : #NEWLINE# #INDENT# after_show = ar . get_status ( ) #NEWLINE# obj = sar . data_iterator [ 0 ] #NEWLINE# items . append ( sar . renderer . href_button ( dd . build_media_url ( obj . file . name ) , _ ( 'show' ) , target = '_blank' , icon_name = 'page_go' , style = 'vertical-align:-30%;' , title = _ ( 'Open the uploaded file in a new browser window' ) ) ) #NEWLINE# after_show . update ( record_id = obj . pk ) #NEWLINE# items . append ( sar . window_action_button ( sar . ah . actor . detail_action , after_show , _ ( 'Edit' ) , icon_name = 'application_form' , title = _ ( 'Edit metadata of the uploaded file.' ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# obj = sar . sliced_data_iterator [ 0 ] #NEWLINE# items . append ( ar . obj2html ( obj , pgettext ( 'uploaded file' , 'Last' ) ) ) #NEWLINE# btn = sar . renderer . action_button ( obj , sar , sar . bound_action , _ ( 'All {0} files' ) . format ( n ) , icon_name = None ) #NEWLINE# items . append ( btn ) #NEWLINE# #UNINDENT# #UNINDENT# return E . div ( * join_elems ( items , ', ' ) ) #NEWLINE# #UNINDENT# vf = dd . VirtualField ( dd . DisplayField ( i . text ) , f ) #NEWLINE# dd . inject_field ( i . model_spec , i . name , vf )