Skip to content

Commit

Permalink
Merge branch 'master' into pagination-and-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
RumitAP authored Oct 5, 2023
2 parents a4ff42a + 29108a5 commit 58c18db
Show file tree
Hide file tree
Showing 51 changed files with 347 additions and 86 deletions.
6 changes: 6 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
changelog:
exclude:
authors:
- dependabot
- pre-commit-ci
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
options: --health-cmd="mariadb-admin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install gettext
run: |
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ repos:
- "-x *test*.py"

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
language_version: python3.8

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
args:
Expand Down Expand Up @@ -47,7 +47,7 @@ repos:
- "--strict"

- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.13.0
hooks:
- id: pyupgrade
args: [--py38-plus]
4 changes: 4 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Authors
- Alexander Anikeev
- Amanda Ng (`AmandaCLNg <https://github.com/AmandaCLNg>`_)
- Amartis Gladius (`Amartis <https://github.com/amartis>`_)
- Anton Kulikov (`bigtimecriminal <https://github.com/bigtimecriminal>`_)
- Ben Lawson (`blawson <https://github.com/blawson>`_)
- Benjamin Mampaey (`bmampaey <https://github.com/bmampaey>`_)
- Bheesham Persaud (`bheesham <https://github.com/bheesham>`_)
Expand Down Expand Up @@ -64,6 +65,7 @@ Authors
- Jake Howard (`RealOrangeOne <https://github.com/realorangeone>`_)
- James Muranga (`jamesmura <https://github.com/jamesmura>`_)
- James Pulec
- Jeppe Fihl-Pearson (`Tenzer <https://github.com/Tenzer>`_)
- Jesse Shapiro
- Jihoon Baek (`jihoon796 <https://github.com/jihoon796>`_)
- Jim Gomez
Expand All @@ -90,6 +92,7 @@ Authors
- Lucas Wiman
- Maciej "RooTer" Urbański
- Marcelo Canina (`marcanuy <https://github.com/marcanuy>`_)
- Marco Sirabella
- Mark Davidoff
- Martin Bachwerk
- Marty Alchin
Expand All @@ -105,6 +108,7 @@ Authors
- Nathan Villagaray-Carski (`ncvc <https://github.com/ncvc>`_)
- Nianpeng Li
- Nick Träger
- Noel James (`NoelJames <https://github.com/NoelJames>`_)
- Phillip Marshall
- Prakash Venkatraman (`dopatraman <https://github.com/dopatraman>`_)
- Rajesh Pappula
Expand Down
21 changes: 21 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Changes
Unreleased
----------

- Allow ``HistoricalRecords.m2m_fields`` as str (gh-1243)
- Fixed ``HistoryRequestMiddleware`` deleting non-existent
``HistoricalRecords.context.request`` in very specific circumstances (gh-1256)
- Added ``custom_historical_attrs`` to ``bulk_create_with_history()`` and
``bulk_update_with_history()`` for setting additional fields on custom history models
(gh-1248)
- Passing an empty list as the ``fields`` argument to ``bulk_update_with_history()`` is
now allowed; history records will still be created (gh-1248)
- Added temporary requirement on ``asgiref>=3.6`` while the minimum required Django
version is lower than 4.2 (gh-1261)
- Small performance optimization of the ``clean-duplicate_history`` command (gh-1015)

3.4.0 (2023-08-18)
------------------

- Fixed typos in the docs
- Added feature to evaluate ``history`` model permissions explicitly when
``SIMPLE_HISTORY_ENFORCE_HISTORY_MODEL_PERMISSIONS`` is set to ``True``
Expand All @@ -17,6 +32,12 @@ Unreleased
- Added support for Django 4.2 (gh-1202)
- Made ``bulk_update_with_history()`` return the number of model rows updated (gh-1206)
- Added pagination to ``SimpleHistoryAdmin`` (gh-1220)
- Fixed ``HistoryRequestMiddleware`` not cleaning up after itself (i.e. deleting
``HistoricalRecords.context.request``) under some circumstances (gh-1188)
- Made ``HistoryRequestMiddleware`` async-capable (gh-1209)
- Fixed error when setting ``table_name`` with ``inherit=True`` (gh-1195)
- Fixed ``FieldError`` when creating historical records for many-to-many fields with
``to="self"`` (gh-1218)

3.3.0 (2023-03-08)
------------------
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ django-simple-history
:alt: Documentation Status

.. image:: https://img.shields.io/codecov/c/github/jazzband/django-simple-history/master.svg
:target: http://codecov.io/github/jazzband/django-simple-history?branch=master
:target: https://app.codecov.io/github/jazzband/django-simple-history?branch=master
:alt: Test Coverage

.. image:: https://img.shields.io/pypi/v/django-simple-history.svg
:target: https://pypi.python.org/pypi/django-simple-history
:target: https://pypi.org/project/django-simple-history/
:alt: PyPI Version

.. image:: https://api.codeclimate.com/v1/badges/66cfd94e2db991f2d28a/maintainability
:target: https://codeclimate.com/github/jazzband/django-simple-history/maintainability
:alt: Maintainability

.. image:: https://pepy.tech/badge/django-simple-history
.. image:: https://static.pepy.tech/badge/django-simple-history
:target: https://pepy.tech/project/django-simple-history
:alt: Downloads

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
:target: https://github.com/psf/black
:alt: Code Style

.. image:: https://jazzband.co/static/img/badge.svg
Expand Down
60 changes: 37 additions & 23 deletions docs/common_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ You can also specify a default user or default change reason responsible for the
>>> Poll.history.get(id=data[0].id).history_user == user
True
If you're using `additional fields in historical models`_ and have custom fields to
batch-create into the history, pass the optional dict argument ``custom_historical_attrs``
containing the field names and values.
A field ``session`` would be passed as ``custom_historical_attrs={'session': 'training'}``.

.. _additional fields in historical models: historical_model.html#adding-additional-fields-to-historical-models

.. code-block:: pycon
>>> from simple_history.tests.models import PollWithHistoricalSessionAttr
>>> data = [
PollWithHistoricalSessionAttr(id=x, question=f'Question {x}')
for x in range(10)
]
>>> objs = bulk_create_with_history(
data, PollWithHistoricalSessionAttr,
custom_historical_attrs={'session': 'training'}
)
>>> data[0].history.get().session
'training'
Bulk Updating a Model with History (New)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -88,6 +109,22 @@ default manager returns a filtered set), you can specify which manager to use wi
>>> data = [PollWithAlternativeManager(id=x, question='Question ' + str(x), pub_date=now()) for x in range(1000)]
>>> objs = bulk_create_with_history(data, PollWithAlternativeManager, batch_size=500, manager=PollWithAlternativeManager.all_polls)
If you're using `additional fields in historical models`_ and have custom fields to
batch-update into the history, pass the optional dict argument ``custom_historical_attrs``
containing the field names and values.
A field ``session`` would be passed as ``custom_historical_attrs={'session': 'jam'}``.

.. _additional fields in historical models: historical_model.html#adding-additional-fields-to-historical-models

.. code-block:: pycon
>>> bulk_update_with_history(
data, PollWithHistoricalSessionAttr, [],
custom_historical_attrs={'session': 'jam'}
)
>>> data[0].history.latest().session
'jam'
QuerySet Updates with History (Updated in Django 2.2)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unlike with ``bulk_create``, `queryset updates`_ perform an SQL update query on
Expand Down Expand Up @@ -124,29 +161,6 @@ Tracking Custom Users
cannot be set directly on a swapped user model because of the user
foreign key to track the user making changes.

Using django-webtest with Middleware
------------------------------------

When using django-webtest_ to test your Django project with the
django-simple-history middleware, you may run into an error similar to the
following::

django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`test_env`.`core_historicaladdress`, CONSTRAINT `core_historicaladdress_history_user_id_0f2bed02_fk_user_user_id` FOREIGN KEY (`history_user_id`) REFERENCES `user_user` (`id`))')

.. _django-webtest: https://github.com/django-webtest/django-webtest

This error occurs because ``django-webtest`` sets
``DEBUG_PROPAGATE_EXCEPTIONS`` to true preventing the middleware from cleaning
up the request. To solve this issue, add the following code to any
``clean_environment`` or ``tearDown`` method that
you use:

.. code-block:: python
from simple_history.middleware import HistoricalRecords
if hasattr(HistoricalRecords.context, 'request'):
del HistoricalRecords.context.request
Using F() expressions
---------------------
``F()`` expressions, as described here_, do not work on models that have
Expand Down
7 changes: 5 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

