improve decimal field: use pattern, show right-aligned
This commit is contained in:
		
							parent
							
								
									6e7219bdce
								
							
						
					
					
						commit
						b1cb9456fa
					
				
					 1 changed files with 5 additions and 3 deletions
				
			
		| 
						 | 
					@ -41,7 +41,9 @@ class TextField(Field):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DecimalField(Field):
 | 
					class DecimalField(Field):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    format = '###,###,##0.##'
 | 
					    format = 'decimal'
 | 
				
			||||||
 | 
					    pattern = u'#,##0.00;-#,##0.00'
 | 
				
			||||||
 | 
					    renderer = 'right'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getDisplayValue(self, row):
 | 
					    def getDisplayValue(self, row):
 | 
				
			||||||
        value = self.getRawValue(row)
 | 
					        value = self.getRawValue(row)
 | 
				
			||||||
| 
						 | 
					@ -53,8 +55,8 @@ class DecimalField(Field):
 | 
				
			||||||
        langInfo = nv and getattr(nv, 'languageInfo', None) or None
 | 
					        langInfo = nv and getattr(nv, 'languageInfo', None) or None
 | 
				
			||||||
        if langInfo:
 | 
					        if langInfo:
 | 
				
			||||||
            locale = locales.getLocale(langInfo.language)
 | 
					            locale = locales.getLocale(langInfo.language)
 | 
				
			||||||
            fmt = locale.numbers.getFormatter('decimal')
 | 
					            fmt = locale.numbers.getFormatter(self.format)
 | 
				
			||||||
            return fmt.format(value)
 | 
					            return fmt.format(value, pattern=self.pattern)
 | 
				
			||||||
        return '%.2f' % value
 | 
					        return '%.2f' % value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue