pax_global_header 0000666 0000000 0000000 00000000064 12627540154 0014520 g ustar 00root root 0000000 0000000 52 comment=6941e53f1a455782bc2a3dd363e24ab718edc3ee
django-reversion-release-1.10.0/ 0000775 0000000 0000000 00000000000 12627540154 0016471 5 ustar 00root root 0000000 0000000 django-reversion-release-1.10.0/.coveragerc 0000664 0000000 0000000 00000000562 12627540154 0020615 0 ustar 00root root 0000000 0000000 [report]
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
assert False
# Don't complain if tests don't hit model __str__ methods.
def __str__
omit =
*/venv/*
*/virtualenv/*
show_missing = True
django-reversion-release-1.10.0/.gitignore 0000664 0000000 0000000 00000000217 12627540154 0020461 0 ustar 00root root 0000000 0000000 .DS_Store
*.db
.project
.pydevproject
.settings
*.pyc
*.pyo
dist
build
MANIFEST
src/django_reversion.egg-info/
docs/_build
.coverage
*.sqlite3
django-reversion-release-1.10.0/.travis.yml 0000664 0000000 0000000 00000004150 12627540154 0020602 0 ustar 00root root 0000000 0000000 language: python
sudo: false
python:
- 2.7
- 3.4
- 3.5
cache:
directories:
- $HOME/.cache/pip
env:
- DJANGO=django==1.7.11
- DJANGO=django==1.7.11 DB_ENGINE="django.db.backends.postgresql_psycopg2" DB_NAME="test_project" DB_USER="postgres"
- DJANGO=django==1.7.11 DB_ENGINE="django.db.backends.mysql" DB_NAME="test_project" DB_USER="travis"
- DJANGO=django==1.8.7
- DJANGO=django==1.8.7 DB_ENGINE="django.db.backends.postgresql_psycopg2" DB_NAME="test_project" DB_USER="postgres"
- DJANGO=django==1.8.7 DB_ENGINE="django.db.backends.mysql" DB_NAME="test_project" DB_USER="travis"
- DJANGO=django==1.9.0
- DJANGO=django==1.9.0 DB_ENGINE="django.db.backends.postgresql" DB_NAME="test_project" DB_USER="postgres"
- DJANGO=django==1.9.0 DB_ENGINE="django.db.backends.mysql" DB_NAME="test_project" DB_USER="travis"
matrix:
fast_finish: true
exclude:
- python: 3.5
env: DJANGO=django==1.7.11
- python: 3.5
env: DJANGO=django==1.7.11 DB_ENGINE="django.db.backends.postgresql_psycopg2" DB_NAME="test_project" DB_USER="postgres"
- python: 3.5
env: DJANGO=django==1.7.11 DB_ENGINE="django.db.backends.mysql" DB_NAME="test_project" DB_USER="travis"
services:
- postgresql
- mysql
install:
- travis_retry pip install $DJANGO
- if [[ "$DB_ENGINE" == "django.db.backends.postgresql" ]] ; then travis_retry pip install psycopg2; fi
- if [[ "$DB_ENGINE" == "django.db.backends.postgresql_psycopg2" ]] ; then travis_retry pip install psycopg2; fi
- if [[ "$DB_ENGINE" == "django.db.backends.mysql" ]] ; then travis_retry pip install mysqlclient ; fi
- pip install -e .[test,diff]
before_script:
- if [[ "$DB_ENGINE" == "django.db.backends.mysql" ]] ; then mysql -e 'create database test_project'; fi
- if [[ "$DB_ENGINE" == "django.db.backends.postgresql_psycopg2" ]] ; then psql -c 'create database test_project;' -U postgres; fi
- if [[ "$DB_ENGINE" == "django.db.backends.postgresql" ]] ; then psql -c 'create database test_project;' -U postgres; fi
script: coverage run src/tests/manage.py test src/tests/test_reversion/
after_script: coverage report
notifications:
email: false
django-reversion-release-1.10.0/CHANGELOG.md 0000664 0000000 0000000 00000023156 12627540154 0020311 0 ustar 00root root 0000000 0000000 # django-reversion changelog
## 1.10 - 02/12/2015
- **Breaking:** Updated the location of [admin classes](http://django-reversion.readthedocs.org/en/latest/admin.html).
Prior to this change, you could access the `VersionAdmin` class using the following import:
```py
# Old-style import for accessing the admin class.
import reversion
# Access admin class from the reversion namespace.
class YourModelAdmin(reversion.VersionAdmin):
...
```
In order to support Django 1.9, the admin class has been moved to the following
import:
```py
# New-style import for accesssing admin class.
from reversion.admin import VersionAdmin
# Use the admin class directly.
class YourModelAdmin(VersionAdmin):
...
```
- **Breaking:** Updated the location of [low-level API](http://django-reversion.readthedocs.org/en/latest/api.html) methods.
Prior to this change, you could access the low-level API using the following import:
```py
# Old-style import for accessing the low-level API.
import reversion
# Use low-level API methods from the reversion namespace.
@reversion.register
class YourModel(models.Model):
...
```
In order to support Django 1.9, the low-level API
methods have been moved to the following import:
```py
# New-style import for accesssing the low-level API.
from reversion import revisions
# Use low-level API methods from the revisions namespace.
@revisions.register
class YourModel(models.Model):
...
```
- **Breaking:** Updated the location of [reversion signals](http://django-reversion.readthedocs.org/en/latest/signals.html).
Prior to this change, you could access the reversion signals using the following import:
```py
# Old-style import for accessing the reversion signals
import reversion
# Use signals from the reversion namespace.
reversion.post_revision_commit.connect(...)
```
In order to support Django 1.9, the reversion signals have been moved to the following
import:
```py
# New-style import for accesssing the reversion signals.
from reversion.signals import pre_revision_commit, post_revision_commit
# Use reversion signals directly.
post_revision_commit.connect(...)
```
- Django 1.9 compatibility (@etianen).
- Added spanish (argentina) translation (@gonzalobustos).
- Minor bugfixes and tweaks (@Blitzstok, @IanLee1521, @lutoma, @siamalekpour, @etianen).
## 1.9.3 - 07/08/2015
- Fixing regression with admin redirects following save action (@etianen).
## 1.9.2 - 07/08/2015
- Fixing regression with "delete", "save as new" and "save and continue" button being shown in recover and revision admin views (@etianen).
- Fixing regression where VersionAdmin.ignore_duplicate_revisions was ignored (@etianen).
## 1.9.1 - 04/08/2015
- Fixing packaging error that rendered the 1.9.0 release unusable. No way to cover up the mistake, so here's a brand new bugfix release! (@etianen).
## 1.9.0 - 04/08/2015
- Using database transactions do render consistent views of past revisions in database admin, fixing a lot of lingering minor issues (@etianen).
- Correct handling of readonly fields in admin (@etianen).
- Updates to Czech translation (@cuchac).
- Arabic translation (@RamezIssac).
- Fixing deleterevisions to work with Python2 (@jmurty).
- Fixing edge-cases where an object does not have a PK (@johnfraney).
- Tweaks, code cleanups and documentation fixes (@claudep, @johnfraney, @podloucky-init, Drew Hubl, @JanMalte, @jmurty, @etianen).
## 1.8.7 - 21/05/2015
- Fixing deleterevisions command on Python 3 (@davidfsmith).
- Fixing Django 1.6 compatibility (@etianen).
- Removing some Django 1.9 deprecation warnings (@BATCOH, @niknokseyer).
- Minor tweaks (@nikolas, @etianen).
## 1.8.6 - 13/04/2015
- Support for MySQL utf8mb4 (@alexhayes).
- Fixing some Django deprecation warnings (Drew Hubl, @khakulov, @adonm).
- Versions passed through by reversion.post_revision_commit now contain a primary key (@joelarson).
## 1.8.5 - 31/10/2014
- Added support for proxy models (@AgDude, @bourivouh).
- Allowing registration of models with django-reversion using custom signals (@ErwinJunge).
- Fixing some Django deprecation warnings (@skipp, @narrowfail).
## 1.8.4 - 07/09/2014
- Fixing including legacy south migrations in PyPi package (@GeyseR).
## 1.8.3 - 06/09/2014
- Provisional Django 1.7 support (@etianen).
- Multi-db and multi-manager support to management commands (@marekmalek).
- Added index on reversion.date_created (@rkojedzinszky).
- Minor bugfixes and documentation improvements (@coagulant).
## 1.8.2 - 01/08/2014
- reversion.register() can now be used as a class decorator (@aquavitae).
- Danish translation (@Vandborg).
- Improvements to Travis CI integration (@thedrow).
- Simplified Chinese translation (@QuantumGhost).
- Minor bugfixes and documentation improvements (@marekmalek, @dhoffman34, @mauricioabreu, @mark0978).
## 1.8.1 - 29/05/2014
- Slovak translation (@jbub).
- Deleting a user no longer deletes the associated revisions (@daaray).
- Improving handling of inline models in admin integration (@blueyed).
- Improving error messages for proxy model registration (@blueyed).
- Improvements to using migrations with custom user model (@aivins).
- Removing sys.exit() in deleterevisions management command, allowing it to be used internally by Django projects (@tongwang).
- Fixing some backwards-compatible admin deprecation warnings (Thomas Schreiber).
- Fixing tests if RevisionMiddleware is used as a decorator in the parent project (@jmoldow).
- Derived models, such as those generated by deferred querysets, now work.
- Removed deprecated low-level API methods.
## 1.8.0 - 01/11/2013
- Django 1.6 compatibility (@niwibe & @meshy).
- Removing type flag from Version model.
- Using bulk_create to speed up revision creation.
- Including docs in source distribution (@pquentin & @fladi).
- Spanish translation (@alexander-ae).
- Fixing edge-case bugs in revision middleware (@pricem & @oppianmatt).
## 1.7.1 - 26/06/2013
- Bugfixes when using a custom User model.
- Minor bugfixes.
## 1.7 - 27/02/2013
- Django 1.5 compatibility.
- Experimantal Python 3.3 compatibility!
## 1.6.6 - 12/02/2013
- Removing version checking code. It's more trouble than it's worth.
- Dutch translation improvements.
## 1.6.5 - 12/12/2012
- Support for Django 1.4.3.
## 1.6.4 - 28/10/2012
- Support for Django 1.4.2.
## 1.6.3 - 05/09/2012
- Fixing issue with reverting models with unique constraints in the admin.
- Enforcing permissions in admin views.
## 1.6.2 - 31/07/2012
- Batch saving option in createinitialrevisions.
- Suppressing warning for Django 1.4.1.
## 1.6.1 - 20/06/2012
- Swedish translation.
- Fixing formating for PyPi readme and license.
- Minor features and bugfixes.
## 1.6 - 27/03/2012
- Django 1.4 compatibility.
## 1.5.2 - 27/03/2012
- Multi-db support.
- Brazillian Portuguese translation.
- New manage_manually revision mode.
## 1.5.1 - 20/10/2011
- Polish translation.
- Minor bug fixes.
## 1.5 - 04/09/2011
- Added in simplified low level API methods, and deprecated old low level API methods.
- Added in support for multiple revision managers running in the same project.
- Added in significant speedups for models with integer primary keys.
- Added in cleanup improvements to patch generation helpers.
- Minor bug fixes.
## 1.4 - 27/04/2011
- Added in a version flag for add / change / delete annotations.
- Added experimental deleterevisions management command.
- Added a --comment option to createinitialrevisions management command.
- Django 1.3 compatibility.
## 1.3.3 - 05/03/2011
- Improved resilience of revert() to database integrity errors.
- Added in Czech translation.
- Added ability to only save revisions if there is no change.
- Fixed long-running bug with file fields in inline related admin models.
- Easier debugging for createinitialrevisions command.
- Improved compatibility with Oracle database backend.
- Fixed error in MySQL tests.
- Greatly improved performance of get_deleted() Version manager method.
- Fixed an edge-case UnicodeError.
## 1.3.2 - 22/10/2010
- Added Polish translation.
- Added French translation.
- Improved resilience of unit tests.
- Improved scaleability of Version.object.get_deleted() method.
- Improved scaleability of createinitialrevisions command.
- Removed post_syncdb hook.
- Added new createinitialrevisions management command.
- Fixed DoesNotExistError with OneToOneFields and follow.
## 1.3.1 - 31/05/2010
This release is compatible with Django 1.2.1.
- Django 1.2.1 admin compatibility.
## 1.2.1 - 03/03/2010
This release is compatible with Django 1.1.1.
- The django syncdb command will now automatically populate any
version-controlled models with an initial revision. This ensures existing
projects that integrate Reversion won't get caught out.
- Reversion now works with SQLite for tables over 999 rows.
- Added Hebrew translation.
## 1.2 - 12/10/2009
This release is compatible with Django 1.1.
- Django 1.1 admin compatibility.
## 1.1.2 - 23/07/2009
This release is compatible with Django 1.0.4.
- Doc tests.
- German translation update.
- Better compatibility with the Django trunk.
- The ability to specify a serialization format used by the ReversionAdmin
class when models are auto-registered.
- Reduction in the number of database queries performed by the Reversion
- admin interface.
## 1.1.1 - 25/03/2010
This release is compatible with Django 1.0.2.
- German and Italian translations.
- Helper functions for generating diffs.
- Improved handling of one-to-many relationships in the admin.
django-reversion-release-1.10.0/LICENSE 0000664 0000000 0000000 00000002764 12627540154 0017507 0 ustar 00root root 0000000 0000000 Copyright (c) 2009, David Hall.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of David Hall nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
django-reversion-release-1.10.0/MANIFEST.in 0000664 0000000 0000000 00000000334 12627540154 0020227 0 ustar 00root root 0000000 0000000 include src/reversion/templates/reversion/*.html
include src/reversion/locale/*/LC_MESSAGES/django.*
include LICENSE
include README.rst
include CHANGELOG.md
include MANIFEST.in
recursive-include docs *
prune docs/_build
django-reversion-release-1.10.0/README.rst 0000664 0000000 0000000 00000005711 12627540154 0020164 0 ustar 00root root 0000000 0000000 django-reversion
================
**django-reversion** is an extension to the Django web framework that provides
comprehensive version control facilities.
Features
--------
- Roll back to any point in a model's history - an unlimited undo facility!
- Recover deleted models - never lose data again!
- Admin integration for maximum usability.
- Group related changes into revisions that can be rolled back in a single
transaction.
- Automatically save a new version whenever your model changes using Django's
flexible signalling framework.
- Automate your revision management with easy-to-use middleware.
**django-reversion** can be easily added to your existing Django project with an
absolute minimum of code changes.
Documentation
-------------
Please read the `Getting Started `_
guide for more information.
Download instructions, bug reporting and links to full documentation can be
found at the `main project website `_.
You can keep up to date with the latest announcements by joining the
`django-reversion discussion group `_.
Upgrading
---------
If you're upgrading your existing installation of django-reversion, please check
the `Schema Migrations `_
documentation for information on any database changes and how to upgrade. If you're using
South to manage database migrations in your project, then upgrading is as easy as running
a few django management commands.
It's always worth checking the `CHANGELOG `_
before upgrading too, just in case you get caught off-guard by a minor upgrade to the library.
Contributing
------------
Bug reports, bug fixes, and new features are always welcome. Please raise issues on the
`django-reversion project site `_, and submit
pull requests for any new code.
You can run the test suite yourself from within a virtual environment with the following
commands:
::
$ pip install -e .[test]
$ coverage run src/tests/manage.py test src/tests/test_reversion/
The django-reversion project is built on every push with `Travis CI `_.
.. image:: https://travis-ci.org/etianen/django-reversion.svg?branch=master
:target: https://travis-ci.org/etianen/django-reversion
More information
----------------
The django-reversion project was developed by Dave Hall. You can get the code
from the `django-reversion project site `_.
Dave Hall is a freelance web developer, based in Cambridge, UK. You can usually
find him on the Internet in a number of different places:
- `Website `_
- `Twitter `_
- `Google Profile `_
django-reversion-release-1.10.0/docs/ 0000775 0000000 0000000 00000000000 12627540154 0017421 5 ustar 00root root 0000000 0000000 django-reversion-release-1.10.0/docs/Makefile 0000664 0000000 0000000 00000012744 12627540154 0021071 0 ustar 00root root 0000000 0000000 # Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make ' where is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/django-reversion.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/django-reversion.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/django-reversion"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/django-reversion"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
django-reversion-release-1.10.0/docs/admin.rst 0000664 0000000 0000000 00000004770 12627540154 0021253 0 ustar 00root root 0000000 0000000 .. _admin:
Admin integration
=================
django-reversion can be used to add a powerful rollback and recovery facility to your admin site. To enable this, simply register your models with a subclass of ``reversion.VersionAdmin``.
::
from reversion.admin import VersionAdmin
class YourModelAdmin(VersionAdmin):
pass
admin.site.register(YourModel, YourModelAdmin)
You can also use ``VersionAdmin`` as a mixin with another specialized admin class.
::
class YourModelAdmin(VersionAdmin, YourBaseModelAdmin):
pass
If you're using an existing third party app, then you can add patch django-reversion into its admin class by using the ``reversion.helpers.patch_admin()`` method. For example, to add version control to the built-in User model:
::
from reversion.helpers import patch_admin
patch_admin(User)
Admin customizations
--------------------
It's possible to customize the way django-reversion integrates with your admin site by specifying options on the subclass of ``VersionAdmin`` as follows:
::
class YourModelAdmin(VersionAdmin):
option_name = option_value
The available admin options are:
* **history_latest_first:** Whether to display the available versions in reverse chronological order on the revert and recover views (default ``False``)
* **ignore_duplicate_revisions:** Whether to ignore duplicate revisions when storing version data (default ``False``)
* **recover_form_template:** The name of the template to use when rendering the recover form (default ``'reversion/recover_form.html'``)
* **reversion_format:** The name of a serialization format to use when storing version data (default ``'json'``)
* **revision_form_template:** The name of the template to use when rendering the revert form (default ``'reversion/revision_form.html'``)
* **recover_list_template:** The name of the template to use when rendering the recover list view (default ``'reversion/recover_list.html'``)
Customizing admin templates
---------------------------
In addition to specifying custom templates using the options above, you can also place specially named templates on your template root to override the default templates on a per-model or per-app basis.
For example, to override the recover_list template for the user model, the auth app, or all registered models, you could create a template with one of the following names:
* ``'reversion/auth/user/recover_list.html'``
* ``'reversion/auth/recover_list.html'``
* ``'reversion/recover_list.html'``
django-reversion-release-1.10.0/docs/api.rst 0000664 0000000 0000000 00000027512 12627540154 0020733 0 ustar 00root root 0000000 0000000 .. _api:
Low-level API
=============
You can use django-reversion's API to build powerful version-controlled views outside of the built-in admin site.
Importing the low-level API
---------------------------
Import the low-level API as follows:
::
from reversion import revisions
**Note:** If using django-reversion < 1.10, import the low-level API using ``import reversion as revisions``.
Registering models with django-reversion
----------------------------------------
If you're already using the :ref:`admin integration ` for a model, then there's no need to register it. However, if you want to register a model without using the admin integration, then you need to use the ``revisions.register()`` method.
::
from reversion import revisions
revisions.register(YourModel)
``revisions.register`` can also be used as a class decorator, with or without arguments.
::
from reversion import revisions
@revisions.register
class YourModel(models.Model):
...
@revisions.register(format='yaml')
class YourOtherModel(models.Model):
...
**Warning:** If you’re using django-reversion in a management command, and are using the automatic ``VersionAdmin`` registration method, then you’ll need to import the relevant ``admin.py`` file at the top of your management command file.
**Warning:** When Django starts up, some python scripts get loaded twice, which can cause 'already registered' errors to be thrown. If you place your calls to ``revisions.register()`` in the ``models.py`` file, immediately after the model definition, this problem will go away.
Creating revisions
------------------
A revision represents one or more changes made to your models, grouped together as a single unit. You create a revision by marking up a section of code to represent a revision. Whenever you call ``save()`` on a model within the scope of a revision, it will be added to that revision.
**Note:** If you call ``save()`` outside of the scope of a revision, a revision is NOT created. This means that you are in control of when to create revisions.
There are several ways to create revisions, as explained below. Although there is nothing stopping you from mixing and matching these approaches, it is recommended that you pick one of the methods and stick with it throughout your project.
revisions.create_revision() decorator
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can decorate any function with the ``revisions.create_revision()`` decorator. Any changes to your models that occur during this function will be grouped together into a revision.
::
@transaction.atomic()
@revisions.create_revision()
def you_view_func(request):
your_model.save()
revisions.create_revision() context manager
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can use a context manager to mark up a block of code. Once the block terminates, any changes made to your models will be grouped together into a revision.
::
with transaction.atomic(), revisions.create_revision():
your_model.save()
RevisionMiddleware
^^^^^^^^^^^^^^^^^^
The simplest way to create revisions is to use ``reversion.middleware.RevisionMiddleware``. This will automatically wrap every request in a revision, ensuring that all changes to your models will be added to their version history.
To enable the revision middleware, simply add it to your ``MIDDLEWARE_CLASSES`` setting as follows::
MIDDLEWARE_CLASSES = (
'reversion.middleware.RevisionMiddleware',
# Other middleware goes here...
)
**Warning**: Due to changes in the Django 1.6 transaction handling, revision data will be saved in a separate database transaction to the one used to save your models, even if you set ``ATOMIC_REQUESTS = True``. If you need to ensure that your models and revisions are saved in the save transaction, please use the ``revisions.create_revision()`` context manager or decorator in combination with ``transaction.atomic()``.
Version meta data
-----------------
It is possible to attach a comment and a user reference to an active revision using the following method::
with transaction.atomic(), revisions.create_revision():
your_model.save()
revisions.set_user(user)
revisions.set_comment("Comment text...")
If you use ``RevisionMiddleware``, then the user will automatically be added to the revision from the incoming request.
Custom meta data
^^^^^^^^^^^^^^^^
You can attach custom meta data to a revision by creating a separate django model to hold the additional fields. For example::
from reversion.models import Revision
class VersionRating(models.Model):
# There must be a relationship with Revision called `revision`.
revision = models.ForeignKey(Revision)
rating = models.PositiveIntegerField()
You can then attach this meta class to a revision using the following method::
revisions.add_meta(VersionRating, rating=5)
Reverting to previous revisions
-------------------------------
To revert a model to a previous version, use the following method::
your_model = YourModel.objects.get(pk=1)
# Build a list of all previous versions, latest versions first:
version_list = revisions.get_for_object(your_model)
# Build a list of all previous versions, latest versions first, duplicates removed:
version_list = revisions.get_for_object(your_model).get_unique()
# Find the most recent version for a given date:
version = revisions.get_for_date(your_model, datetime.datetime(2008, 7, 10))
# Access the model data stored within the version:
version_data = version.field_dict
# Revert all objects in this revision:
version.revision.revert()
# Revert all objects in this revision, deleting related objects that have been created since the revision:
version.revision.revert(delete=True)
# Just revert this object, leaving the rest of the revision unchanged:
version.revert()
Recovering Deleted Objects
--------------------------
To recover a deleted object, use the following method::
# Built a list of all deleted objects, latest deletions first.
deleted_list = revisions.get_deleted(YourModel)
# Access a specific deleted object.
delete_version = deleted_list.get(id=5)
# Recover all objects in this revision:
deleted_version.revision.revert()
# Just recover this object, leaving the rest of the revision unchanged:
deleted_version.revert()
Advanced model registration
---------------------------
Following foreign key relationships
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Normally, when you save a model it will only save the primary key of any ForeignKey or ManyToMany fields. If you also wish to include the data of the foreign key in your revisions, pass a list of relationship names to the ``revisions.register()`` method.
::
revisions.register(YourModel, follow=["your_foreign_key_field"])
**Please note:** If you use the follow parameter, you must also ensure that the related model has been registered with django-reversion.
In addition to ForeignKey and ManyToMany relationships, you can also specify related names of one-to-many relationships in the follow clause. For example, given the following database models::
class Person(models.Model):
pass
class Pet(models.Model):
person = models.ForeignKey(Person)
revisions.register(Person, follow=["pet_set"])
revisions.register(Pet)
Now whenever you save a revision containing a ``Person``, all related ``Pet`` instances will be automatically saved to the same revision.
Multi-table inheritance
^^^^^^^^^^^^^^^^^^^^^^^
By default, django-reversion will not save data in any parent classes of a model that uses multi-table inheritance. If you wish to also add parent models to your revision, you must explicitly add them to the follow clause when you register the model.
For example::
class Place(models.Model):
pass
class Restaurant(Place):
pass
revisions.register(Place)
revisions.register(Restaurant, follow=["place_ptr"])
Saving a subset of fields
^^^^^^^^^^^^^^^^^^^^^^^^^
If you only want a subset of fields to be saved to a revision, you can specify a ``fields`` or ``exclude`` argument to the ``revisions.register()`` method.
::
revisions.register(YourModel, fields=["pk", "foo", "bar"])
revisions.register(YourModel, exclude=["foo"])
**Please note:** If you are not careful, then it is possible to specify a combination of fields that will make the model impossible to recover. As such, approach this option with caution.
Custom serialization format
^^^^^^^^^^^^^^^^^^^^^^^^^^^
By default, django-reversion will serialize model data using the ``'json'`` serialization format. You can override this on a per-model basis using the format argument to the register method.
::
revisions.register(YourModel, format="yaml")
**Please note:** The named serializer must serialize model data to a utf-8 encoded character string. Please verify that your serializer is compatible before using it with django-reversion.
Registering with custom signals
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
By default, django-reversion saves a new revision whenever a model is saved, using the ``post_save`` signal. However, sometimes you might need to create a revision on other signals too.
::
from django.db.models.signals import post_save
from your_app.signals import custom_signal
revisions.register(YourModel, signals=[post_save, custom_signal])
By default, revision data is serialized at the end of the ``revisions.create_revision()`` block, allowing foreign key references to be updated in the same block before the revision data is prepared. However, in some cases you might want to serialize the revision data immediately, such as times when the model is shortly going to be deleted.
::
from django.db.models.signals import post_save, pre_delete
revisions.register(YourModel, signals=[post_save], eager_signals=[pre_delete])
**Important:** Creating revisions using the `pre_delete` signal is not recommended, as it alters the semantics of revision recovery. Only do this if you have a good understanding of the django-reversion internals.
Really advanced registration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It's possible to customize almost every aspect of model registration by registering your model with a subclass of ``revisions.VersionAdapter``. Behind the scenes, ``revisions.register()`` does this anyway, but you can explicitly provide your own VersionAdapter if you need to perform really advanced customization.
::
class MyVersionAdapter(revisions.VersionAdapter):
pass # Please see the reversion source code for available methods to override.
revisions.register(MyModel, adapter_cls=MyVersionAdapter)
Automatic Registration by the Admin Interface
---------------------------------------------
As mentioned at the start of this page, the admin interface will automatically register any models that use the ``VersionAdmin`` class. The admin interface will automatically follow any InlineAdmin relationships, as well as any parent links for models that use multi-table inheritance.
For example::
# models.py
class Place(models.Model):
pass
class Restaurant(Place):
pass
class Meal(models.Model):
restaurant = models.ForeignKey(Restaurant)
# admin.py
class MealInlineAdmin(admin.StackedInline):
model = Meal
class RestaurantAdmin(VersionAdmin):
inlines = MealInlineAdmin,
admin.site.register(Restaurant, RestaurantAdmin)
Since ``Restaurant`` has been registered with a subclass of ``VersionAdmin``, the following registration calls will be made automatically::
revisions.register(Place)
revisions.register(Restaurant, follow=("place_ptr", "meal_set"))
revisions.register(Meal)
It is only necessary to manually register these models if you wish to override the default registration parameters. In most cases, however, the defaults will suit just fine.
django-reversion-release-1.10.0/docs/commands.rst 0000664 0000000 0000000 00000002316 12627540154 0021756 0 ustar 00root root 0000000 0000000 .. _commands:
Management commands
===================
django-reversion comes with a number of additional django-admin.py management commands, detailed below.
createinitialrevisions
----------------------
This command is used to create a single, base revision for all registered models in your project. It should be run after installing django-reversion, or registering a new model with django-reversion. If your project contains a lot of version-controlled data, then this might take a while to complete.
::
django-admin.py createinitialrevisions
django-admin.py createinitialrevisions someapp
django-admin.py createinitialrevisions someapp.SomeModel
deleterevisions
----------------------
This command is used to delete old revisions. It can be run regularly to keep storage requirements of models history sane. You can specify to delete revisions older than N days or delete only revisions older than the specified date or keep only the N most recent revisions for each object.
::
django-admin.py deleterevisions myapp
django-admin.py deleterevisions --date=2015-01-15
django-admin.py deleterevisions myapp.mymodel --days=365 --force
django-admin.py deleterevisions myapp.mymodel --keep=10
django-reversion-release-1.10.0/docs/conf.py 0000664 0000000 0000000 00000017443 12627540154 0020731 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# django-reversion documentation build configuration file, created by
# sphinx-quickstart on Thu Aug 29 09:17:37 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.intersphinx']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = 'django-reversion'
copyright = '2013, Dave Hall'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.10'
# The full version, including alpha/beta/rc tags.
release = '1.10.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# " v documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'django-reversiondoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-reversion.tex', 'django-reversion Documentation',
'Dave Hall', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-reversion', 'django-reversion Documentation',
['Dave Hall'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'django-reversion', 'django-reversion Documentation',
'Dave Hall', 'django-reversion', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'http://docs.python.org/': None}
django-reversion-release-1.10.0/docs/diffs.rst 0000664 0000000 0000000 00000004657 12627540154 0021262 0 ustar 00root root 0000000 0000000 .. _diffs:
Generating Diffs
================
A common problem when dealing with version-controlled text is generating diffs to highlight changes between different versions.
django-reversion comes with a number of helper functions that make generating diffs easy. They all rely on the `google-diff-match-patch `_ library, so make sure you have this installed before trying to use the functions.
Low-Level API
-------------
It is possible to generate two types of diff using the diff helper functions. For the purpose of these examples, it is assumed that you have created a model called ``Page``, which contains a text field called ``content``.
First of all, you need to use the :ref:`low level API ` to retrieve the versions you want to compare.
::
from reversion.helpers import generate_patch
# Get the page object to generate diffs for.
page = Page.objects.all()[0]
# Get the two versions to compare.
available_versions = revisions.get_for_object(page)
new_version = available_versions[0]
old_version = available_versions[1]
Now, in order to generate a text patch::
from reversion.helpers import generate_patch
patch = generate_patch(old_version, new_version, "content")
Or, to generate a pretty HTML patch::
from reversion.helpers import generate_patch_html
patch_html = generate_patch_html(old_version, new_version, "content")
Because text diffs can often be fragmented and hard to read, an optional ``cleanup`` parameter may be passed to generate friendlier diffs.
::
patch_html = generate_patch_html(old_version, new_version, "content", cleanup="semantic")
patch_html = generate_patch_html(old_version, new_version, "content", cleanup="efficiency")
Of the two cleanup styles, the one that generally produces the best result is 'semantic'.
Admin Integration
-----------------
The admin integration for django-reversion does not currently support diff generation. This is a deliberate design decision, as it would make the framework a lot more heavyweight, as well as carrying the risk of confusing non-technical end users.
While future versions may support a more advanced admin class, for the time being it is left up to your own imagination for ways in which to integrate diffs with your project.
One example might be to use django-reversion-compare, see `django-reversion-compare `_.
django-reversion-release-1.10.0/docs/django-versions.rst 0000664 0000000 0000000 00000003145 12627540154 0023266 0 ustar 00root root 0000000 0000000 .. _django-versions:
Compatible Django Versions
==========================
django-reversion is an actively-maintained project, and aims to stay compatible with the latest version of Django. Unfortunately, this means that the latest release of django-reversion might not work with older versions of Django.
If you are using anything other than the latest release of Django, it is important that you check the table below to ensure that your django-reversion download will be compatible.
============== =================
Django version Reversion release
============== =================
1.7+ 1.10.0
1.6+ 1.8.5
1.5.1+ 1.7.1
1.5 1.7
1.4.4+ 1.6.6
1.4.3 1.6.5
1.4.2 1.6.4
1.4.1 1.6.3
1.4 1.6.1
1.3.6 1.5.7
1.3.5 1.5.6
1.3.4 1.5.5
1.3.3 1.5.4
1.3.2 1.5.3
1.3.1 1.5.2
1.3 1.5
1.2.5 1.3.3
1.2.4 1.3.3
1.2.3 1.3.2
1.2 1.3
1.1.1 1.2.1
1.1 1.2
1.0.4 1.1.2
1.0.3 1.1.2
1.0.2 1.1.1
============== =================
Getting the code
----------------
All django-reversion releases are available from the `project downloads area `_. You can also use Git to checkout tags from the `public git repository `_.
There are a number of alternative methods you can use when installing django-reversion. Please check the :ref:`installation methods ` page for more information.
django-reversion-release-1.10.0/docs/how-it-works.rst 0000664 0000000 0000000 00000005504 12627540154 0022531 0 ustar 00root root 0000000 0000000 .. _how-it-works:
How it works
============
Saving Revisions
----------------
Enabling version control for a model is achieved using the ``revisions.register`` method. This registers the version control machinery with the ``post_save`` signal for that model, allowing new changes to the model to be caught.
::
from reversion import revisions
revisions.register(YourModel)
Any models that use subclasses of ``VersionAdmin`` in the admin interface will be automatically registered with django-reversion. As such, it is only necessary to manually register these models if you wish to override the default registration settings.
Whenever you save changes to a model, it is serialized using the Django serialization framework into a JSON string. This is saved to the database as a ``reversion.models.Version`` model. Each ``Version`` model is linked to a model instance using a ``GenericForeignKey``.
Foreign keys and many-to-many relationships are normally saved as their primary keys only. However, the ``revisions.register`` method takes an optional follow clause allowing these relationships to be automatically added to revisions. Please see :ref:`Low Level API ` for more information.
Reverting Versions
------------------
Reverting a version is simply a matter of loading the appropriate ``Version`` model from the database, deserializing the model data, and re-saving the old data.
There are a number of utility methods present on the ``Version`` object manager to assist this process. Please see :ref:`Low Level API ` for more information.
Revision Management
-------------------
Related changes to models are grouped together in revisions. This allows for atomic rollback from one revision to another. You can automate revision management using either ``reversion.middleware.RevisionMiddleware``, or the ``reversion.create_revision`` decorator.
For more information on creating revisions, please see :ref:`Low Level API `.
Admin Integration
-----------------
Full admin integration is achieved using the ``reversion.admin.VersionAdmin`` class. This will create a new revision whenever a model is edited using the admin interface. Any models registered for version control, including inline models, will be included in this revision.
The ``object_history`` view is extended to make each ``LogEntry`` a link that can be used to revert the model back to the most recent version at the time the ``LogEntry`` was created.
Choosing to revert a model will display the standard model change form. The fields in this form are populated using the data contained in the revision corresponding to the chosen ``LogEntry``. Saving this form will result in a new revision being created containing the new model data.
For most projects, simply registering a model with a subclass of ``VersionAdmin`` is enough to satisfy all its version-control needs.
django-reversion-release-1.10.0/docs/index.rst 0000664 0000000 0000000 00000003625 12627540154 0021270 0 ustar 00root root 0000000 0000000 .. _index:
django-reversion documentation
==============================
Getting started with django-reversion
-------------------------------------
To install django-reversion, follow these steps:
1. Install with pip: ``pip install django-reversion``.
2. Add ``'reversion'`` to ``INSTALLED_APPS``.
3. Run ``manage.py migrate``.
If you have installed anything other than the latest version of Django, please check the :ref:`compatible Django versions ` page before installing django-reversion.
There are a number of alternative methods you can use when installing django-reversion. Please check the :ref:`installation methods ` page for more information.
Admin integration
-----------------
django-reversion can be used to add a powerful rollback and recovery facility to your admin site. To enable this, simply register your models with a subclass of ``reversion.VersionAdmin``::
from reversion.admin import VersionAdmin
class YourModelAdmin(VersionAdmin):
pass
admin.site.register(YourModel, YourModelAdmin)
Whenever you register a model with the ``VersionAdmin`` class, be sure to run the ``./manage.py createinitialrevisions`` command to populate the version database with an initial set of model data. Depending on the number of rows in your database, this command could take a while to execute.
For more information about admin integration, please read the :ref:`admin integration ` documentation.
Low Level API
-------------
You can use django-reversion's API to build powerful version-controlled views. For more information, please read the :ref:`low level API ` documentation.
More information
----------------
Installation
^^^^^^^^^^^^
.. toctree::
:maxdepth: 1
installation
django-versions
migrations
admin
Further reading
^^^^^^^^^^^^^^^
.. toctree::
:maxdepth: 1
api
commands
signals
how-it-works
diffs
django-reversion-release-1.10.0/docs/installation.rst 0000664 0000000 0000000 00000002434 12627540154 0022657 0 ustar 00root root 0000000 0000000 .. _installation:
Installation methods
====================
**Note:** It is recommended that you always use the latest release of django-reversion with the latest release of Django. If you are using an older version of Django, then please check out the :ref:`Compatible Django Versions ` page for more information.
For information on configuring django-reversion, see the :ref:`getting started ` guide.
pip
---
You can install django-reversion into your system, or virtual environment, by running the following command in a terminal::
$ pip install django-reversion
easy_install
------------
The popular easy_install utility can be used to install the latest django-reversion release from the Python Package Index. Simply run the following command in a terminal::
$ sudo easy_install django-reversion
Git
---
Using Git to install django-reversion provides an easy way of upgrading your installation at a later date. Simply clone the `public git repository `_ and symlink the ``src/reversion`` directory into your ``PYTHONPATH``::
$ git clone git://github.com/etianen/django-reversion.git
$ cd django-reversion.git
$ git checkout release-1.9.3
$ ln -s src/reversion /your/pythonpath/location/reversion
django-reversion-release-1.10.0/docs/make.bat 0000664 0000000 0000000 00000011774 12627540154 0021040 0 ustar 00root root 0000000 0000000 @ECHO OFF
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=_build
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
set I18NSPHINXOPTS=%SPHINXOPTS% .
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^` where ^ is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. singlehtml to make a single large HTML file
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. devhelp to make HTML files and a Devhelp project
echo. epub to make an epub
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. text to make text files
echo. man to make manual pages
echo. texinfo to make Texinfo files
echo. gettext to make PO message catalogs
echo. changes to make an overview over all changed/added/deprecated items
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
goto end
)
if "%1" == "html" (
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
goto end
)
if "%1" == "singlehtml" (
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\django-reversion.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\django-reversion.ghc
goto end
)
if "%1" == "devhelp" (
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished.
goto end
)
if "%1" == "epub" (
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The epub file is in %BUILDDIR%/epub.
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
if errorlevel 1 exit /b 1
echo.
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "text" (
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The text files are in %BUILDDIR%/text.
goto end
)
if "%1" == "man" (
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The manual pages are in %BUILDDIR%/man.
goto end
)
if "%1" == "texinfo" (
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
goto end
)
if "%1" == "gettext" (
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
if errorlevel 1 exit /b 1
echo.
echo.The overview file is in %BUILDDIR%/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
if errorlevel 1 exit /b 1
echo.
echo.Link check complete; look for any errors in the above output ^
or in %BUILDDIR%/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
if errorlevel 1 exit /b 1
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in %BUILDDIR%/doctest/output.txt.
goto end
)
:end
django-reversion-release-1.10.0/docs/migrations.rst 0000664 0000000 0000000 00000004464 12627540154 0022337 0 ustar 00root root 0000000 0000000 .. _migrations:
Schema migrations
=================
This page describes the schema migrations that have taken place over the lifetime of django-reversion, along with a how-to guide for updating your schema.
django-reversion 1.8.3
----------------------
This release adds an index to the ``date_created`` column on the ``reversion_revision`` table.
In order to apply this migration using south, simply run::
./manage.py migrate reversion
**Important:** South 1.0 or greater is required to run these migrations.
This release also starts using the django core `migrations framework `_, which is intended to be used as the community standard going forwards. To `upgrade from south `_, please complete the following steps:
1. Ensure that your app is up-to-date with all django-reversion migrations.
2. Upgrade to Django 1.7 or greater.
3. Remove ``'south'`` from ``INSTALLED_APPS``.
4. Run ``./manage.py migrate reversion``.
The legacy south migrations will be removed from django-reversion in release 1.9.
django-reversion 1.8
--------------------
This release removes ``type`` column from ``reversion_version`` table.
In order to apply this migration using south, simply run::
./manage.py migrate reversion
django-reversion 1.5
--------------------
This release adds in significant speedups for models with integer primary keys.
In order to apply this migration using south, simply run::
./manage.py migrate reversion
If you have a large amount of existing version data, then this command might take a little while to run while the database tables are updated.
django-reversion 1.4
--------------------
This release added a much-requested 'type' field to Version models, allows statistic to be gathered about the number of additions, changes and deletions that have been applied to a model.
In order to apply this migration, it is first necessary to install South.
1. Add 'south' to your ``INSTALLED_APPS`` setting.
2. Run ``./manage.py syncdb``
You then need to run the following two commands to complete the migration::
./manage.py migrate reversion 0001 --fake
./manage.py migrate reversion
django-reversion 1.3.3
----------------------
No migration needed.
django-reversion-release-1.10.0/docs/signals.rst 0000664 0000000 0000000 00000003346 12627540154 0021621 0 ustar 00root root 0000000 0000000 .. _signals:
Signals sent by django-reversion
================================
django-reversion provides a number of custom signals that can be used to tie-in additional functionality to the version creation mechanism.
reversion.signals.pre_revision_commit
-------------------------------------
This signal is triggered just before a revision is saved to the database. It receives the following keyword arguments:
* **instances** - A list of the model instances in the revision.
* **revision** - The unsaved Revision model.
* **versions** - The unsaved Version models in the revision.
reversion.signals..post_revision_commit
---------------------------------------
This signal is triggered just after a revision is saved to the database. It receives the following keyword arguments:
* **instances** - A list of the model instances in the revision.
* **revision** - The saved Revision model.
* **versions** - The saved Version models in the revision.
Connecting to signals
---------------------
The signals listed above are sent only once *per revision*, rather than once *per model in the revision*. In practice, this means that you should connect to the signals without specifying a `sender`, as below::
def on_revision_commit(**kwargs):
pass # Your signal handler code here.
reversion.post_revision_commit.connect(on_revision_commit)
To execute code only when a revision has been saved for a particular Model, you should inspect the contents of the `instances` parameter, as below::
def on_revision_commit(instances, **kwargs):
for instance in instances:
if isinstance(instance, MyModel):
pass # Your signal handler code here.
reversion.post_revision_commit.connect(on_revision_commit)
django-reversion-release-1.10.0/setup.py 0000664 0000000 0000000 00000003463 12627540154 0020211 0 ustar 00root root 0000000 0000000 import sys
sys.path.insert(0, "src")
from setuptools import setup, find_packages
from reversion import __version__
# Load in babel support, if available.
try:
from babel.messages import frontend as babel
cmdclass = {"compile_catalog": babel.compile_catalog,
"extract_messages": babel.extract_messages,
"init_catalog": babel.init_catalog,
"update_catalog": babel.update_catalog,}
except ImportError:
cmdclass = {}
setup(
name = "django-reversion",
version = '.'.join(str(x) for x in __version__),
license = "BSD",
description = "An extension to the Django web framework that provides comprehensive version control facilities",
author = "Dave Hall",
author_email = "dave@etianen.com",
url = "http://github.com/etianen/django-reversion",
zip_safe = False,
packages = find_packages("src"),
package_dir = {
"": "src",
},
package_data = {
"reversion": ["locale/*/LC_MESSAGES/django.*", "templates/reversion/*.html"]},
cmdclass = cmdclass,
install_requires = [
"django>=1.7",
],
extras_require = {
"diff": [
"diff_match_patch",
],
"test": [
"coverage",
],
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
"Framework :: Django",
]
)
django-reversion-release-1.10.0/src/ 0000775 0000000 0000000 00000000000 12627540154 0017260 5 ustar 00root root 0000000 0000000 django-reversion-release-1.10.0/src/reversion/ 0000775 0000000 0000000 00000000000 12627540154 0021274 5 ustar 00root root 0000000 0000000 django-reversion-release-1.10.0/src/reversion/__init__.py 0000664 0000000 0000000 00000000273 12627540154 0023407 0 ustar 00root root 0000000 0000000 """
Transactional version control for Django models.
Developed by Dave Hall.
"""
from __future__ import unicode_literals
__version__ = VERSION = (1, 10, 0)
django-reversion-release-1.10.0/src/reversion/admin.py 0000664 0000000 0000000 00000031176 12627540154 0022746 0 ustar 00root root 0000000 0000000 """Admin extensions for django-reversion."""
from __future__ import unicode_literals
from contextlib import contextmanager
from django.db import models, transaction, connection
from django.conf.urls import url
from django.contrib import admin
from django.contrib.admin import options
try:
from django.contrib.admin.utils import unquote, quote
except ImportError: # Django < 1.7 pragma: no cover
from django.contrib.admin.util import unquote, quote
try:
from django.contrib.contenttypes.admin import GenericInlineModelAdmin
from django.contrib.contenttypes.fields import GenericRelation
except ImportError: # Django < 1.9 pragma: no cover
from django.contrib.contenttypes.generic import GenericInlineModelAdmin, GenericRelation
from django.core.urlresolvers import reverse
from django.core.exceptions import PermissionDenied, ImproperlyConfigured
from django.shortcuts import get_object_or_404, render
from django.utils.text import capfirst
from django.utils.translation import ugettext as _
from django.utils.encoding import force_text
from django.utils.formats import localize
from reversion.models import Version
from reversion.revisions import default_revision_manager
class RollBackRevisionView(Exception):
pass
class VersionAdmin(admin.ModelAdmin):
"""Abstract admin class for handling version controlled models."""
object_history_template = "reversion/object_history.html"
change_list_template = "reversion/change_list.html"
revision_form_template = None
recover_list_template = None
recover_form_template = None
# The revision manager instance used to manage revisions.
revision_manager = default_revision_manager
# The serialization format to use when registering models with reversion.
reversion_format = "json"
# Whether to ignore duplicate revision data.
ignore_duplicate_revisions = False
# If True, then the default ordering of object_history and recover lists will be reversed.
history_latest_first = False
# Revision helpers.
@property
def revision_context_manager(self):
"""The revision context manager for this VersionAdmin."""
return self.revision_manager._revision_context_manager
def _get_template_list(self, template_name):
opts = self.model._meta
return (
"reversion/%s/%s/%s" % (opts.app_label, opts.object_name.lower(), template_name),
"reversion/%s/%s" % (opts.app_label, template_name),
"reversion/%s" % template_name,
)
def _order_version_queryset(self, queryset):
"""Applies the correct ordering to the given version queryset."""
if self.history_latest_first:
return queryset.order_by("-pk")
return queryset.order_by("pk")
@contextmanager
def _create_revision(self, request):
with transaction.atomic(), self.revision_context_manager.create_revision():
self.revision_context_manager.set_user(request.user)
self.revision_context_manager.set_ignore_duplicates(self.ignore_duplicate_revisions)
yield
# Messages.
def log_addition(self, request, object, change_message=None):
change_message = change_message or _("Initial version.")
self.revision_context_manager.set_comment(change_message)
try:
super(VersionAdmin, self).log_addition(request, object, change_message)
except TypeError: # Django < 1.9 pragma: no cover
super(VersionAdmin, self).log_addition(request, object)
def log_change(self, request, object, message):
self.revision_context_manager.set_comment(message)
super(VersionAdmin, self).log_change(request, object, message)
# Auto-registration.
def _autoregister(self, model, follow=None):
"""Registers a model with reversion, if required."""
if not self.revision_manager.is_registered(model):
follow = follow or []
# Use model_meta.concrete_model to catch proxy models
for parent_cls, field in model._meta.concrete_model._meta.parents.items():
follow.append(field.name)
self._autoregister(parent_cls)
self.revision_manager.register(model, follow=follow, format=self.reversion_format)
def _introspect_inline_admin(self, inline):
"""Introspects the given inline admin, returning a tuple of (inline_model, follow_field)."""
inline_model = None
follow_field = None
fk_name = None
if issubclass(inline, GenericInlineModelAdmin):
inline_model = inline.model
ct_field = inline.ct_field
fk_name = inline.ct_fk_field
for field in self.model._meta.virtual_fields:
if isinstance(field, GenericRelation) and field.rel.to == inline_model and field.object_id_field_name == fk_name and field.content_type_field_name == ct_field:
follow_field = field.name
break
elif issubclass(inline, options.InlineModelAdmin):
inline_model = inline.model
fk_name = inline.fk_name
if not fk_name:
for field in inline_model._meta.fields:
if isinstance(field, (models.ForeignKey, models.OneToOneField)) and issubclass(self.model, field.rel.to):
fk_name = field.name
break
if fk_name and not inline_model._meta.get_field(fk_name).rel.is_hidden():
accessor = inline_model._meta.get_field(fk_name).related.get_accessor_name()
follow_field = accessor
return inline_model, follow_field, fk_name
def __init__(self, *args, **kwargs):
"""Initializes the VersionAdmin"""
super(VersionAdmin, self).__init__(*args, **kwargs)
# Check that database transactions are supported.
if not connection.features.uses_savepoints: # pragma: no cover
raise ImproperlyConfigured("Cannot use VersionAdmin with a database that does not support savepoints.")
# Automatically register models if required.
if not self.revision_manager.is_registered(self.model):
inline_fields = []
for inline in self.inlines:
inline_model, follow_field, _ = self._introspect_inline_admin(inline)
if inline_model:
self._autoregister(inline_model)
if follow_field:
inline_fields.append(follow_field)
self._autoregister(self.model, inline_fields)
def get_urls(self):
"""Returns the additional urls used by the Reversion admin."""
urls = super(VersionAdmin, self).get_urls()
admin_site = self.admin_site
opts = self.model._meta
info = opts.app_label, opts.model_name,
reversion_urls = [
url("^recover/$", admin_site.admin_view(self.recoverlist_view), name='%s_%s_recoverlist' % info),
url("^recover/([^/]+)/$", admin_site.admin_view(self.recover_view), name='%s_%s_recover' % info),
url("^([^/]+)/history/([^/]+)/$", admin_site.admin_view(self.revision_view), name='%s_%s_revision' % info),]
return reversion_urls + urls
# Views.
def add_view(self, request, form_url='', extra_context=None):
with self._create_revision(request):
return super(VersionAdmin, self).add_view(request, form_url, extra_context)
def change_view(self, request, object_id, form_url='', extra_context=None):
with self._create_revision(request):
return super(VersionAdmin, self).change_view(request, object_id, form_url, extra_context)
def revisionform_view(self, request, version, template_name, extra_context=None):
try:
with transaction.atomic():
# Revert the revision.
version.revision.revert(delete=True)
# Run the normal changeform view.
with self._create_revision(request):
response = self.changeform_view(request, version.object_id, request.path, extra_context)
# Decide on whether the keep the changes.
if request.method == "POST" and response.status_code == 302:
self.revision_context_manager.set_comment(_("Reverted to previous version, saved on %(datetime)s") % {"datetime": localize(version.revision.date_created)})
else:
response.template_name = template_name # Set the template name to the correct template.
response.render() # Eagerly render the response, so it's using the latest version of the database.
raise RollBackRevisionView # Raise an exception to undo the transaction and the revision.
except RollBackRevisionView:
pass
return response
def recover_view(self, request, version_id, extra_context=None):
"""Displays a form that can recover a deleted model."""
# The revisionform view will check for change permission (via changeform_view),
# but we also need to check for add permissions here.
if not self.has_add_permission(request): # pragma: no cover
raise PermissionDenied
# Render the recover view.
version = get_object_or_404(Version, pk=version_id)
return self.revisionform_view(request, version, self.recover_form_template or self._get_template_list("recover_form.html"), {
"title": _("Recover %(name)s") % {"name": version.object_repr},
})
def revision_view(self, request, object_id, version_id, extra_context=None):
"""Displays the contents of the given revision."""
object_id = unquote(object_id) # Underscores in primary key get quoted to "_5F"
version = get_object_or_404(Version, pk=version_id, object_id=object_id)
return self.revisionform_view(request, version, self.revision_form_template or self._get_template_list("revision_form.html"), {
"title": _("Revert %(name)s") % {"name": version.object_repr},
})
def changelist_view(self, request, extra_context=None):
"""Renders the change view."""
with self._create_revision(request):
context = {
"has_change_permission": self.has_change_permission(request),
}
context.update(extra_context or {})
return super(VersionAdmin, self).changelist_view(request, context)
def recoverlist_view(self, request, extra_context=None):
"""Displays a deleted model to allow recovery."""
# Check if user has change or add permissions for model
if not self.has_change_permission(request) or not self.has_add_permission(request): # pragma: no cover
raise PermissionDenied
model = self.model
opts = model._meta
deleted = self._order_version_queryset(self.revision_manager.get_deleted(self.model))
# Get the site context.
try:
each_context = self.admin_site.each_context(request)
except TypeError: # Django <= 1.7 pragma: no cover
each_context = self.admin_site.each_context()
# Get the rest of the context.
context = dict(
each_context,
opts = opts,
app_label = opts.app_label,
module_name = capfirst(opts.verbose_name),
title = _("Recover deleted %(name)s") % {"name": force_text(opts.verbose_name_plural)},
deleted = deleted,
)
context.update(extra_context or {})
return render(request, self.recover_list_template or self._get_template_list("recover_list.html"), context)
def history_view(self, request, object_id, extra_context=None):
"""Renders the history view."""
# Check if user has change permissions for model
if not self.has_change_permission(request): # pragma: no cover
raise PermissionDenied
object_id = unquote(object_id) # Underscores in primary key get quoted to "_5F"
opts = self.model._meta
action_list = [
{
"revision": version.revision,
"url": reverse("%s:%s_%s_revision" % (self.admin_site.name, opts.app_label, opts.model_name), args=(quote(version.object_id), version.id)),
}
for version
in self._order_version_queryset(self.revision_manager.get_for_object_reference(
self.model,
object_id,
).select_related("revision__user"))
]
# Compile the context.
context = {"action_list": action_list}
context.update(extra_context or {})
return super(VersionAdmin, self).history_view(request, object_id, context)
django-reversion-release-1.10.0/src/reversion/errors.py 0000664 0000000 0000000 00000000545 12627540154 0023166 0 ustar 00root root 0000000 0000000 class RevertError(Exception):
"""Exception thrown when something goes wrong with reverting a model."""
class RevisionManagementError(Exception):
"""Exception that is thrown when something goes wrong with revision managment."""
class RegistrationError(Exception):
"""Exception thrown when registration with django-reversion goes wrong."""
django-reversion-release-1.10.0/src/reversion/helpers.py 0000664 0000000 0000000 00000006007 12627540154 0023313 0 ustar 00root root 0000000 0000000 """A number of useful helper functions to automate common tasks."""
from __future__ import unicode_literals
from django.contrib import admin
from django.contrib.admin.sites import NotRegistered
from django.utils.encoding import force_text
from reversion.admin import VersionAdmin
def patch_admin(model, admin_site=None):
"""
Enables version control with full admin integration for a model that has
already been registered with the django admin site.
This is excellent for adding version control to existing Django contrib
applications.
"""
admin_site = admin_site or admin.site
try:
ModelAdmin = admin_site._registry[model].__class__
except KeyError:
raise NotRegistered("The model {model} has not been registered with the admin site.".format(
model = model,
))
# Unregister existing admin class.
admin_site.unregister(model)
# Register patched admin class.
class PatchedModelAdmin(VersionAdmin, ModelAdmin):
pass
admin_site.register(model, PatchedModelAdmin)
# Patch generation methods, only available if the google-diff-match-patch
# library is installed.
#
# http://code.google.com/p/google-diff-match-patch/
try:
from diff_match_patch import diff_match_patch
except ImportError: # pragma: no cover
pass
else:
dmp = diff_match_patch()
def generate_diffs(old_version, new_version, field_name, cleanup):
"""Generates a diff array for the named field between the two versions."""
# Extract the text from the versions.
old_text = old_version.field_dict[field_name] or ""
new_text = new_version.field_dict[field_name] or ""
# Generate the patch.
diffs = dmp.diff_main(force_text(old_text), force_text(new_text))
if cleanup == "semantic":
dmp.diff_cleanupSemantic(diffs)
elif cleanup == "efficiency":
dmp.diff_cleanupEfficiency(diffs)
elif cleanup is None:
pass
else: # pragma: no cover
raise ValueError("cleanup parameter should be one of 'semantic', 'efficiency' or None.")
return diffs
def generate_patch(old_version, new_version, field_name, cleanup=None):
"""
Generates a text patch of the named field between the two versions.
The cleanup parameter can be None, "semantic" or "efficiency" to clean up the diff
for greater human readibility.
"""
diffs = generate_diffs(old_version, new_version, field_name, cleanup)
patch = dmp.patch_make(diffs)
return dmp.patch_toText(patch)
def generate_patch_html(old_version, new_version, field_name, cleanup=None):
"""
Generates a pretty html version of the differences between the named
field in two versions.
The cleanup parameter can be None, "semantic" or "efficiency" to clean up the diff
for greater human readibility.
"""
diffs = generate_diffs(old_version, new_version, field_name, cleanup)
return dmp.diff_prettyHtml(diffs)
django-reversion-release-1.10.0/src/reversion/locale/ 0000775 0000000 0000000 00000000000 12627540154 0022533 5 ustar 00root root 0000000 0000000 django-reversion-release-1.10.0/src/reversion/locale/ar/ 0000775 0000000 0000000 00000000000 12627540154 0023135 5 ustar 00root root 0000000 0000000 django-reversion-release-1.10.0/src/reversion/locale/ar/LC_MESSAGES/ 0000775 0000000 0000000 00000000000 12627540154 0024722 5 ustar 00root root 0000000 0000000 django-reversion-release-1.10.0/src/reversion/locale/ar/LC_MESSAGES/django.mo 0000664 0000000 0000000 00000005115 12627540154 0026523 0 ustar 00root root 0000000 0000000 | L Q > B D H Y r 3 P ( X H p l ] l F B
M ) c = Z <