commit python-django-reversion for openSUSE:Factory
Hello community, here is the log from the commit of package python-django-reversion for openSUSE:Factory checked in at 2018-07-21 10:25:26 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-django-reversion (Old) and /work/SRC/openSUSE:Factory/.python-django-reversion.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-django-reversion" Sat Jul 21 10:25:26 2018 rev:3 rq:624238 version:3.0.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-django-reversion/python-django-reversion.changes 2018-05-30 12:37:41.519634302 +0200 +++ /work/SRC/openSUSE:Factory/.python-django-reversion.new/python-django-reversion.changes 2018-07-21 10:25:26.614954237 +0200 @@ -1,0 +2,20 @@ +Fri Jul 20 10:00:17 UTC 2018 - 9+suse@cirno.systems + +- Update to version 3.0.0: + * Breaking: 'Revision.commment' now contains the raw JSON change + message generated by django admin, rather than a string. + Accesing 'Revision.comment' directly is no longer recommended. + Instead, use 'Revision.get_comment()'. + * Breaking: django-reversion now uses '_base_manager' to + calculate deleted models, not '_default_manager'. This change + will only affect models that perform default filtering in their + '_default_manager' + * Added 'request_creates_revision' hook to 'RevisionMiddleware' + and 'views.create_revision'. + * Added 'revision_request_creates_revision' hook to + 'views.RevisionMixinView'. + * Added '--meta' flag to './manage.py createrevisions' + * Fixed bug when reverting deleted nested inlines + * Added tests for django 2.1 + +------------------------------------------------------------------- Old: ---- django-reversion-2.0.13.tar.gz New: ---- django-reversion-3.0.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-django-reversion.spec ++++++ --- /var/tmp/diff_new_pack.84DZvh/_old 2018-07-21 10:25:27.030954136 +0200 +++ /var/tmp/diff_new_pack.84DZvh/_new 2018-07-21 10:25:27.030954136 +0200 @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-django-reversion -Version: 2.0.13 +Version: 3.0.0 Release: 0 Summary: A Django extension that provides version control for model instances License: BSD-3-Clause ++++++ django-reversion-2.0.13.tar.gz -> django-reversion-3.0.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/CHANGELOG.rst new/django-reversion-3.0.0/CHANGELOG.rst --- old/django-reversion-2.0.13/CHANGELOG.rst 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/CHANGELOG.rst 2018-07-19 13:22:54.000000000 +0200 @@ -3,7 +3,22 @@ django-reversion changelog ========================== -2.0.13 - 23/01/2017 +3.0.0 - 19/07/2018 +------------------ + +- **Breaking:** ``Revision.commment`` now contains the raw JSON change message generated by django admin, rather than + a string. Accesing ``Revision.comment`` directly is no longer recommended. Instead, use ``Revision.get_comment()``. + (@RamezIssac). +- **BREAKING:** django-reversion now uses ``_base_manager`` to calculate deleted models, not ``_default_manager``. This + change will only affect models that perform default filtering in their ``_default_manager`` (@ivissani). +- Added ``request_creates_revision`` hook to ``RevisionMiddleware`` and ``views.create_revision``. (@kklingenberg). +- Added ``revision_request_creates_revision`` hook to ``views.RevisionMixinView``. (@kklingenberg). +- Added ``--meta`` flag to ``./manage.py createrevisions`` (@massover). +- Fixed bug when reverting deleted nested inlines (Primož Kariž). +- Added tests for django 2.1 (@claudep). + + +2.0.13 - 23/01/2018 ------------------- - Improve performance of ``get_deleted()`` for Oracle (@passuf). @@ -161,7 +176,7 @@ class YourVersionAdmin(VersionAdmin): def reversion_register(self, model, **options): - options["ignore_duplicate_revisions"] = True + options["ignore_duplicates"] = True super(YourVersionAdmin, self).reversion_register(model, **options) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/PKG-INFO new/django-reversion-3.0.0/PKG-INFO --- old/django-reversion-2.0.13/PKG-INFO 2018-01-23 11:37:21.000000000 +0100 +++ new/django-reversion-3.0.0/PKG-INFO 2018-07-19 13:23:52.000000000 +0200 @@ -1,12 +1,11 @@ Metadata-Version: 1.1 Name: django-reversion -Version: 2.0.13 +Version: 3.0.0 Summary: An extension to the Django web framework that provides version control for model instances. Home-page: http://github.com/etianen/django-reversion Author: Dave Hall Author-email: dave@etianen.com License: BSD -Description-Content-Type: UNKNOWN Description: UNKNOWN Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable @@ -16,6 +15,6 @@ Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 -Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 Classifier: Framework :: Django diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/django_reversion.egg-info/PKG-INFO new/django-reversion-3.0.0/django_reversion.egg-info/PKG-INFO --- old/django-reversion-2.0.13/django_reversion.egg-info/PKG-INFO 2018-01-23 11:37:21.000000000 +0100 +++ new/django-reversion-3.0.0/django_reversion.egg-info/PKG-INFO 2018-07-19 13:23:52.000000000 +0200 @@ -1,12 +1,11 @@ Metadata-Version: 1.1 Name: django-reversion -Version: 2.0.13 +Version: 3.0.0 Summary: An extension to the Django web framework that provides version control for model instances. Home-page: http://github.com/etianen/django-reversion Author: Dave Hall Author-email: dave@etianen.com License: BSD -Description-Content-Type: UNKNOWN Description: UNKNOWN Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable @@ -16,6 +15,6 @@ Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 -Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 Classifier: Framework :: Django diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/django_reversion.egg-info/SOURCES.txt new/django-reversion-3.0.0/django_reversion.egg-info/SOURCES.txt --- old/django-reversion-2.0.13/django_reversion.egg-info/SOURCES.txt 2018-01-23 11:37:21.000000000 +0100 +++ new/django-reversion-3.0.0/django_reversion.egg-info/SOURCES.txt 2018-07-19 13:23:52.000000000 +0200 @@ -84,11 +84,7 @@ reversion/management/commands/__init__.py reversion/management/commands/createinitialrevisions.py reversion/management/commands/deleterevisions.py -reversion/migrations/0001_initial.py reversion/migrations/0001_squashed_0004_auto_20160611_1202.py -reversion/migrations/0002_auto_20141216_1509.py -reversion/migrations/0003_auto_20160601_1600.py -reversion/migrations/0004_auto_20160611_1202.py reversion/migrations/__init__.py reversion/templates/reversion/change_list.html reversion/templates/reversion/object_history.html diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/docs/admin.rst new/django-reversion-3.0.0/docs/admin.rst --- old/django-reversion-2.0.13/docs/admin.rst 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/docs/admin.rst 2018-07-19 13:22:54.000000000 +0200 @@ -106,4 +106,4 @@ The model that will be registered with django-reversion. ``options`` - Registeration options, see :ref:`reversion.register() <register>`. + Registration options, see :ref:`reversion.register() <register>`. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/docs/api.rst new/django-reversion-3.0.0/docs/api.rst --- old/django-reversion-2.0.13/docs/api.rst 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/docs/api.rst 2018-07-19 13:22:54.000000000 +0200 @@ -462,7 +462,7 @@ The ``User`` that created the revision, or None. -``Revision.comment`` +``Revision.get_comment()`` A text comment on the revision. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/docs/commands.rst new/django-reversion-3.0.0/docs/commands.rst --- old/django-reversion-2.0.13/docs/commands.rst 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/docs/commands.rst 2018-07-19 13:22:54.000000000 +0200 @@ -17,6 +17,7 @@ ./manage.py createinitialrevisions ./manage.py createinitialrevisions your_app.YourModel --comment="Initial revision." + ./manage.py createinitialrevisions your_app.YourModel --meta="{\"your_app.RevisionMeta\": {\"hello\": \"world\"}}" Run ``./manage.py createinitialrevisions --help`` for more information. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/docs/django-versions.rst new/django-reversion-3.0.0/docs/django-versions.rst --- old/django-reversion-2.0.13/docs/django-versions.rst 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/docs/django-versions.rst 2018-07-19 13:22:54.000000000 +0200 @@ -10,7 +10,7 @@ ============== ================= Django version Reversion release ============== ================= -1.8 - current 2.0.0 +1.8 - current 2.x 1.7 1.10.x 1.6 1.8.x ============== ================= diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/docs/middleware.rst new/django-reversion-3.0.0/docs/middleware.rst --- old/django-reversion-2.0.13/docs/middleware.rst 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/docs/middleware.rst 2018-07-19 13:22:54.000000000 +0200 @@ -9,14 +9,14 @@ reversion.middleware.RevisionMiddleware --------------------------------------- -Wrap the every request that isn't ``GET``, ``HEAD`` or ``OPTIONS`` in a revision block. +Wrap every request in a revision block. The request user will also be added to the revision metadata. To enable ``RevisionMiddleware``, add ``'reversion.middleware.RevisionMiddleware'`` to your ``MIDDLEWARE_CLASSES`` setting. For Django >= 1.10, add it to your ``MIDDLEWARE`` setting. .. Warning:: - This will wrap every request that isn't ``GET``, ``HEAD`` or ``OPTIONS`` in a database transaction. For best performance, consider marking individual views instead. + This will wrap every request that meets the specified criterion in a database transaction. For best performance, consider marking individual views instead. ``RevisionMiddleware.manage_manually = False`` @@ -32,3 +32,21 @@ ``RevisionMiddleware.atomic = True`` .. include:: /_include/create-revision-atomic.rst + +``RevisionMiddleware.request_creates_revision(request)`` + + By default, any request that isn't ``GET``, ``HEAD`` or ``OPTIONS`` will be wrapped in a revision block. Override this method if you need to apply a custom rule. + + For example: + + .. code:: python + + from reversion.middleware import RevisionMiddleware + + class BypassRevisionMiddleware(RevisionMiddleware): + + def request_creates_revision(self, request): + # Bypass the revision according to some header + silent = request.META.get("HTTP_X_NOREVISION", "false") + return super().request_creates_revision(request) and \ + silent != "true" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/docs/views.rst new/django-reversion-3.0.0/docs/views.rst --- old/django-reversion-2.0.13/docs/views.rst 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/docs/views.rst 2018-07-19 13:22:54.000000000 +0200 @@ -9,19 +9,23 @@ Decorators ---------- -``reversion.views.create_revision(manage_manually=False, using=None, atomic=True)`` +``reversion.views.create_revision(manage_manually=False, using=None, atomic=True, request_creates_revision=None)`` - Decorates a view to wrap every request that isn't ``GET``, ``HEAD`` or ``OPTIONS`` in a revision block. + Decorates a view to wrap every request in a revision block. The request user will also be added to the revision metadata. You can set the revision comment by calling :ref:`reversion.set_comment() <set_comment>` within your view. .. include:: /_include/create-revision-args.rst + ``request_creates_revision`` + + Hook used to decide whether a request should be wrapped in a revision block. If ``None``, it will default to omitting ``GET``, ``HEAD`` and ``OPTIONS`` requests. + reversion.views.RevisionMixin ----------------------------- -Mixin a class-based view to wrap every request that isn't ``GET``, ``HEAD`` or ``OPTIONS`` in a revision block. +Mixin a class-based view to wrap every request in a revision block. The request user will also be added to the revision metadata. You can set the revision comment by calling :ref:`reversion.set_comment() <set_comment>` within your view. @@ -43,3 +47,7 @@ ``RevisionMixin.revision_using = None`` .. include:: /_include/create-revision-using.rst + +``RevisionMixin.revision_request_creates_revision(request)`` + + By default, any request that isn't ``GET``, ``HEAD`` or ``OPTIONS`` will be wrapped in a revision block. Override this method if you need to apply a custom rule. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/__init__.py new/django-reversion-3.0.0/reversion/__init__.py --- old/django-reversion-2.0.13/reversion/__init__.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/__init__.py 2018-07-19 13:22:54.000000000 +0200 @@ -36,4 +36,4 @@ get_registered_models, ) -__version__ = VERSION = (2, 0, 13) +__version__ = VERSION = (3, 0, 0) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/admin.py new/django-reversion-3.0.0/reversion/admin.py --- old/django-reversion-2.0.13/reversion/admin.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/admin.py 2018-07-19 13:22:54.000000000 +0200 @@ -5,7 +5,6 @@ from django.conf.urls import url from django.contrib import admin, messages from django.contrib.admin import options -from django.contrib.admin.models import LogEntry from django.contrib.admin.utils import unquote, quote try: from django.contrib.contenttypes.admin import GenericInlineModelAdmin @@ -86,7 +85,7 @@ # could first call super() and get the change_message from the returned # LogEntry. if isinstance(change_message, list): - set_comment(LogEntry(change_message=json.dumps(change_message)).get_change_message()) + set_comment(json.dumps(change_message)) else: set_comment(change_message) try: @@ -97,7 +96,7 @@ def log_change(self, request, object, message): if is_active(): if isinstance(message, list): - set_comment(LogEntry(change_message=json.dumps(message)).get_change_message()) + set_comment(json.dumps(message)) else: set_comment(message) super(VersionAdmin, self).log_change(request, object, message) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/management/commands/createinitialrevisions.py new/django-reversion-3.0.0/reversion/management/commands/createinitialrevisions.py --- old/django-reversion-2.0.13/reversion/management/commands/createinitialrevisions.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/management/commands/createinitialrevisions.py 2018-07-19 13:22:54.000000000 +0200 @@ -1,8 +1,13 @@ from __future__ import unicode_literals + +import json + +from django.apps import apps +from django.core.management import CommandError from django.db import reset_queries, transaction, router from reversion.models import Revision, Version, _safe_subquery from reversion.management.commands import BaseRevisionCommand -from reversion.revisions import create_revision, set_comment, add_to_revision +from reversion.revisions import create_revision, set_comment, add_to_revision, add_meta class Command(BaseRevisionCommand): @@ -23,6 +28,14 @@ default=500, help="For large sets of data, revisions will be populated in batches. Defaults to 500.", ) + parser.add_argument( + "--meta", + action="store", + default={}, + type=json.loads, + help=("Specify meta models and corresponding values for each initial revision as JSON" + "eg. --meta \"{\"core.RevisionMeta\", {\"hello\": \"world\"}}\""), + ) def handle(self, *app_labels, **options): verbosity = options["verbosity"] @@ -30,6 +43,15 @@ model_db = options["model_db"] comment = options["comment"] batch_size = options["batch_size"] + meta = options["meta"] + meta_models = [] + for label in meta.keys(): + try: + model = apps.get_model(label) + meta_models.append(model) + except LookupError: + raise CommandError("Unknown model: {}".format(label)) + meta_values = meta.values() # Create revisions. using = using or router.db_for_write(Revision) with transaction.atomic(using=using): @@ -58,6 +80,9 @@ objects = live_objs.in_bulk(chunked_ids) for obj in objects.values(): with create_revision(using=using): + if meta: + for model, values in zip(meta_models, meta_values): + add_meta(model, **values) set_comment(comment) add_to_revision(obj, model_db=model_db) created_count += 1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/middleware.py new/django-reversion-3.0.0/reversion/middleware.py --- old/django-reversion-2.0.13/reversion/middleware.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/middleware.py 2018-07-19 13:22:54.000000000 +0200 @@ -20,11 +20,15 @@ self.get_response = create_revision( manage_manually=self.manage_manually, using=self.using, - atomic=self.atomic + atomic=self.atomic, + request_creates_revision=self.request_creates_revision )(get_response) + def request_creates_revision(self, request): + return _request_creates_revision(request) + def process_request(self, request): - if _request_creates_revision(request): + if self.request_creates_revision(request): context = create_revision_base( manage_manually=self.manage_manually, using=self.using, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/migrations/0001_initial.py new/django-reversion-3.0.0/reversion/migrations/0001_initial.py --- old/django-reversion-2.0.13/reversion/migrations/0001_initial.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/migrations/0001_initial.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations -import django.db.models.deletion -from django.conf import settings - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('contenttypes', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Revision', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('manager_slug', models.CharField(default='default', max_length=200, db_index=True)), - ('date_created', models.DateTimeField(auto_now_add=True, help_text='The date and time this revision was created.', verbose_name='date created', db_index=True)), - ('comment', models.TextField(help_text='A text comment on this revision.', verbose_name='comment', blank=True)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, to=settings.AUTH_USER_MODEL, help_text='The user who created this revision.', null=True, verbose_name='user')), - ], - options={ - "ordering": ("-pk",) - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Version', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('object_id', models.TextField(help_text='Primary key of the model under version control.')), - ('object_id_int', models.IntegerField(help_text="An indexed, integer version of the stored model's primary key, used for faster lookups.", null=True, db_index=True, blank=True)), - ('format', models.CharField(help_text='The serialization format used by this model.', max_length=255)), - ('serialized_data', models.TextField(help_text='The serialized form of this version of the model.')), - ('object_repr', models.TextField(help_text='A string representation of the object.')), - ('content_type', models.ForeignKey(help_text='Content type of the model under version control.', on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), - ('revision', models.ForeignKey(help_text='The revision that contains this version.', on_delete=django.db.models.deletion.CASCADE, to='reversion.Revision')), - ], - options={ - "ordering": ("-pk",) - }, - bases=(models.Model,), - ), - ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/migrations/0001_squashed_0004_auto_20160611_1202.py new/django-reversion-3.0.0/reversion/migrations/0001_squashed_0004_auto_20160611_1202.py --- old/django-reversion-2.0.13/reversion/migrations/0001_squashed_0004_auto_20160611_1202.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/migrations/0001_squashed_0004_auto_20160611_1202.py 2018-07-19 13:22:54.000000000 +0200 @@ -9,8 +9,6 @@ class Migration(migrations.Migration): - replaces = [('reversion', '0001_initial'), ('reversion', '0002_auto_20141216_1509'), ('reversion', '0003_auto_20160601_1600'), ('reversion', '0004_auto_20160611_1202')] - initial = True dependencies = [ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/migrations/0002_auto_20141216_1509.py new/django-reversion-3.0.0/reversion/migrations/0002_auto_20141216_1509.py --- old/django-reversion-2.0.13/reversion/migrations/0002_auto_20141216_1509.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/migrations/0002_auto_20141216_1509.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('reversion', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='revision', - name='manager_slug', - field=models.CharField(default='default', max_length=191, db_index=True), - ), - ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/migrations/0003_auto_20160601_1600.py new/django-reversion-3.0.0/reversion/migrations/0003_auto_20160601_1600.py --- old/django-reversion-2.0.13/reversion/migrations/0003_auto_20160601_1600.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/migrations/0003_auto_20160601_1600.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,108 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.6 on 2016-06-01 16:00 -from __future__ import unicode_literals - -from collections import defaultdict -from django.db import DEFAULT_DB_ALIAS, migrations, models, router -from django.apps import apps as live_apps - - -def de_dupe_version_table(apps, schema_editor): - """ - Removes some duplicate Version models that may have crept into the database and will prevent the - unique index being added by migration 0004. - """ - db_alias = schema_editor.connection.alias - Version = apps.get_model("reversion", "Version") - keep_version_ids = Version.objects.using(db_alias).order_by().values_list( - # Group by the unique constraint we intend to enforce. - "revision_id", - "content_type_id", - "object_id", - ).annotate( - # Add in the most recent id for each duplicate row. - max_pk=models.Max("pk"), - ).values_list("max_pk", flat=True) - # Do not do anything if we're keeping all ids anyway. - if keep_version_ids.count() == Version.objects.using(db_alias).all().count(): - return - # Delete all duplicate versions. Can't do this as a delete with subquery because MySQL doesn't like running a - # subquery on the table being updated/deleted. - delete_version_ids = list(Version.objects.using(db_alias).exclude( - pk__in=keep_version_ids, - ).values_list("pk", flat=True)) - Version.objects.using(db_alias).filter( - pk__in=delete_version_ids, - ).delete() - - -def set_version_db(apps, schema_editor): - """ - Updates the db field in all Version models to point to the correct write - db for the model. - """ - db_alias = schema_editor.connection.alias - Version = apps.get_model("reversion", "Version") - content_types = Version.objects.using(db_alias).order_by().values_list( - "content_type_id", - "content_type__app_label", - "content_type__model" - ).distinct() - model_dbs = defaultdict(list) - for content_type_id, app_label, model_name in content_types: - # We need to be able to access all models in the project, and we can't - # specify them up-front in the migration dependencies. So we have to - # just get the live model. This should be fine, since we don't actually - # manipulate the live model in any way. - try: - model = live_apps.get_model(app_label, model_name) - except LookupError: - # If the model appears not to exist, play it safe and use the default db. - db = "default" - else: - db = router.db_for_write(model) - model_dbs[db].append(content_type_id) - # Update db field. - # speedup for case when there is only default db - if DEFAULT_DB_ALIAS in model_dbs and len(model_dbs) == 1: - Version.objects.using(db_alias).update(db=DEFAULT_DB_ALIAS) - else: - for db, content_type_ids in model_dbs.items(): - Version.objects.using(db_alias).filter( - content_type__in=content_type_ids - ).update(db=db) - - -class Migration(migrations.Migration): - - dependencies = [ - ('reversion', '0002_auto_20141216_1509'), - ] - - operations = [ - migrations.RemoveField( - model_name='revision', - name='manager_slug', - ), - migrations.RemoveField( - model_name='version', - name='object_id_int', - ), - migrations.AlterField( - model_name='version', - name='object_id', - field=models.CharField(help_text='Primary key of the model under version control.', max_length=191), - ), - migrations.AlterField( - model_name='revision', - name='date_created', - field=models.DateTimeField(db_index=True, help_text='The date and time this revision was created.', verbose_name='date created'), - ), - migrations.AddField( - model_name='version', - name='db', - field=models.CharField(null=True, help_text='The database the model under version control is stored in.', max_length=191), - ), - migrations.RunPython(de_dupe_version_table), - migrations.RunPython(set_version_db), - ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/migrations/0004_auto_20160611_1202.py new/django-reversion-3.0.0/reversion/migrations/0004_auto_20160611_1202.py --- old/django-reversion-2.0.13/reversion/migrations/0004_auto_20160611_1202.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/migrations/0004_auto_20160611_1202.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.7 on 2016-06-11 12:02 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('reversion', '0003_auto_20160601_1600'), - ] - - operations = [ - migrations.AlterField( - model_name='version', - name='db', - field=models.CharField(help_text='The database the model under version control is stored in.', max_length=191), - ), - migrations.AlterUniqueTogether( - name='version', - unique_together=set([('db', 'content_type', 'object_id', 'revision')]), - ), - ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/models.py new/django-reversion-3.0.0/reversion/models.py --- old/django-reversion-2.0.13/reversion/models.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/models.py 2018-07-19 13:22:54.000000000 +0200 @@ -1,12 +1,13 @@ from __future__ import unicode_literals from collections import defaultdict -from itertools import chain +from itertools import chain, groupby from django.contrib.contenttypes.models import ContentType try: from django.contrib.contenttypes.fields import GenericForeignKey except ImportError: # Django < 1.9 pragma: no cover from django.contrib.contenttypes.generic import GenericForeignKey from django.conf import settings +from django.contrib.admin.models import LogEntry from django.core import serializers from django.core.serializers.base import DeserializationError from django.core.exceptions import ObjectDoesNotExist @@ -62,6 +63,14 @@ help_text="A text comment on this revision.", ) + def get_comment(self): + try: + return LogEntry(change_message=self.comment).get_change_message() + except AttributeError: + # Django < 1.10 + # LogEntry dont have `.get_change_message()` + return self.comment + def revert(self, delete=False): # Group the models by the database of the serialized model. versions_by_db = defaultdict(list) @@ -88,7 +97,10 @@ ) # Delete objects that are no longer in the current revision. collector = Collector(using=version_db) - collector.collect([item for item in current_revision if item not in old_revision]) + new_objs = [item for item in current_revision + if item not in old_revision] + for model, group in groupby(new_objs, type): + collector.collect(list(group)) collector.delete() # Attempt to revert all revisions. _safe_revert(versions) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/revisions.py new/django-reversion-3.0.0/reversion/revisions.py --- old/django-reversion-2.0.13/reversion/revisions.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/revisions.py 2018-07-19 13:22:54.000000000 +0200 @@ -218,6 +218,7 @@ def _save_revision(versions, user=None, comment="", meta=(), date_created=None, using=None): from reversion.models import Revision # Only save versions that exist in the database. + # Use _base_manager so we don't have problems when _default_manager is overriden model_db_pks = defaultdict(lambda: defaultdict(set)) for version in versions: model_db_pks[version._model][version.db].add(version.object_id) @@ -225,7 +226,7 @@ model: { db: frozenset(map( force_text, - model._default_manager.using(db).filter(pk__in=pks).values_list("pk", flat=True), + model._base_manager.using(db).filter(pk__in=pks).values_list("pk", flat=True), )) for db, pks in db_pks.items() } @@ -258,7 +259,7 @@ version.save(using=using) # Save the meta information. for meta_model, meta_fields in meta: - meta_model._default_manager.db_manager(using=using).create( + meta_model._base_manager.db_manager(using=using).create( revision=revision, **meta_fields ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/templates/reversion/object_history.html new/django-reversion-3.0.0/reversion/templates/reversion/object_history.html --- old/django-reversion-2.0.13/reversion/templates/reversion/object_history.html 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/templates/reversion/object_history.html 2018-07-19 13:22:54.000000000 +0200 @@ -29,7 +29,7 @@ — {% endif %} </td> - <td>{{action.revision.comment|linebreaksbr|default:""}}</td> + <td>{{action.revision.get_comment|linebreaksbr|default:""}}</td> </tr> {% endfor %} </tbody> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/reversion/views.py new/django-reversion-3.0.0/reversion/views.py --- old/django-reversion-2.0.13/reversion/views.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/reversion/views.py 2018-07-19 13:22:54.000000000 +0200 @@ -19,16 +19,18 @@ set_user(request.user) -def create_revision(manage_manually=False, using=None, atomic=True): +def create_revision(manage_manually=False, using=None, atomic=True, request_creates_revision=None): """ View decorator that wraps the request in a revision. The revision will have it's user set from the request automatically. """ + request_creates_revision = request_creates_revision or _request_creates_revision + def decorator(func): @wraps(func) def do_revision_view(request, *args, **kwargs): - if _request_creates_revision(request): + if request_creates_revision(request): try: with create_revision_base(manage_manually=manage_manually, using=using, atomic=atomic): response = func(request, *args, **kwargs) @@ -64,5 +66,9 @@ self.dispatch = create_revision( manage_manually=self.revision_manage_manually, using=self.revision_using, - atomic=self.revision_atomic + atomic=self.revision_atomic, + request_creates_revision=self.revision_request_creates_revision )(self.dispatch) + + def revision_request_creates_revision(self, request): + return _request_creates_revision(request) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/setup.py new/django-reversion-3.0.0/setup.py --- old/django-reversion-2.0.13/setup.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/setup.py 2018-07-19 13:22:54.000000000 +0200 @@ -38,8 +38,8 @@ "Operating System :: OS Independent", "Programming Language :: Python", 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', "Framework :: Django", ] ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/tests/test_app/migrations/0001_initial.py new/django-reversion-3.0.0/tests/test_app/migrations/0001_initial.py --- old/django-reversion-2.0.13/tests/test_app/migrations/0001_initial.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/tests/test_app/migrations/0001_initial.py 2018-07-19 13:22:54.000000000 +0200 @@ -48,6 +48,14 @@ ], ), migrations.CreateModel( + name='TestModelNestedInline', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nested_inline_name', models.CharField(default=b'v1', max_length=191)), + ('test_model_inline', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_app.TestModelInline')), + ], + ), + migrations.CreateModel( name='TestModelRelated', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/tests/test_app/models.py new/django-reversion-3.0.0/tests/test_app/models.py --- old/django-reversion-2.0.13/tests/test_app/models.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/tests/test_app/models.py 2018-07-19 13:22:54.000000000 +0200 @@ -99,6 +99,18 @@ ) +class TestModelNestedInline(models.Model): + test_model_inline = models.ForeignKey( + TestModelInline, + on_delete=models.CASCADE, + ) + + nested_inline_name = models.CharField( + max_length=191, + default="v1", + ) + + class TestMeta(models.Model): revision = models.ForeignKey( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/tests/test_app/tests/base.py new/django-reversion-3.0.0/tests/test_app/tests/base.py --- old/django-reversion-2.0.13/tests/test_app/tests/base.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/tests/test_app/tests/base.py 2018-07-19 13:22:54.000000000 +0200 @@ -51,9 +51,9 @@ revision = Version.objects.using(using).get_for_object(objects[0], model_db=model_db).get().revision self.assertEqual(revision.user, user) if hasattr(comment, 'pattern'): - assertRegex(self, revision.comment, comment) + assertRegex(self, revision.get_comment(), comment) elif comment is not None: # Allow a wildcard comment. - self.assertEqual(revision.comment, comment) + self.assertEqual(revision.get_comment(), comment) self.assertAlmostEqual(revision.date_created, date_created or timezone.now(), delta=timedelta(seconds=1)) # Check meta. self.assertEqual(revision.testmeta_set.count(), len(meta_names)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/tests/test_app/tests/test_commands.py new/django-reversion-3.0.0/tests/test_app/tests/test_commands.py --- old/django-reversion-2.0.13/tests/test_app/tests/test_commands.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/tests/test_app/tests/test_commands.py 2018-07-19 13:22:54.000000000 +0200 @@ -1,3 +1,4 @@ +import json from datetime import timedelta from django.core.management import CommandError from django.utils import timezone @@ -81,6 +82,15 @@ self.assertSingleRevision((obj,), comment="comment v1") +class CreateInitialRevisionsMetaTest(TestModelMixin, TestBase): + def testCreateInitialRevisionsComment(self): + obj = TestModel.objects.create() + meta_name = "meta name" + meta = json.dumps({"test_app.TestMeta": {"name": meta_name}}) + self.callCommand("createinitialrevisions", "--meta", meta) + self.assertSingleRevision((obj,), meta_names=(meta_name, ), comment="Initial version.") + + class DeleteRevisionsTest(TestModelMixin, TestBase): def testDeleteRevisions(self): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/tests/test_app/tests/test_models.py new/django-reversion-3.0.0/tests/test_app/tests/test_models.py --- old/django-reversion-2.0.13/tests/test_app/tests/test_models.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/tests/test_app/tests/test_models.py 2018-07-19 13:22:54.000000000 +0200 @@ -1,7 +1,10 @@ from django.utils.encoding import force_text import reversion from reversion.models import Version -from test_app.models import TestModel, TestModelRelated, TestModelParent +from test_app.models import ( + TestModel, TestModelRelated, TestModelParent, TestModelInline, + TestModelNestedInline, +) from test_app.tests.base import TestBase, TestModelMixin, TestModelParentMixin @@ -373,3 +376,40 @@ obj.refresh_from_db() self.assertEqual(obj.name, "v1") self.assertFalse(TestModelRelated.objects.filter(pk=obj_related.pk).exists()) + + def testRevertDeleteNestedInline(self): + reversion.register(TestModel, follow=("testmodelinline_set",)) + reversion.register( + TestModelInline, follow=("testmodelnestedinline_set",)) + reversion.register(TestModelNestedInline) + with reversion.create_revision(): + parent = TestModel.objects.create() + child_a = TestModelInline.objects.create( + test_model=parent) + grandchild_a = TestModelNestedInline.objects.create( + test_model_inline=child_a) + + with reversion.create_revision(): + child_b = TestModelInline.objects.create( + test_model=parent) + grandchild_b = TestModelNestedInline.objects.create( + test_model_inline=child_b) + reversion.add_to_revision(parent) + + Version.objects.get_for_object(parent)[1].revision.revert(delete=True) + parent.refresh_from_db() + self.assertRaises( + TestModelInline.DoesNotExist, + lambda: child_b.refresh_from_db() + ) + + self.assertRaises( + TestModelNestedInline.DoesNotExist, + lambda: grandchild_b.refresh_from_db() + ) + self.assertEqual( + list(parent.testmodelinline_set.all()), [child_a] + ) + self.assertEqual( + list(child_a.testmodelnestedinline_set.all()), [grandchild_a] + ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/tests/test_app/tests/test_views.py new/django-reversion-3.0.0/tests/test_app/tests/test_views.py --- old/django-reversion-2.0.13/tests/test_app/tests/test_views.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/tests/test_app/tests/test_views.py 2018-07-19 13:22:54.000000000 +0200 @@ -33,6 +33,10 @@ self.client.get("/test-app/revision-mixin/") self.assertNoRevision() + def testRevisionMixinCustomPredicate(self): + self.client.post("/test-app/revision-mixin/", HTTP_X_NOREVISION="true") + self.assertNoRevision() + class RevisionMixinUserTest(LoginMixin, TestModelMixin, TestBase): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/django-reversion-2.0.13/tests/test_app/views.py new/django-reversion-3.0.0/tests/test_app/views.py --- old/django-reversion-2.0.13/tests/test_app/views.py 2018-01-23 11:36:05.000000000 +0100 +++ new/django-reversion-3.0.0/tests/test_app/views.py 2018-07-19 13:22:54.000000000 +0200 @@ -20,5 +20,9 @@ class RevisionMixinView(RevisionMixin, View): + def revision_request_creates_revision(self, request): + silent = request.META.get("HTTP_X_NOREVISION", "false") == "true" + return super(RevisionMixinView, self).revision_request_creates_revision(request) and not silent + def dispatch(self, request): return save_obj_view(request)
participants (1)
-
root