Skip to content

Commit 4f34cf8

Browse files
authored
Merge branch 'master' into 422-add-history-extra-fields
2 parents cb20c3b + 7dbc000 commit 4f34cf8

File tree

7 files changed

+19
-5
lines changed

7 files changed

+19
-5
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Authors
5151
- Ross Rogers
5252
- Steven Klass
5353
- Steeve Chailloux
54+
- Tommy Beadle (@tbeadle)
5455
- Trey Hunner
5556
- Ulysses Vilela
5657
- vnagendra

CHANGES.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Changes
22
=======
33

44
Unreleased
5-
-----------
5+
----------
66
- Add `custom_model_name` parameter to the constructor of `HistoricalRecords` (gh-451)
7+
- Fix header on history pages when custom site_header is used (gh-448)
78
- Modify `pre_create_historircal_record` to pass `history_instance` for ease of customization (gh-421)
89

910
2.5.1 (2018-10-19)

docs/advanced.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ There are three documented ways to attach users to a tracked change:
121121
User instance that made the request as the ``history_user`` on the history
122122
table.
123123

124-
2. Use ``simple_history.admin.SimpleHistoryAdmin`. Under the hood,
124+
2. Use ``simple_history.admin.SimpleHistoryAdmin``. Under the hood,
125125
``SimpleHistoryAdmin`` actually sets the ``_history_user`` on the object to
126126
attach the user to the tracked change by overriding the `save_model` method.
127127

runtests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'django.contrib.auth',
2626
'django.contrib.sessions',
2727
'django.contrib.admin',
28+
'django.contrib.messages',
2829
]
2930

3031
DEFAULT_SETTINGS = dict(
@@ -45,6 +46,7 @@
4546
'OPTIONS': {
4647
'context_processors': [
4748
'django.contrib.auth.context_processors.auth',
49+
'django.contrib.messages.context_processors.messages',
4850
]
4951
},
5052
}],

simple_history/admin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def history_view(self, request, object_id, extra_context=None):
8484
'admin_user_view': admin_user_view,
8585
'history_list_display': history_list_display,
8686
}
87+
context.update(self.admin_site.each_context(request))
8788
context.update(extra_context or {})
8889
extra_kwargs = {}
8990
return render(request, self.object_history_template, context,
@@ -189,6 +190,7 @@ def history_form_view(self, request, object_id, version_id):
189190
'save_on_top': self.save_on_top,
190191
'root_path': getattr(self.admin_site, 'root_path', None),
191192
}
193+
context.update(self.admin_site.each_context(request))
192194
extra_kwargs = {}
193195
return render(request, self.object_history_form_template, context,
194196
**extra_kwargs)

simple_history/models.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,13 @@ def diff_against(self, old_history):
442442

443443
changes = []
444444
changed_fields = []
445+
instance_fields = [field.name for field in self.instance._meta.fields]
446+
old_instance_fields = [
447+
field.name for field in old_history.instance._meta.fields
448+
]
445449
for field in self._meta.fields:
446-
if hasattr(self.instance, field.name) and \
447-
hasattr(old_history.instance, field.name):
450+
if field.name in instance_fields and \
451+
field.name in old_instance_fields:
448452
old_value = getattr(old_history, field.name, '')
449453
new_value = getattr(self, field.name)
450454
if old_value != new_value:

simple_history/tests/tests/test_admin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_history_user_on_save_in_admin(self):
194194
self.assertEqual(Poll.history.get().history_user, self.user)
195195

196196
# Ensure polls saved on edit page in admin interface save correct user
197-
change_page = changelist_page.click("Poll object")
197+
change_page = changelist_page.click("Poll object", index=1)
198198
change_page.form.submit()
199199
self.assertEqual([p.history_user for p in Poll.history.all()],
200200
[self.user, self.user])
@@ -467,6 +467,7 @@ def test_history_form_view_without_getting_history(self):
467467
'save_on_top': admin.save_on_top,
468468
'root_path': getattr(admin_site, 'root_path', None),
469469
}
470+
context.update(admin_site.each_context(request))
470471
mock_render.assert_called_once_with(
471472
request, admin.object_history_form_template, context)
472473

@@ -522,6 +523,7 @@ def test_history_form_view_getting_history(self):
522523
'save_on_top': admin.save_on_top,
523524
'root_path': getattr(admin_site, 'root_path', None),
524525
}
526+
context.update(admin_site.each_context(request))
525527
mock_render.assert_called_once_with(
526528
request, admin.object_history_form_template, context)
527529

@@ -576,6 +578,7 @@ def test_history_form_view_getting_history_with_setting_off(self):
576578
'save_on_top': admin.save_on_top,
577579
'root_path': getattr(admin_site, 'root_path', None),
578580
}
581+
context.update(admin_site.each_context(request))
579582
mock_render.assert_called_once_with(
580583
request, admin.object_history_form_template, context)
581584

@@ -632,5 +635,6 @@ def test_history_form_view_getting_history_abstract_external(self):
632635
'save_on_top': admin.save_on_top,
633636
'root_path': getattr(admin_site, 'root_path', None),
634637
}
638+
context.update(admin_site.each_context(request))
635639
mock_render.assert_called_once_with(
636640
request, admin.object_history_form_template, context)

0 commit comments

Comments
 (0)