# 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.autodoc"]
extensions = [
"sphinx.ext.autodoc",
"sphinx_rtd_theme",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down Expand Up @@ -93,7 +96,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
# html_theme = 'default'
html_theme = "sphinx_rtd_theme"

# 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
Expand Down
14 changes: 10 additions & 4 deletions docs/historical_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Allow tracking to be inherited

By default history tracking is only added for the model that is passed
to ``register()`` or has the ``HistoricalRecords`` descriptor. By
passing ``inherit=True`` to either way of registering you can change
passing ``inherit=True`` to either way of registering, you can change
that behavior so that any child model inheriting from it will have
historical tracking as well. Be careful though, in cases where a model
can be tracked more than once, ``MultipleRegistrationsError`` will be
Expand All @@ -384,6 +384,9 @@ raised.
Both ``User`` and ``Poll`` in the example above will cause any model
inheriting from them to have historical tracking as well.

**Note:** For parent models having a ``HistoricalRecords`` field with ``inherit=True``
*and* a ``table_name``, the latter option will not be inherited by child models.

History Model In Different App
------------------------------

Expand Down Expand Up @@ -466,9 +469,12 @@ If you want to track many to many relationships, you need to define them explici
This will create a historical intermediate model that tracks each relational change
between `Poll` and `Category`.

You may also define these fields in a model attribute (by default on `_history_m2m_fields`).
This is mainly used for inherited models. You can override the attribute name by setting
your own `m2m_fields_model_field_name` argument on the `HistoricalRecord` instance.
You may use either the name of the field or the field instance itself.

You may also define these fields in a class attribute (by default on `_history_m2m_fields`).
This is mainly used by inherited models not declaring their own `HistoricalRecord`.
You can override the attribute name by setting your own `m2m_fields_model_field_name`
argument on the `HistoricalRecord` instance.

You will see the many to many changes when diffing between two historical records:

Expand Down
8 changes: 4 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ django-simple-history
:alt: Documentation Status

.. image:: https://img.shields.io/codecov/c/github/jazzband/django-simple-history/master.svg
:target: http://codecov.io/github/jazzband/django-simple-history?branch=master
:target: https://app.codecov.io/github/jazzband/django-simple-history?branch=master
:alt: Test Coverage

.. image:: https://img.shields.io/pypi/v/django-simple-history.svg
:target: https://pypi.python.org/pypi/django-simple-history
:target: https://pypi.org/project/django-simple-history/
:alt: PyPI Version

.. image:: https://api.codeclimate.com/v1/badges/66cfd94e2db991f2d28a/maintainability
:target: https://codeclimate.com/github/jazzband/django-simple-history/maintainability
:alt: Maintainability

.. image:: https://pepy.tech/badge/django-simple-history
.. image:: https://static.pepy.tech/badge/django-simple-history
:target: https://pepy.tech/project/django-simple-history
:alt: Downloads

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
:target: https://github.com/psf/black
:alt: Code Style

.. image:: https://jazzband.co/static/img/badge.svg
Expand Down
2 changes: 1 addition & 1 deletion requirements/coverage.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
coverage==7.2.7
coverage==7.3.1
toml==0.10.2
4 changes: 2 additions & 2 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Install this project in editable mode, so that its package metadata can be queried
-e .
Sphinx==6.2.1
sphinx-rtd-theme==1.2.2
Sphinx==7.2.6
sphinx-rtd-theme==1.3.0
4 changes: 2 additions & 2 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
black==23.7.0
flake8==6.0.0
black==23.9.1
flake8==6.1.0
isort==5.12.0
2 changes: 1 addition & 1 deletion requirements/postgres.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DEV: Replace this with `psycopg[binary]` when the minimum required Django version is
# 4.2 or higher, as this is likely to be deprecated in the future
# (see https://docs.djangoproject.com/en/4.2/releases/4.2/#psycopg-3-support)
psycopg2-binary==2.9.6
psycopg2-binary==2.9.8
2 changes: 2 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-r ./coverage.txt
# DEV: Remove this requirement entirely when the minimum required Django version is 4.2
asgiref>=3.6
2 changes: 1 addition & 1 deletion requirements/tox.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-r ./coverage.txt
tox==4.6.4
tox==4.11.3
tox-gh-actions==3.1.3
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"fallback_version": "0.0.0",
},
setup_requires=["setuptools_scm"],
# DEV: Remove `asgiref` when the minimum required Django version is 4.2
install_requires=["asgiref>=3.6"],
description="Store model history and view/revert changes from admin site.",
long_description="\n".join((readme.read(), changes.read())),
long_description_content_type="text/x-rst",
Expand Down
Binary file modified simple_history/locale/ar/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion simple_history/locale/ar/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Project-Id-Version: django-simple-history\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-08 11:30+0300\n"
"PO-Revision-Date: 2022-11-08 13:54+0300\n"
Expand Down
Binary file modified simple_history/locale/cs_CZ/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion simple_history/locale/cs_CZ/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Project-Id-Version: django-simple-history\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-18 21:54+0200\n"
"PO-Revision-Date: 2021-09-20 19:50+0200\n"
Expand Down
Binary file modified simple_history/locale/de/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion simple_history/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Project-Id-Version: django-simple-history\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-21 15:58+0100\n"
"PO-Revision-Date: 2018-11-21 16:31+0100\n"
Expand Down
Binary file modified simple_history/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion simple_history/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Project-Id-Version: django-simple-history\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-04 01:50+0300\n"
"PO-Revision-Date: 2020-04-25 22:50+0200\n"
Expand Down
Binary file modified simple_history/locale/id/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 58c18db

Please sign in to comment.