create restore button basic functionality
This commit is contained in:
parent
7d768875d5
commit
609fb88c72
5 changed files with 21 additions and 2 deletions
|
@ -258,6 +258,10 @@ class Change(models.Model):
|
|||
return True
|
||||
return not getattr(current_obj, field.name).filter(pk=self.field_value).exists()
|
||||
|
||||
def restore(self, author):
|
||||
if not self.can_restore:
|
||||
return
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.pk is not None:
|
||||
raise TypeError('change objects can not be edited (use update to set discarded_by)')
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
{% trans 'View History' %}
|
||||
</a>
|
||||
</p>
|
||||
{% bootstrap_messages %}
|
||||
|
||||
{% include 'editor/fragment_change_groups.html' %}
|
||||
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
{% include 'editor/fragment_modal_close.html' %}
|
||||
<h3>{{ changeset.title }}</h3>
|
||||
<h4>{% trans 'Changeset History' %}</h4>
|
||||
<form method="post" action="{{ request.path }}">
|
||||
{% csrf_token %}
|
||||
<p><a href="{% url 'editor.changesets.detail' pk=changeset.pk %}">« {% trans 'back to changeset' %}</a></p>
|
||||
{% bootstrap_messages %}
|
||||
|
||||
{% include 'editor/fragment_change_groups.html' %}
|
||||
</form>
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
<i class="glyphicon glyphicon-user text-muted" data-toggle="tooltip" data-placement="left" title="{{ change.author.username }}"></i>
|
||||
{% endif %}
|
||||
{% if change.can_restore %}
|
||||
<a class="btn btn-xs btn-default" data-toggle="tooltip" data-placement="left" title="{% trans 'Restore original state' %}">
|
||||
<button type="submit" name="restore" value="{{ change.pk }}" class="btn btn-xs btn-default" data-toggle="tooltip" data-placement="left" title="{% trans 'Restore original state' %}">
|
||||
<i class="glyphicon glyphicon-share-alt"></i>
|
||||
</a>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if change.created %}
|
||||
<i class="glyphicon glyphicon-time text-muted" data-toggle="tooltip" data-placement="left" title="{{ change.created }}"></i>
|
||||
|
|
|
@ -2,6 +2,7 @@ import json
|
|||
from operator import itemgetter
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
from django.utils.formats import date_format
|
||||
|
@ -23,6 +24,15 @@ def changeset_detail(request, pk, show_history=False):
|
|||
|
||||
ctx = group_changes(changeset, can_edit=can_edit, show_history=show_history)
|
||||
|
||||
if request.method == 'POST':
|
||||
restore = request.POST.get('restore')
|
||||
if restore.isdigit():
|
||||
change = changeset.changes.filter(pk=restore).first()
|
||||
if change is not None and change.can_restore:
|
||||
change.restore(request.user if request.user.is_authenticated else None)
|
||||
messages.success(request, _('Original state has been restored!'))
|
||||
return redirect(request.path)
|
||||
|
||||
if show_history:
|
||||
return render(request, 'editor/changeset_history.html', ctx)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue