Fix for changes in modern django-reversion

We have to upgrade django-reversion to 1.8 due to upgrading Django, but
unfortunately in that same version the author has removed the type field
on Version model, without a particularly good explanation as to why. This
is really annoying as we were using it to provide a reasonable audit
including for deletes. I suspect we'll need to move away from
django-reversion and do our own thing in future, but for now at least
allow the layer index to keep working.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2016-06-07 15:41:59 +12:00
parent 82c632ca2d
commit 2227102973

View File

@ -630,29 +630,30 @@ def annotate_revision(sender, **kwargs):
for ver, inst in zip(versions, instances):
currentVersion = ver.field_dict
modelmeta = ver.content_type.model_class()._meta
if ver.type == reversion.models.VERSION_DELETE:
changelist.append("Deleted %s: %s" % (modelmeta.verbose_name.lower(), ver.object_repr))
#FIXME modern django-reversion dropped the type field (argh!)
#if ver.type == reversion.models.VERSION_DELETE:
# changelist.append("Deleted %s: %s" % (modelmeta.verbose_name.lower(), ver.object_repr))
#else:
pastver = reversion.get_for_object(inst)
if pastver:# and ver.type != reversion.models.VERSION_ADD:
pastVersion = pastver[0].field_dict
changes = set(currentVersion.items()) - set(pastVersion.items())
changedVars = [var[0] for var in changes]
fieldchanges = []
for field in changedVars:
if field not in ignorefields:
modelfield = modelmeta.get_field(field)
newvalue = currentVersion[field]
if modelfield.choices:
for v in modelfield.choices:
if v[0] == newvalue:
newvalue = v[1]
break
fieldchanges.append("%s to '%s'" % (modelfield.verbose_name.lower(), newvalue))
if fieldchanges:
changelist.append("Changed %s %s %s" % (modelmeta.verbose_name.lower(), ver.object_repr, ", ".join(fieldchanges)))
else:
pastver = reversion.get_for_object(inst)
if pastver and ver.type != reversion.models.VERSION_ADD:
pastVersion = pastver[0].field_dict
changes = set(currentVersion.items()) - set(pastVersion.items())
changedVars = [var[0] for var in changes]
fieldchanges = []
for field in changedVars:
if field not in ignorefields:
modelfield = modelmeta.get_field(field)
newvalue = currentVersion[field]
if modelfield.choices:
for v in modelfield.choices:
if v[0] == newvalue:
newvalue = v[1]
break
fieldchanges.append("%s to '%s'" % (modelfield.verbose_name.lower(), newvalue))
if fieldchanges:
changelist.append("Changed %s %s %s" % (modelmeta.verbose_name.lower(), ver.object_repr, ", ".join(fieldchanges)))
else:
changelist.append("Added %s: %s" % (modelmeta.verbose_name.lower(), ver.object_repr))
changelist.append("Added %s: %s" % (modelmeta.verbose_name.lower(), ver.object_repr))
comment = '\n'.join(changelist)
if not comment:
comment = 'No changes'