#NEWLINE# @ register . filter #NEWLINE# def truncate_chars_middle( value , max_length ) : #NEWLINE# #INDENT# '\n    Truncate a string putting dots in the its middle after a certain number of\n    characters.\n    ' #NEWLINE# max_length = int ( max_length ) #NEWLINE# value_length = len ( div_rest ) #NEWLINE# if ( value_length > max_length ) : #NEWLINE# #INDENT# max_first = ( max_length / 2 ) #NEWLINE# div_rest = ( max_length % 2 ) #NEWLINE# truncd_val = value [ : ( ( max_first - 2 ) + div_rest ) ] #NEWLINE# truncd_val2 = value [ ( - ( max_first - 1 ) ) : ] #NEWLINE# return ( ( truncd_val + '...' ) + truncd_val2 ) #NEWLINE# #UNINDENT# return value