mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix ratings in save to disk templates not being divided by 2
This commit is contained in:
commit
b905ae569e
@ -563,8 +563,12 @@ class Metadata(object):
|
|||||||
def format_tags(self):
|
def format_tags(self):
|
||||||
return u', '.join([unicode(t) for t in sorted(self.tags, key=sort_key)])
|
return u', '.join([unicode(t) for t in sorted(self.tags, key=sort_key)])
|
||||||
|
|
||||||
def format_rating(self):
|
def format_rating(self, v=None, divide_by=1.0):
|
||||||
return unicode(self.rating)
|
if v is None:
|
||||||
|
if self.rating is not None:
|
||||||
|
return unicode(self.rating/divide_by)
|
||||||
|
return u'None'
|
||||||
|
return unicode(v/divide_by)
|
||||||
|
|
||||||
def format_field(self, key, series_with_index=True):
|
def format_field(self, key, series_with_index=True):
|
||||||
'''
|
'''
|
||||||
|
@ -189,7 +189,7 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250,
|
|||||||
else:
|
else:
|
||||||
template = re.sub(r'\{series_index[^}]*?\}', '', template)
|
template = re.sub(r'\{series_index[^}]*?\}', '', template)
|
||||||
if mi.rating is not None:
|
if mi.rating is not None:
|
||||||
format_args['rating'] = mi.format_rating()
|
format_args['rating'] = mi.format_rating(divide_by=2.0)
|
||||||
if hasattr(mi.timestamp, 'timetuple'):
|
if hasattr(mi.timestamp, 'timetuple'):
|
||||||
format_args['timestamp'] = strftime(timefmt, mi.timestamp.timetuple())
|
format_args['timestamp'] = strftime(timefmt, mi.timestamp.timetuple())
|
||||||
if hasattr(mi.pubdate, 'timetuple'):
|
if hasattr(mi.pubdate, 'timetuple'):
|
||||||
@ -211,6 +211,9 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250,
|
|||||||
format_args[key] = strftime(timefmt, format_args[key].timetuple())
|
format_args[key] = strftime(timefmt, format_args[key].timetuple())
|
||||||
elif cm['datatype'] == 'bool':
|
elif cm['datatype'] == 'bool':
|
||||||
format_args[key] = _('yes') if format_args[key] else _('no')
|
format_args[key] = _('yes') if format_args[key] else _('no')
|
||||||
|
elif cm['datatype'] == 'rating':
|
||||||
|
format_args[key] = mi.format_rating(format_args[key],
|
||||||
|
divide_by=2.0)
|
||||||
elif cm['datatype'] in ['int', 'float']:
|
elif cm['datatype'] in ['int', 'float']:
|
||||||
if format_args[key] != 0:
|
if format_args[key] != 0:
|
||||||
format_args[key] = unicode(format_args[key])
|
format_args[key] = unicode(format_args[key])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user