show_model_changes: special display for new fields

c.f. #560
This commit is contained in:
Adrian Sampson 2014-03-01 09:57:53 -08:00
parent ecace62e14
commit 057ff66ad6

View file

@ -599,9 +599,9 @@ def show_model_changes(new, old=None, fields=None, always=False):
"""
old = old or new._db._get(type(new), new.id)
# Build up lines showing changed or new fields.
# Build up lines showing changed fields.
changes = []
for field in old.keys() + list(set(new.keys()) - set(old.keys())):
for field in old:
# Subset of the fields. Never show mtime.
if field == 'mtime' or (fields and field not in fields):
continue
@ -611,6 +611,13 @@ def show_model_changes(new, old=None, fields=None, always=False):
if line:
changes.append(u' {0}: {1}'.format(field, line))
# New fields.
for field in set(new) - set(old):
changes.append(u' {0}: {1}'.format(
field,
colorize('red', new._get_formatted(field))
))
# Print changes.
if changes or always:
print_obj(old, old._db)