Self hosted FLOSS fitness/workout, nutrition and weight tracker
add ability to revert
Tom Bowyer8df789dd4bbe
diff --git a/wger/exercises/templates/history/list3.html b/wger/exercises/templates/history/list3.htmlindex c2c81871d..a4b69e931 100644--- a/wger/exercises/templates/history/list3.html+++ b/wger/exercises/templates/history/list3.html@@ -84,7 +84,7 @@</div></td><td>- <a href="#" id="view-changes" class="btn btn-danger btn-sm btn-block">+ <a href="revert/{{ event.history.record.history_id }}" id="view-changes" class="btn btn-danger btn-sm btn-block">{% translate "Revert changes" %}</a></td>diff --git a/wger/exercises/urls.py b/wger/exercises/urls.pyindex 5137e5dc5..f47398824 100644--- a/wger/exercises/urls.py+++ b/wger/exercises/urls.py@@ -41,6 +41,8 @@ patterns_history = [path('overview/', history.overview, name='overview'),path('overview-history/', history.overview2, name='overview-history'),path('admin-control/', history.control, name='admin-control'),+ path('admin-control/revert/<int:pk>/',+ history.history_revert, name='history-revert'),]# sub patterns for musclesdiff --git a/wger/exercises/views/history.py b/wger/exercises/views/history.pyindex a1a94369d..98060ac71 100644--- a/wger/exercises/views/history.py+++ b/wger/exercises/views/history.py@@ -21,9 +21,15 @@ import loggingfrom django.contrib.auth.decorators import permission_requiredfrom django.contrib.contenttypes.models import ContentTypefrom django.shortcuts import render+from django.http import HttpResponseRedirect+from django.urls import (+ reverse,+ reverse_lazy,+)# Third Partyfrom actstream.models import Action+from actstream import action as actstream_action# wgerfrom wger.exercises.models import Exercise@@ -73,6 +79,8 @@ def control(request):action_object_content_type_id=object_content_type_ID,)+ print(stream)+out = []for entry in stream:# Fetch history@@ -95,3 +103,30 @@ def control(request):return render(request, 'history/list3.html', {'history': out,})+++@permission_required('exercises.change_exercise')+def history_revert(request, pk):+ """+ Used to revert objects+ """++ hist = Exercise.history.filter(history_id=pk).first()++ revert_obj = hist.prev_record++ revert_obj.instance.save()++ updated_object = Exercise.objects.get(id=revert_obj.id)+ most_recent_history = updated_object.history.order_by('history_date').last()++ actstream_action.send(+ request.user,+ verb=StreamVerbs.UPDATED.value,+ action_object=revert_obj.instance,+ data={+ 'history_id': most_recent_history.history_id,+ }+ )++ return HttpResponseRedirect(reverse('exercise:history:admin-control'))