Property for easy FormattedMapping access

This commit is contained in:
Adrian Sampson 2014-05-06 11:49:32 -07:00
parent e800b46a5d
commit c08e07d31b
2 changed files with 9 additions and 3 deletions

View file

@ -393,6 +393,12 @@ class Model(object):
"""
return FormattedMapping(self, for_path)
@property
def formatted(self):
"""A `dict`-like view containing formatted values.
"""
return self._formatted_mapping(False)
def evaluate_template(self, template, for_path=False):
"""Evaluate a template (a string or a `Template` object) using
the object's fields. If `for_path` is true, then no new path

View file

@ -576,8 +576,8 @@ def _field_diff(field, old, new):
return None
# Get formatted values for output.
oldstr = old._get_formatted(field)
newstr = new._get_formatted(field)
oldstr = old.formatted.get(field, u'')
newstr = new.formatted.get(field, u'')
# For strings, highlight changes. For others, colorize the whole
# thing.
@ -617,7 +617,7 @@ def show_model_changes(new, old=None, fields=None, always=False):
for field in set(new) - set(old):
changes.append(u' {0}: {1}'.format(
field,
colorize('red', new._get_formatted(field))
colorize('red', new.formatted[field])
))
# Print changes.