Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update admin.py #467

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Maintainers
Authors
=======

- Adnan Umer (@uadnan)
- Aleksey Kladov
- Alexander Anikeev
- Ben Lawson
- bradford281
- Buddy Lindsey, Jr.
- Brian Dixon
- Buddy Lindsey, Jr.
- Corey Bertram
- Damien Nozay
- Daniel Gilge
Expand All @@ -21,56 +22,56 @@ Authors
- Eduardo Cuducos
- Florian Eßer
- George Vilches
- Gregory Bataille
- Grzegorz Bialy
- Hamish Downer
- Hanyin Zhang
- James Pulec
- Jesse Shapiro
- Jim Gomez
- Joao Junior(@joaojunior)
- Joao Pedro Francese
- jofusa
- John Whitlock
- Jonathan Leroy
- Jonathan Sanchez
- Jonathan Zvesper (@zvesp)
- Josh Fyne
- Kevin Foster
- Klaas van Schelven
- Kris Neuharth
- Kyle Seever
- Leticia Portella
- Lucas Wiman
- Maciej "RooTer" Urbański
- Mark Davidoff
- Leticia Portella
- Martin Bachwerk
- Marty Alchin
- Matheus Cansian (@mscansian)
- Mauricio de Abreu Antunes
- Micah Denbraver
- Michael England
- Miguel Vargas
- Mike Spainhower
- Nathan Villagaray-Carski
- Nianpeng Li
- Phillip Marshall
- Rajesh Pappula
- Ray Logel
- Roberto Aguilar
- Rod Xavier Bondoc
- Ross Lote
- Ross Mechanic
- Ross Rogers
- Steven Klass
- Sergey Ozeranskiy (@ozeranskiy)
- Shane Engelman
- Steeve Chailloux
- Steven Klass
- Tommy Beadle (@tbeadle)
- Trey Hunner
- Ulysses Vilela
- bradford281
- jofusa
- vnagendra
- Lucas Wiman
- Michael England
- Gregory Bataille
- Jesse Shapiro
- Kevin Foster
- Shane Engelman
- Ray Logel
- Nathan Villagaray-Carski
- Mike Spainhower
- Alexander Anikeev
- Kyle Seever
- Adnan Umer (@uadnan)
- Jonathan Zvesper (@zvesp)
- Matheus Cansian (@mscansian)
- Jim Gomez
- Hanyin Zhang

Background
==========
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Unreleased
----------
- Add `custom_model_name` parameter to the constructor of `HistoricalRecords` (gh-451)
- Fix header on history pages when custom site_header is used (gh-448)
- Add `extra_context` parameter to history_form_view (gh-467)

2.5.1 (2018-10-19)
------------------
Expand Down
4 changes: 3 additions & 1 deletion simple_history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def response_change(self, request, obj):
return super(SimpleHistoryAdmin, self).response_change(
request, obj)

def history_form_view(self, request, object_id, version_id):
def history_form_view(self, request, object_id, version_id,
extra_context=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra_context is None by default, so you shouldn't have to add it here. Try to add separate tests where extra_context has an actual value and passes through

request.current_app = self.admin_site.name
original_opts = self.model._meta
model = getattr(
Expand Down Expand Up @@ -191,6 +192,7 @@ def history_form_view(self, request, object_id, version_id):
'root_path': getattr(self.admin_site, 'root_path', None),
}
context.update(self.admin_site.each_context(request))
context.update(extra_context or {})
extra_kwargs = {}
return render(request, self.object_history_form_template, context,
**extra_kwargs)
Expand Down
20 changes: 16 additions & 4 deletions simple_history/tests/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ def test_history_form_view_without_getting_history(self):
admin = SimpleHistoryAdmin(Poll, admin_site)

with patch('simple_history.admin.render') as mock_render:
admin.history_form_view(request, poll.id, history.pk)
admin.history_form_view(request, poll.id, history.pk,
extra_context=None)

context = {
# Verify this is set for original object
Expand Down Expand Up @@ -467,7 +468,9 @@ def test_history_form_view_without_getting_history(self):
'save_on_top': admin.save_on_top,
'root_path': getattr(admin_site, 'root_path', None),
}
extra_context = {}
ozeranskii marked this conversation as resolved.
Show resolved Hide resolved
context.update(admin_site.each_context(request))
context.update(extra_context or {})
mock_render.assert_called_once_with(
request, admin.object_history_form_template, context)

Expand All @@ -488,7 +491,8 @@ def test_history_form_view_getting_history(self):

with patch('simple_history.admin.render') as mock_render:
with patch('simple_history.admin.SIMPLE_HISTORY_EDIT', True):
admin.history_form_view(request, poll.id, history.pk)
admin.history_form_view(request, poll.id, history.pk,
extra_context=None)

context = {
# Verify this is set for history object not poll object
Expand Down Expand Up @@ -523,7 +527,9 @@ def test_history_form_view_getting_history(self):
'save_on_top': admin.save_on_top,
'root_path': getattr(admin_site, 'root_path', None),
}
extra_context = {}
context.update(admin_site.each_context(request))
context.update(extra_context or {})
mock_render.assert_called_once_with(
request, admin.object_history_form_template, context)

Expand All @@ -544,7 +550,8 @@ def test_history_form_view_getting_history_with_setting_off(self):

with patch('simple_history.admin.render') as mock_render:
with patch('simple_history.admin.SIMPLE_HISTORY_EDIT', False):
admin.history_form_view(request, poll.id, history.pk)
admin.history_form_view(request, poll.id, history.pk,
extra_context=None)

context = {
# Verify this is set for history object not poll object
Expand Down Expand Up @@ -578,7 +585,9 @@ def test_history_form_view_getting_history_with_setting_off(self):
'save_on_top': admin.save_on_top,
'root_path': getattr(admin_site, 'root_path', None),
}
extra_context = {}
context.update(admin_site.each_context(request))
context.update(extra_context or {})
mock_render.assert_called_once_with(
request, admin.object_history_form_template, context)

Expand All @@ -599,7 +608,8 @@ def test_history_form_view_getting_history_abstract_external(self):

with patch('simple_history.admin.render') as mock_render:
with patch('simple_history.admin.SIMPLE_HISTORY_EDIT', True):
admin.history_form_view(request, obj.id, history.pk)
admin.history_form_view(request, obj.id, history.pk,
extra_context=None)

context = {
# Verify this is set for history object
Expand Down Expand Up @@ -635,6 +645,8 @@ def test_history_form_view_getting_history_abstract_external(self):
'save_on_top': admin.save_on_top,
'root_path': getattr(admin_site, 'root_path', None),
}
extra_context = {}
context.update(admin_site.each_context(request))
context.update(extra_context or {})
mock_render.assert_called_once_with(
request, admin.object_history_form_template, context)