Skip to content

Commit f13ed41

Browse files
authored
Merge branch 'master' into ExcludeAndIncludeFields
2 parents bd5667c + d76e446 commit f13ed41

28 files changed

+355
-277
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
- DJANGO="Django>=1.7,<1.8"
1414
- DJANGO="Django>=1.8,<1.9"
1515
- DJANGO="Django>=1.9,<1.10"
16+
- DJANGO="Django>=1.10,<1.11"
1617

1718
install:
1819
- pip install -U coverage codecov
@@ -31,5 +32,7 @@ matrix:
3132
env: DJANGO="Django>=1.7,<1.8"
3233
- python: 3.3
3334
env: DJANGO="Django>=1.9,<1.10"
35+
- python: 3.3
36+
env: DJANGO="Django>=1.10,<1.11"
3437

3538
after_success: codecov

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Authors
3333
- Ulysses Vilela
3434
- vnagendra
3535
- Lucas Wiman
36+
- Michael England
3637

3738
Background
3839
==========

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ Changes
33

44
tip (unreleased)
55
----------------
6+
- Added --batchsize option to the populate_history management command.
7+
8+
1.8.2 (2017-01-19)
9+
------------------
610
- Add Polish locale.
11+
- Add Django 1.10 support.
712

813
1.8.1 (2016-03-19)
914
------------------

docs/usage.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ settings:
3737

3838
.. code-block:: python
3939
40-
MIDDLEWARE_CLASSES = [
40+
MIDDLEWARE = [
4141
# ...
4242
'simple_history.middleware.HistoryRequestMiddleware',
4343
]
@@ -83,6 +83,9 @@ initial change for preexisting model instances:
8383
8484
$ python manage.py populate_history --auto
8585
86+
By default, history rows are inserted in batches of 200. This can be changed if needed for large tables
87+
by using the ``--batchsize`` option, for example ``--batchsize 500``.
88+
8689
.. _admin_integration:
8790

8891
Integration with Django Admin
@@ -168,5 +171,6 @@ records for all ``Choice`` instances can be queried by using the manager on the
168171
<simple_history.manager.HistoryManager object at 0x1cc4290>
169172
>>> Choice.history.all()
170173
[<HistoricalChoice: Choice object as of 2010-10-25 18:05:12.183340>, <HistoricalChoice: Choice object as of 2010-10-25 18:04:59.047351>]
171-
172-
Because the history is model, you can also filter it like regulary QuerySets, a.k. Choice.history.filter(choice_text='Not Much') will work!
174+
175+
Because the history is model, you can also filter it like regularly QuerySets,
176+
a.k. Choice.history.filter(choice_text='Not Much') will work!

runtests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
'simple_history.tests',
1717
'simple_history.tests.custom_user',
1818
'simple_history.tests.external',
19-
'simple_history.tests.migration_test_app',
19+
'simple_history.registry_tests.migration_test_app',
2020

2121
'simple_history',
2222

@@ -50,6 +50,7 @@
5050

5151

5252
def main():
53+
5354
if not settings.configured:
5455
settings.configure(**DEFAULT_SETTINGS)
5556
if hasattr(django, 'setup'):
@@ -59,9 +60,10 @@ def main():
5960
except ImportError:
6061
from django.test.simple import DjangoTestSuiteRunner
6162
failures = DjangoTestSuiteRunner(failfast=False).run_tests(['tests'])
63+
failures |= DjangoTestSuiteRunner(failfast=False).run_tests(['registry_tests'])
6264
else:
63-
failures = DiscoverRunner(failfast=False).run_tests(
64-
['simple_history.tests'])
65+
failures = DiscoverRunner(failfast=False).run_tests(['simple_history.tests'])
66+
failures |= DiscoverRunner(failfast=False).run_tests(['simple_history.registry_tests'])
6567
sys.exit(failures)
6668

6769

setup.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
import simple_history
33

44
tests_require = [
5-
'Django>=1.4', 'WebTest==2.0.18', 'django-webtest==1.7.8', 'mock==1.0.1']
6-
try:
7-
from unittest import skipUnless
8-
except ImportError: # Python 2.6 compatibility
9-
tests_require.append("unittest2")
5+
'Django>=1.6', 'WebTest==2.0.24', 'django-webtest==1.8.0', 'mock==1.0.1']
106

117
setup(
128
name='django-simple-history',
@@ -29,7 +25,6 @@
2925
"Environment :: Web Environment",
3026
"Intended Audience :: Developers",
3127
"Programming Language :: Python",
32-
"Programming Language :: Python :: 2.6",
3328
"Programming Language :: Python :: 2.7",
3429
'Programming Language :: Python :: 3',
3530
'Programming Language :: Python :: 3.2',

simple_history/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals
22

3-
__version__ = '1.8.1'
3+
__version__ = '1.8.2'
44

55

66
def register(

simple_history/admin.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
from django.contrib.admin.utils import unquote
1919
except ImportError: # Django < 1.7
2020
from django.contrib.admin.util import unquote
21+
try:
22+
from django.utils.version import get_complete_version
23+
except ImportError:
24+
from django import VERSION
25+
get_complete_version = lambda: VERSION
2126

2227
USER_NATURAL_KEY = tuple(
2328
key.lower() for key in settings.AUTH_USER_MODEL.split('.', 1))
@@ -75,8 +80,10 @@ def history_view(self, request, object_id, extra_context=None):
7580
'admin_user_view': admin_user_view
7681
}
7782
context.update(extra_context or {})
78-
return render(request, template_name=self.object_history_template,
79-
dictionary=context, current_app=request.current_app)
83+
extra_kwargs = {}
84+
if get_complete_version() < (1, 8):
85+
extra_kwargs['current_app'] = request.current_app
86+
return render(request, self.object_history_template, context, **extra_kwargs)
8087

8188
def response_change(self, request, obj):
8289
if '_change_history' in request.POST and SIMPLE_HISTORY_EDIT:
@@ -178,8 +185,10 @@ def history_form_view(self, request, object_id, version_id):
178185
'save_on_top': self.save_on_top,
179186
'root_path': getattr(self.admin_site, 'root_path', None),
180187
}
181-
return render(request, template_name=self.object_history_form_template,
182-
dictionary=context, current_app=request.current_app)
188+
extra_kwargs = {}
189+
if get_complete_version() < (1, 8):
190+
extra_kwargs['current_app'] = request.current_app
191+
return render(request, self.object_history_form_template, context, **extra_kwargs)
183192

184193
def save_model(self, request, obj, form, change):
185194
"""Set special model attribute to user for reference after save"""

simple_history/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
django-simple-history exceptions and warnings classes.
33
"""
44

5+
56
class MultipleRegistrationsError(Exception):
67
"""The model has been registered to have history tracking more than once"""
78
pass

simple_history/management/commands/_populate_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_history_model_for_model(model):
1515
return getattr(model, manager_name).model
1616

1717

18-
def bulk_history_create(model, history_model):
18+
def bulk_history_create(model, history_model, batch_size):
1919
"""Save a copy of all instances to the historical model."""
2020
historical_instances = [
2121
history_model(
@@ -26,4 +26,4 @@ def bulk_history_create(model, history_model):
2626
for field in instance._meta.fields
2727
}
2828
) for instance in model.objects.all()]
29-
history_model.objects.bulk_create(historical_instances)
29+
history_model.objects.bulk_create(historical_instances, batch_size=batch_size)

0 commit comments

Comments
 (0)