template: Nicer formatting of account split lines.
This provides nicer output when the whole line can fit in the desired width, even if the account name or amount are unusually long.
This commit is contained in:
		
							parent
							
								
									93fffe6666
								
							
						
					
					
						commit
						9d9254b69a
					
				
					 1 changed files with 10 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -88,6 +88,10 @@ class AmountTokenTransformer(TokenTransformer):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class AccountSplitter:
 | 
			
		||||
    TARGET_LINE_LEN = 78
 | 
			
		||||
    # -4 because that's how many spaces prefix an account line.
 | 
			
		||||
    TARGET_ACCTLINE_LEN = TARGET_LINE_LEN - 4
 | 
			
		||||
 | 
			
		||||
    def __init__(self, signed_currencies, signed_currency_fmt, unsigned_currency_fmt,
 | 
			
		||||
                 template_name):
 | 
			
		||||
        self.splits = collections.OrderedDict()
 | 
			
		||||
| 
						 | 
				
			
			@ -158,12 +162,13 @@ class AccountSplitter:
 | 
			
		|||
            if amount == 0:
 | 
			
		||||
                yield ''
 | 
			
		||||
            else:
 | 
			
		||||
                account_s = '    {:45}  {:>19}\n'.format(
 | 
			
		||||
                    account.format_map(template_vars),
 | 
			
		||||
                    babel.numbers.format_currency(amount, template_vars['currency'], amt_fmt),
 | 
			
		||||
                account_s = account.format_map(template_vars)
 | 
			
		||||
                amount_s = babel.numbers.format_currency(amount, template_vars['currency'], amt_fmt)
 | 
			
		||||
                sep_len = max(2, self.TARGET_ACCTLINE_LEN - len(account_s) - len(amount_s))
 | 
			
		||||
                yield '    {}{}{}\n{}'.format(
 | 
			
		||||
                    account_s, ' ' * sep_len, amount_s,
 | 
			
		||||
                    metadata.format_map(template_vars),
 | 
			
		||||
                )
 | 
			
		||||
                metadata_s = metadata.format_map(template_vars)
 | 
			
		||||
                yield account_s + metadata_s
 | 
			
		||||
 | 
			
		||||
    def render_next(self, template_vars):
 | 
			
		||||
        if template_vars is not self._last_template_vars:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue