Skip to content

Commit

Permalink
Merge branch 'master' into django-3.0-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-engel committed Jan 9, 2020
2 parents 40785fd + 0c10b4c commit 294656e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ CONTRIBUTORS are and/or have been (alphabetic order):
Github: <https://github.com/w4rri0r3k>
* Wickström, Frank
Github: <https://github.com/frwickst>
* Willemsm, Thomas
Github: <https://github.com/willtho89>
9 changes: 7 additions & 2 deletions README.creole
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ INSTALLED_APPS = (
# Add reversion models to admin interface:
ADD_REVERSION_ADMIN=True
# optional settings:
REVERSION_COMPARE_FOREIGN_OBJECTS_AS_ID=False
REVERSION_COMPARE_IGNORE_NOT_REGISTERED=False
}}}

=== Usage ===
Expand Down Expand Up @@ -260,10 +263,12 @@ Maybe other versions are compatible, too.

== Changelog ==

* *dev* [[https://github.com/jedie/django-reversion-compare/compare/v0.8.6...master|compare v0.8.6...master]]
* *dev* [[https://github.com/jedie/django-reversion-compare/compare/v0.8.7...master|compare v0.8.7...master]]
** TBC
* v0.8.7 - 06.01.2020 [[https://github.com/jedie/django-reversion-compare/compare/v0.8.6...v0.8.7|compare v0.8.6...v0.8.7]]
** Add new optional settings {{{REVERSION_COMPARE_IGNORE_NOT_REGISTERED}}}, see: [[https://github.com/jedie/django-reversion-compare/issues/103|issues #103]]
** reformat code with 'black'
** some code cleanup
** TBC
* v0.8.6 - 04.01.2019 [[https://github.com/jedie/django-reversion-compare/compare/v0.8.5...v0.8.6|compare v0.8.5...v0.8.6]]
** Bugfix: [[https://github.com/jedie/django-reversion-compare/pull/110|Use ".pk" instead of ".id" when referring to related object.]] contributed by [[https://github.com/peterlisak|Peter Lisák]]
** Run tests: Skip Django v1.8 and add Python v3.7
Expand Down
2 changes: 1 addition & 1 deletion reversion_compare/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# coding: utf-8

__version__ = "0.8.6"
__version__ = "0.8.7"
13 changes: 11 additions & 2 deletions reversion_compare/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.db import models
from django.utils.encoding import force_text
from django.utils.translation import ugettext as _
from reversion import RegistrationError

from reversion.models import Version
from reversion.revisions import _get_options
Expand Down Expand Up @@ -44,6 +45,8 @@ def __init__(self, field, field_name, obj, version_record, follow):
self.follow = follow
# try and get a value, if none punt
self.compare_foreign_objects_as_id = getattr(settings, "REVERSION_COMPARE_FOREIGN_OBJECTS_AS_ID", False)
# ignore not registered models
self.ignore_not_registered = getattr(settings, "REVERSION_COMPARE_IGNORE_NOT_REGISTERED", False)
if self.compare_foreign_objects_as_id:
self.value = version_record.field_dict.get(getattr(field, "attname", field_name), DOES_NOT_EXIST)
else:
Expand Down Expand Up @@ -201,8 +204,14 @@ def get_many_to_something(self, target_ids, related_model, is_reverse=False):
if ver.revision.date_created < old_revision.date_created
}

# shift query to database
deleted = list(Version.objects.filter(revision=old_revision).get_deleted(related_model))
try:
# shift query to database
deleted = list(Version.objects.filter(revision=old_revision).get_deleted(related_model))
except RegistrationError as e:
if self.ignore_not_registered and "has not been registered with django-reversion" in e.__str__():
deleted = []
else:
raise e

return versions, missing_objects_dict, deleted

Expand Down

0 comments on commit 294656e

Please sign in to comment.