Allow customization of rendering version diff values

This commit is contained in:
Lance Edgar 2021-05-14 12:13:23 -05:00
parent 00615bea97
commit 949b9d64bf
2 changed files with 18 additions and 4 deletions

View file

@ -11,6 +11,10 @@
overflow: auto;
}
.versions-wrapper {
margin-left: 2rem;
}
</style>
</%def>
@ -45,6 +49,7 @@
</div><!-- form-wrapper -->
<div class="versions-wrapper">
% for version in versions:
<h2>${title_for_version(version)}</h2>
@ -62,7 +67,7 @@
% for field in fields_for_version(version):
<tr>
<td class="field">${field}</td>
<td class="value old-value">${repr(getattr(version.previous, field))}</td>
<td class="value old-value">${render_old_value(version, field)}</td>
<td class="value new-value">&nbsp;</td>
</tr>
% endfor
@ -81,8 +86,8 @@
% for field in fields_for_version(version):
<tr${' class="diff"' if getattr(version, field) != getattr(version.previous, field) else ''|n}>
<td class="field">${field}</td>
<td class="value old-value">${repr(getattr(version.previous, field))}</td>
<td class="value new-value">${repr(getattr(version, field))}</td>
<td class="value old-value">${render_old_value(version, field)}</td>
<td class="value new-value">${render_new_value(version, field, 'dirty')}</td>
</tr>
% endfor
</tbody>
@ -101,7 +106,7 @@
<tr>
<td class="field">${field}</td>
<td class="value old-value">&nbsp;</td>
<td class="value new-value">${repr(getattr(version, field))}</td>
<td class="value new-value">${render_new_value(version, field, 'new')}</td>
</tr>
% endfor
</tbody>
@ -109,6 +114,7 @@
% endif
% endfor
</div>
</%def>

View file

@ -1169,6 +1169,8 @@ class MasterView(View):
'title_for_version': self.title_for_version,
'fields_for_version': self.fields_for_version,
'continuum': continuum,
'render_old_value': self.render_version_old_field_value,
'render_new_value': self.render_version_new_field_value,
})
def title_for_version(self, version):
@ -1198,6 +1200,12 @@ class MasterView(View):
versions.extend(query.all())
return versions
def render_version_old_field_value(self, version, field):
return repr(getattr(version.previous, field))
def render_version_new_field_value(self, version, field, typ):
return repr(getattr(version, field))
def configure_common_form(self, form):
"""
Configure the form in whatever way is deemed "common" - i.e. where