Skip to content

Commit 6ae780b

Browse files
committed
Add ability to edit history
1 parent 78c9291 commit 6ae780b

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

simple_history/admin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.contrib.admin import helpers
77
from django.contrib.contenttypes.models import ContentType
88
from django.core.urlresolvers import reverse
9+
from django.http import HttpResponseRedirect
910
from django.shortcuts import get_object_or_404, render
1011
from django.utils.text import capfirst
1112
from django.utils.html import mark_safe
@@ -75,6 +76,24 @@ def history_view(self, request, object_id, extra_context=None):
7576
return render(request, template_name=self.object_history_template,
7677
dictionary=context, current_app=self.admin_site.name)
7778

79+
def response_change(self, request, obj):
80+
if '_change_history' in request.POST:
81+
verbose_name = obj._meta.verbose_name
82+
83+
msg = _('The %(name)s "%(obj)s" was changed successfully.') % {
84+
'name': force_text(verbose_name),
85+
'obj': force_text(obj)
86+
}
87+
88+
self.message_user(
89+
request, "%s - %s" % (msg, _("You may edit it again below")),
90+
fail_silently=True)
91+
92+
return HttpResponseRedirect(request.path)
93+
else:
94+
return super(SimpleHistoryAdmin, self).response_change(
95+
request, obj)
96+
7897
def history_form_view(self, request, object_id, version_id):
7998
original_opts = self.model._meta
8099
model = getattr(
@@ -89,6 +108,9 @@ def history_form_view(self, request, object_id, version_id):
89108
if not self.has_change_permission(request, obj):
90109
raise PermissionDenied
91110

111+
if '_change_history' in request.POST:
112+
obj = obj.history.get(pk=version_id)
113+
92114
formsets = []
93115
form_class = self.get_form(request, obj)
94116
if request.method == 'POST':

simple_history/templates/simple_history/object_history_form.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
</div>
1414
{% endblock %}
1515

16-
{% comment %}Hack to remove "Save as New" and "Save and Continue" buttons {% endcomment %}
17-
{% block content %}
18-
{% with 1 as is_popup %}
19-
{{block.super}}
20-
{% endwith %}
16+
{% block submit_buttons_bottom %}
17+
{% include "simple_history/submit_line.html" %}
2118
{% endblock %}
2219

2320
{% block form_top %}
24-
<p>{% blocktrans %}Press the save button below to revert to this version of the object.{% endblocktrans %}</p>
21+
<p>{% blocktrans %}Press the 'Revert' button below to revert to this version of the object. Or press the 'Change History' button to edit the history.{% endblocktrans %}</p>
2522
{% endblock %}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% load i18n %}
2+
<div class="submit-row">
3+
<input type="submit" value="{% trans 'Revert' %}" class="default" name="_save" {{ onclick_attrib }}/>
4+
<input type="submit" value="{% trans 'Change History' %}" class="default" name="_change_history" {{ onclick_attrib }}/>
5+
</div>

0 commit comments

Comments
 (0)