From 703711ad5058038652f6a5705b7b4ff01de93d3d Mon Sep 17 00:00:00 2001 From: Thomas Willems Date: Fri, 13 Dec 2019 10:55:30 +0100 Subject: [PATCH 1/4] add option to ignore not registered models --- reversion_compare/compare.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/reversion_compare/compare.py b/reversion_compare/compare.py index 12c3cda..fdf97c1 100644 --- a/reversion_compare/compare.py +++ b/reversion_compare/compare.py @@ -16,6 +16,7 @@ from django.db import models from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.translation import ugettext as _ +from reversion import RegistrationError from reversion.models import Version from reversion.revisions import _get_options @@ -45,6 +46,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: @@ -202,8 +205,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 From de291cc094f8eebf504b68364ec7c7abaf085df9 Mon Sep 17 00:00:00 2001 From: Jens Diemer Date: Mon, 6 Jan 2020 10:50:09 +0100 Subject: [PATCH 2/4] Update README.creole https://github.com/jedie/django-reversion-compare/pull/114 https://github.com/jedie/django-reversion-compare/issues/103 --- README.creole | 1 + 1 file changed, 1 insertion(+) diff --git a/README.creole b/README.creole index 83a2589..56a3081 100644 --- a/README.creole +++ b/README.creole @@ -261,6 +261,7 @@ 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]] +** Add new optinal 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 From eca2fcb659937dafcd9ed676543851856c0300f2 Mon Sep 17 00:00:00 2001 From: Jens Diemer Date: Mon, 6 Jan 2020 10:50:09 +0100 Subject: [PATCH 3/4] Update README.creole and AUTHORS https://github.com/jedie/django-reversion-compare/pull/114 https://github.com/jedie/django-reversion-compare/issues/103 --- AUTHORS | 2 ++ README.creole | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/AUTHORS b/AUTHORS index 00f34d5..0aed2fa 100644 --- a/AUTHORS +++ b/AUTHORS @@ -62,3 +62,5 @@ CONTRIBUTORS are and/or have been (alphabetic order): Github: * Wickström, Frank Github: +* Willemsm, Thomas + Github: diff --git a/README.creole b/README.creole index 83a2589..69b3249 100644 --- a/README.creole +++ b/README.creole @@ -39,6 +39,10 @@ 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 === @@ -261,6 +265,7 @@ 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]] +** Add new optinal 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 From 04f0e0848c474fe587f39e195ab110c1800f80ab Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Mon, 6 Jan 2020 10:56:51 +0100 Subject: [PATCH 4/4] release v0.8.7 --- README.creole | 7 ++++--- reversion_compare/__init__.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.creole b/README.creole index 69b3249..ad1d30c 100644 --- a/README.creole +++ b/README.creole @@ -264,11 +264,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]] -** Add new optinal settings {{{REVERSION_COMPARE_IGNORE_NOT_REGISTERED}}}, see: [[https://github.com/jedie/django-reversion-compare/issues/103|issues #103]] +* *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 diff --git a/reversion_compare/__init__.py b/reversion_compare/__init__.py index ea1224d..a868f10 100644 --- a/reversion_compare/__init__.py +++ b/reversion_compare/__init__.py @@ -1,3 +1,3 @@ # coding: utf-8 -__version__ = "0.8.6" +__version__ = "0.8.7"