mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-10-31 02:27:01 -04:00 
			
		
		
		
	Content server: Make the book size useable in custom book list templates. Fixes #1846839 [Custom book list template doesn't work with {size}](https://bugs.launchpad.net/calibre/+bug/1846839)
This commit is contained in:
		
							parent
							
								
									a87c59e8c8
								
							
						
					
					
						commit
						e93a01aa3d
					
				| @ -24,7 +24,7 @@ from calibre.library.field_metadata import category_icon_map | |||||||
| from polyglot.builtins import iteritems, itervalues, range, filter, unicode_type | from polyglot.builtins import iteritems, itervalues, range, filter, unicode_type | ||||||
| from polyglot.urllib import quote | from polyglot.urllib import quote | ||||||
| 
 | 
 | ||||||
| IGNORED_FIELDS = frozenset('cover ondevice path marked au_map size'.split()) | IGNORED_FIELDS = frozenset('cover ondevice path marked au_map'.split()) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def encode_datetime(dateval): | def encode_datetime(dateval): | ||||||
|  | |||||||
| @ -135,6 +135,20 @@ def render_field(field, mi, book_id):  # {{{ | |||||||
|                 val = 1 |                 val = 1 | ||||||
|             return fmt_sidx(val, use_roman=interface_data.use_roman_numerals_for_series_number) |             return fmt_sidx(val, use_roman=interface_data.use_roman_numerals_for_series_number) | ||||||
| 
 | 
 | ||||||
|  |     def process_size(field, fm, name, val): | ||||||
|  |         val = val or 0 | ||||||
|  |         mb = 1024 * 1024 | ||||||
|  | 
 | ||||||
|  |         def fmt(val, suffix): | ||||||
|  |             ans = f'{val:.1f}' | ||||||
|  |             if ans.endsWith('.0'): | ||||||
|  |                 ans = ans[:-2] | ||||||
|  |             return ans + suffix | ||||||
|  | 
 | ||||||
|  |         if val < mb: | ||||||
|  |             return fmt(val / 1024, 'KB') | ||||||
|  |         return fmt(val / mb, 'MB') | ||||||
|  | 
 | ||||||
|     name = fm.name or field |     name = fm.name or field | ||||||
|     datatype = fm.datatype |     datatype = fm.datatype | ||||||
|     if field is 'comments' or datatype is 'comments': |     if field is 'comments' or datatype is 'comments': | ||||||
| @ -160,6 +174,8 @@ def render_field(field, mi, book_id):  # {{{ | |||||||
|         func = process_series |         func = process_series | ||||||
|     elif field.endswith('_index'): |     elif field.endswith('_index'): | ||||||
|         func = process_series_index |         func = process_series_index | ||||||
|  |     elif field is 'size': | ||||||
|  |         func = process_size | ||||||
|     ans = None |     ans = None | ||||||
|     if func: |     if func: | ||||||
|         ans = func(field, fm, name, val) |         ans = func(field, fm, name, val) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user