• Stars
    star
    311
  • Rank 134,521 (Top 3 %)
  • Language
    Python
  • Created over 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Add compare view to django-reversion for comparing two versions of a reversion model.

django-reversion-compare

tests codecov django-reversion-compare @ PyPi Python Versions License GPL-3.0-or-later

django-reversion-compare is an extension to django-reversion that provides a history compare view to compare two versions of a model which is under reversion.

Comparing model versions is not a easy task. Maybe there are different view how this should looks like. This project will gives you a generic way to see whats has been changed.

Many parts are customizable by overwrite methods or subclassing, see above.

Installation

Just use:

pip install django-reversion-compare

Setup

Add reversion_compare to INSTALLED_APPS in your settings.py, e.g.:

INSTALLED_APPS = (
    'django...',
    ...
    'reversion', # https://github.com/etianen/django-reversion
    'reversion_compare', # https://github.com/jedie/django-reversion-compare
    ...
)

# Add reversion models to admin interface:
ADD_REVERSION_ADMIN=True
# optional settings:
REVERSION_COMPARE_FOREIGN_OBJECTS_AS_ID=False
REVERSION_COMPARE_IGNORE_NOT_REGISTERED=False

Usage

Inherit from CompareVersionAdmin instead of VersionAdmin to get the comparison feature.

admin.py e.g.:

from django.contrib import admin
from reversion_compare.admin import CompareVersionAdmin

from my_app.models import ExampleModel

@admin.register(ExampleModel)
class ExampleModelAdmin(CompareVersionAdmin):
    pass

If you're using an existing third party app, then you can add patch django-reversion-compare into its admin class by using the reversion_compare.helpers.patch_admin() method. For example, to add version control to the built-in User model:

from reversion_compare.helpers import patch_admin

patch_admin(User)

e.g.: Add django-cms Page model:

from cms.models.pagemodel import Page
from reversion_compare.helpers import patch_admin


# Patch django-cms Page Model to add reversion-compare functionality:
patch_admin(Page)

Customize

It's possible to change the look for every field or for a entire field type. You must only define a methods to your admin class with this name scheme:

  • "compare_%s" % field_name
  • "compare_%s" % field.get_internal_type()

If there is no method with this name scheme, the fallback_compare() method will be used.

An example for specifying a compare method for a model field by name:

class YourAdmin(CompareVersionAdmin):
    def compare_foo_bar(self, obj_compare):
        """ compare the foo_bar model field """
        return "%r <-> %r" % (obj_compare.value1, obj_compare.value2)

and example using patch_admin with custom version admin class:

patch_admin(User, AdminClass=YourAdmin)

Class Based View

Beyond the Admin views, you can also create a Class Based View for displaying and comparing version differences. This is a single class-based-view that either displays the list of versions to select for an object or displays both the versions and their differences (if the versions to be compared have been selected). This class can be used just like a normal DetailView:

More information about this can be found in DocString of:

The make run-test-server test project contains a Demo, use the links under:

HistoryCompareDetailView Examples:

Screenshots

Here some screenshots of django-reversion-compare:


How to select the versions to compare:

django-reversion-compare_v0_1_0-01.png


from v0.1.0: DateTimeField compare (last update), TextField compare (content) with small changes and a ForeignKey compare (child model instance was added):

django-reversion-compare_v0_1_0-02.png


from v0.1.0: Same as above, but the are more lines changed in TextField and the ForeignKey relation was removed:

django-reversion-compare_v0_1_0-03.png


Example screenshot from v0.3.0: a many-to-many field compare (friends, hobbies):

django-reversion-compare_v0_3_0-01.png

  • In the first line, the m2m object has been changed.
  • line 2: A m2m object was deleted
  • line 3: A m2m object was removed from this entry (but not deleted)
  • line 4: This m2m object has not changed

create developer environment

We use manage_django_project, so you just need to clone the sources and call manage.py to start hacking.

e.g.:

~$ git clone https://github.com/jedie/django-reversion-compare.git
~$ cd django-reversion-compare

# Just call manage.py and the magic happen:
~/django-reversion-compare$ ./manage.py

# start local dev. web server:
~/django-reversion-compare$ ./manage.py run_dev_server

# run tests:
~/django-reversion-compare$ ./manage.py test
# or with coverage
~/django-reversion-compare$ ./manage.py coverage
# or via tox:
~/django-reversion-compare$ ./manage.py tox p

