Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Self review changes

Tom Bowyer4c7510e8b839
diff --git a/wger/exercises/templates/history/list3.html b/wger/exercises/templates/history/list3.html
index 463b27197..a572c5044 100644
--- a/wger/exercises/templates/history/list3.html
+++ b/wger/exercises/templates/history/list3.html
@@ -33,7 +33,7 @@
</tr>
</thead>
<tbody>
- {% for event in history %}
+ {% for event in context %}
<tr>
<td>{{ event.stream.actor }}</td>
<td>{{ event.stream.verb }}</td>
@@ -45,7 +45,7 @@
{% endif %}
</td>
<td>{{ event.stream.timesince }}</td>
- {% if event.stream.verb == "created" %}
+ {% if event.stream.verb == modes.CREATED.value %}
<td>
<a href="{{ event.stream.action_object.get_absolute_url }}" id="view-changes" class="btn btn-success btn-sm btn-block">
{% translate "View exercise" %}
@@ -56,7 +56,7 @@
{% translate "Delete exercise" %}
</a>
</td>
- {% elif event.stream.verb == "updated" %}
+ {% elif event.stream.verb == modes.UPDATED.value %}
<td>
<a href="#" id="view-changes" data-toggle="modal" data-target="#changes-modal-{{ event.stream.id }}"
class="btn btn-success btn-sm btn-block">
@@ -98,10 +98,29 @@
</div>
</td>
<td>
- <a href="revert/{{ event.history.record.history_id }}" id="view-changes" class="btn btn-danger btn-sm btn-block">
+ <a href="#" id="revert-changes" data-toggle="modal" data-target="#revert-modal-{{ event.stream.id }}"
+ class="btn btn-danger btn-sm btn-block">
{% translate "Revert changes" %}
</a>
+ <div class="modal fade" id="revert-modal-{{ event.stream.id }}">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <h4 class="modal-title">{% translate 'Are you sure?' %}</h4>
+ </div>
+ <div class="modal-body">
+ <a href="revert/{{ event.history.record.history_id }}" id="view-changes" class="btn btn-danger btn-sm btn-block">
+ {% translate "Yes" %}
+ </a>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-light" data-dismiss="modal">{% translate "No" %}</button>
+ </div>
+ </div>
+ </div>
+ </div>
</td>
+ {% endif %}
</tr>
{% endfor %}
</tbody>
diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.py
index 0b7b07fd5..4131c1e22 100644
--- a/wger/exercises/views/exercises.py
+++ b/wger/exercises/views/exercises.py
@@ -33,10 +33,6 @@ from django.forms import (
Select,
Textarea,
)
-from django.http import (FileResponse,
- Http404,
- HttpResponse, HttpResponseForbidden, HttpResponseNotFound, HttpResponseRedirect,
- JsonResponse)
from django.shortcuts import (
get_object_or_404,
render,
@@ -51,9 +47,6 @@ from django.views.generic import (
ListView,
)
-# Third Party
-from actstream import action as actstream_action
-
# wger
from wger.exercises.models import (
Equipment,
@@ -62,7 +55,6 @@ from wger.exercises.models import (
ExerciseCategory,
Muscle,
)
-from wger.exercises.views.helper import StreamVerbs
from wger.manager.models import WorkoutLog
from wger.utils.constants import MIN_EDIT_DISTANCE_THRESHOLD
from wger.utils.generic_views import WgerDeleteMixin
diff --git a/wger/exercises/views/helper.py b/wger/exercises/views/helper.py
index 84eae9222..195166110 100644
--- a/wger/exercises/views/helper.py
+++ b/wger/exercises/views/helper.py
@@ -18,4 +18,3 @@ import enum
class StreamVerbs(enum.Enum):
CREATED = 'created'
UPDATED = 'updated'
- DELETED = 'deleted'
diff --git a/wger/exercises/views/history.py b/wger/exercises/views/history.py
index af7152b7f..daa5ba739 100644
--- a/wger/exercises/views/history.py
+++ b/wger/exercises/views/history.py
@@ -42,6 +42,7 @@ def overview(request):
"""
Generic view to list the history of the exercises
"""
+
context = {
'stream': Action.objects.all(),
@@ -58,7 +59,6 @@ def overview2(request):
"""
Generic view to list the history of the exercises
"""
-
out = []
for entry in Exercise.history.all():
if entry.prev_record:
@@ -72,22 +72,21 @@ def control(request):
"""
Admin view of the history of the exercises
"""
- object_content_type_ID = ContentType.objects.get_for_model(Exercise).id
+ object_content_type = ContentType.objects.get_for_model(Exercise)
stream = Action.objects.filter(
- action_object_content_type_id=object_content_type_ID,
+ action_object_content_type_id=object_content_type.id,
)
out = []
for entry in stream:
- if entry.verb == "created":
+ if entry.verb == StreamVerbs.CREATED.value:
out.append({
- 'history': {'record': None, 'delta': None},
+ 'history': None,
'stream': entry
})
continue
- elif entry.verb == "updated":
- # Fetch history
+ elif entry.verb == StreamVerbs.UPDATED.value:
entry_data = entry.data
if entry_data is None:
continue
@@ -105,20 +104,23 @@ def control(request):
})
return render(request, 'history/list3.html', {
- 'history': out,
+ 'context': out,
+
+ # We can't pass the enum to the template, so we have to do this
+ # https://stackoverflow.com/questions/35953132/
+ 'modes': StreamVerbs.__members__
})
@permission_required('exercises.change_exercise')
def history_revert(request, pk):
"""
- Used to revert objects
+ Used to revert history objects
"""
hist = Exercise.history.get(history_id=pk)
if hist is None:
return HttpResponseRedirect(reverse('exercise:history:admin-control'))
- # exit early if there's no prev_record
revert_obj = hist.prev_record
if revert_obj is None:
return HttpResponseRedirect(reverse('exercise:history:admin-control'))
@@ -130,7 +132,10 @@ def history_revert(request, pk):
return HttpResponseRedirect(reverse('exercise:history:admin-control'))
for change in diff.changes:
- setattr(current_obj, change.field, change.old)
+ try:
+ setattr(current_obj, change.field, change.old)
+ except:
+ logger.warn(f"Failed setting field: {change.field} to {change.old} for Exercise {current_obj.id}")
current_obj.save()