Backwards-incompatible changes

v0.16.0

We use https://github.com/jedie/manage_django_project to manage the dev venv and we switch to main branch.

You must reinit your dev setup.

v0.12.0

Google "diff-match-patch" is now mandatory and not optional.

Version compatibility

Reversion-Compare django-reversion Django Python
>=v0.16.0 v3.0 v3.2, v4.1, v4.2 v3.9, v3.10, v3.11
>=v0.15.0 v3.0 v2.2, v3.2, v4.0 v3.7, v3.8, v3.9
>=v0.13.0 v3.0 v2.2, v3.0, v3.1 v3.7, v3.8, v3.9
>=v0.10.0 v3.0 v2.2, v3.0 v3.6, v3.7, v3.8, pypy3
>=v0.9.0 v2.0 v2.2, v3.0 v3.6, v3.7, v3.8, pypy3
>=v0.8.6 v2.0 v1.11, v2.0 v3.5, v3.6, v3.7, pypy3
>=v0.8.4 v2.0 v1.8, v1.11, v2.0 v3.5, v3.6, pypy3
>=v0.8.3 v2.0 v1.8, v1.11 v3.5, v3.6, pypy3
v0.8.x v2.0 v1.8, v1.10, v1.11 v2.7, v3.4, v3.5, v3.6 (only with Django 1.11)
>=v0.7.2 v2.0 v1.8, v1.9, v1.10 v2.7, v3.4, v3.5
v0.7.x v2.0 v1.8, v1.9 v2.7, v3.4, v3.5
v0.6.x v1.9, v1.10 v1.8, v1.9 v2.7, v3.4, v3.5
>=v0.5.2 v1.9 v1.7, v1.8 v2.7, v3.4
>=v0.4 v1.8 v1.7 v2.7, v3.4
<v0.4 v1.6 v1.4 v2.7

These are the unittests variants. See also: /pyproject.toml Maybe other versions are compatible, too.

Changelog

Links

| Github | https://github.com/jedie/django-reversion-compare | | Python Packages | https://pypi.org/project/django-reversion-compare/ |

Donation

More Repositories

1

django-tools

miscellaneous django tools
Python
129
star
2

PyLucid

PyLucid is ready to use Django-CMS setup
JavaScript
72
star
3

python-creole

Creole markup tools written in Python.
Python
60
star
4

django-for-runners

Store your GPX tracks of your running (or other sports activity) in django.
JavaScript
56
star
5

DragonPy

Emulator for 6809 CPU based system like Dragon 32 / CoCo written in Python...
Python
40
star
6

python-code-snippets

miscellaneous Python code snippets for several use.
Python
35
star
7

inverter-connect

Get information from Deye Microinverter
Python
19
star
8

micropython-sonoff-webswitch

MicroPython project to free the Sonoff WiFi Smart Socket from the cloud by run a webserver on the device.
Python
18
star
9

PyInventory

Web based management to catalog things including state and location etc. using Python/Django.
Python
17
star
10

NAS7820-Tools

Scripts/Tools around NAS7820 Platform
Shell
16
star
11

django-phpBB3

django database models of phpBB3 **unmaintained**
Python
16
star
12

PyHardLinkBackup

Hardlink/Deduplication Backups with Python
Python
16
star
13

kivy-buildozer-docker

Build kivy app apk via buildozer on Travis-CI with docker...
Dockerfile
15
star
14

django-processinfo

Django-app for collecting information from running django processes.
Python
15
star
15

lineageos_info

overview of all supported LineageOS v16 & v17 devices
Python
13
star
16

django-kippo

Django App for kippo SSH Honeypot: https://code.google.com/p/kippo/
Python
11
star
17

XRoar

inofficial mirror of http://www.6809.org.uk/dragon/xroar.shtml (licensed under GNU GPL v2 or above)
C
9
star
18

docker-micropython

Docker image to compile micropython and freeze modules: https://hub.docker.com/r/jedie/micropython
Makefile
8
star
19

poetry-publish

Helper to build and upload a project that used poetry to PyPi, with prechecks
Python
7
star
20

PyOdroidGo

Python
6
star
21

bootstrap_env

Create a complete self contained virtualenv bootstrap file by enbed 'get-pip.py'
Python
5
star
22

3dsmax_bugs

list of annoying 3ds max bugs
5
star
23

PyAdbUninstall

Thinker GUI for uninstall Android Apps via "adb"
Python
4
star
24

manageprojects

Create/update Python / Django projects via CookieCutter Templates
Python
4
star
25

pysmartmeter

Collect data from Hitchi Smartmeter and expose it via MQTT
Python
4
star
26

3dsmax_patches

Bugfixes / Work-a-round for autodesk 3ds max
Python
3
star
27

django-user-secrets

Store user secrets encrypted into database
Python
3
star
28

docker-yaota8266

compile yaota8266 in a docker container by using https://github.com/jedie/yaota8266
Makefile
3
star
29

dev-shell

A "dev-shell" for Python projects ;)
Python
3
star
30

django-cms-tools

Miscellaneous tools/helpers for django-CMS
Python
3
star
31

jedie.github.io

Python
3
star
32

django-debug-toolbar-django-info

django-info panel for django-debug-toolbar
Python
3
star
33

django-timingattack-test

WIP: measure timingattacks against django login
Python
3
star
34

IterFilesystem

Multiprocess directory iteration via os.scandir() with progress indicator via tqdm bars.
Python
3
star
35

PyLucid-Plugins

PyLucid Plugins
Python
2
star
36

WebCrypto-compatibility

"Web Cryptography API" compatibility informations
2
star
37

PyDragon32

Python tools/script around Dragon32/64 homecomputer - moved into DragonPy:
Python
2
star
38

autoaptitude

autoaptitude are some scripts for manage installed packages via aptitude.
Python
2
star
39

PyLucid-boot

**obsolete** - We merged it into https://github.com/jedie/PyLucid/tree/master/bootstrap
Python
2
star
40

RunCalculator

Simple Python/Kivy app to calculate running related stuff...
Python
2
star
41

pybee-docker

Docker containers for the PyBee project
Shell
2
star
42

manage_django_project

manage_django_project is a helper to develop Django projects: Easy bootstrap and (optional) cmd2 shell for all registered manage commands.
Python
2
star
43

DrQueueHelperFiles

Just a few helper bash/batch scripts for DrQueue
Python
1
star
44

PyLucid-KursAnmeldung-plugin

PyLucid Plugin zur Studenten Anmeldung
Python
1
star
45

PyLucid-pre-v0.6-trunk

The first **OLD** releases of PyLucid CMS !!! current development under https://github.com/jedie/PyLucid/ !!!
Python
1
star
46

PyLucid-VideoDatabase-plugin

1
star
47

cookiecutter_templates

CookieCutter Templates for Python / Django packages/projects
Python
1
star
48

pathlib_revised

Python pathlib extension
Python
1
star
49

PyRconShell

Minecraft rcon shell in Python
Python
1
star
50

PyLucid-system-information-plugin

A plugin for PyLucid CMS to get system information (on linux machines)
Python
1
star
51

djangocms-widgets

A widget plugin for djangocms: Include templates into cms pages.
HTML
1
star
52

mp_test_template1

Cookiecutter Test Template 1 for https://github.com/jedie/manageprojects
Python
1
star
53

WebCrypto-bench

Web Cryptography API benchmarks
JavaScript
1
star
54

PyLucid-old-v0.8-trunk

This is the **old** v0.8 trunk from PyLucid. Current development under https://github.com/jedie/PyLucid/ !!!
Python
1
star
55

PyMandelbrot

Mandelbrot set implementation in Python
Python
1
star
56

PyLucid-OpenLayerGPX-plugin

PyLucid CMS plugin for display GPX tracks with OpenLayer/OpenStreetMap
1
star
57

PyLucid-FilebrowserGlue-plugin

Simple glue plugin for using django-filebrowser in PyLucid
Shell
1
star
58

django-fritzconnection

Web based FritzBox management using Python/Django.
Python
1
star
59

BootDrQueue

Bootstrap for https://github.com/kaazoo/DrQueueIPython made with https://github.com/jedie/bootstrap_env
Python
1
star
60

djangobb_project

unofficial mirror of https://bitbucket.org/slav0nic/djangobb_project/
JavaScript
1
star
61

kivyworkshop

Python
1
star
62

compose-services

Docker compose services
Python
1
star
63

PyLucid-djangobb-plugin

PyLucid glue plugin to include DjangoBB forum in PyLucid CMS
Python
1
star
64

device-scan

Python
1
star
65

PyLucid-DecodeUnicode-plugin

PyLucid Plugion: 'DecodeUnicode'
Python
1
star