Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add simple exercise edit history

Roland Geidere024ed7940ea
diff --git a/wger/core/templates/navigation.html b/wger/core/templates/navigation.html
index a0d429bc0..c694ea97d 100644
--- a/wger/core/templates/navigation.html
+++ b/wger/core/templates/navigation.html
@@ -36,7 +36,7 @@
{% if user.is_authenticated %}
<li><a class="dropdown-item" href="{% url 'manager:workout:calendar' user.username %}" rel="nofollow">{% translate "Calendar" %}</a></li>
{% endif %}
-
+
<li><a class="dropdown-item" href="{% url 'gallery:images:overview' %}" rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
@@ -59,6 +59,7 @@
<li class="dropdown-divider"></li>
<li class="dropdown-header">{% translate "Administration" %}</li>
<li><a class="dropdown-item" href="{% url 'exercise:exercise:pending' %}">{% translate "Exercises pending review" %}</a></li>
+ <li><a class="dropdown-item" href="{% url 'exercise:history:overview' %}">{% translate "Exercise edit history" %}</a></li>
<li><a class="dropdown-item" href="{% url 'exercise:equipment:list' %}">{% translate "Equipment" %}</a></li>
<li><a class="dropdown-item" href="{% url 'exercise:muscle:admin-list' %}">{% translate "Muscles" %}</a></li>
<li><a class="dropdown-item" href="{% url 'exercise:category:list' %}">{% translate "Categories" %}</a></li>
diff --git a/wger/exercises/templates/history/list.html b/wger/exercises/templates/history/list.html
new file mode 100644
index 000000000..e9eb52263
--- /dev/null
+++ b/wger/exercises/templates/history/list.html
@@ -0,0 +1,91 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% load static %}
+{% load wger_extras %}
+{% load cache %}
+{% load thumbnail %}
+
+<!--
+ Title
+-->
+{% block title %}{% translate "Exercise edit history" %}{% endblock %}
+
+
+
+{% block header %}
+
+{% endblock %}
+
+
+<!--
+ Main Content
+-->
+{% block content %}
+ <div class="accordion" id="accordionExample">
+ {% for entry in history %}
+ <div class="card">
+ <div class="card-header" id="heading{{ entry.record.history_id }}">
+ <button class="btn btn-link btn-block text-left"
+ type="button"
+ data-toggle="collapse"
+ data-target="#collapse{{ entry.record.history_id }}"
+ aria-expanded="true"
+ aria-controls="collapse{{ entry.record.history_id }}">
+ History entry for {{ entry.record.instance.name }}
+ <small>{{ entry.record.history_date }}</small>
+ </button>
+ </div>
+ <div id="collapse{{ entry.record.history_id }}"
+ class="collapse"
+ aria-labelledby="heading{{ entry.record.history_id }}"
+ data-parent="#accordionExample">
+ <div class="card-body">
+ {% if entry.record.history_type == '~' %}
+ <table class="table">
+ <thead>
+ <tr>
+ <td>Field</td>
+ <td>Old</td>
+ <td>New</td>
+ </tr>
+ </thead>
+ <tbody>
+ {% if entry.delta %}
+ {% for change in entry.delta.changes %}
+ <tr>
+ <td>{{ change.field }}</td>
+ <td>{{ change.old }}</td>
+ <td>{{ change.new }}</td>
+ </tr>
+ {% endfor %}
+ {% endif %}
+ </tbody>
+ </table>
+ {% elif entry.record.history_type == '-' %}
+ <p>Entry deleted</p>
+ {% elif entry.record.history_type == '+' %}
+ <p>Entry created</p>
+ {% endif %}
+ </div>
+ </div>
+ </div>
+ {% endfor %}
+
+ </div>
+
+
+{% endblock %}
+
+
+<!--
+ Side bar
+-->
+{% block sidebar %}
+
+{% endblock %}
+
+
+
+{% block options %}
+
+{% endblock %}
diff --git a/wger/exercises/urls.py b/wger/exercises/urls.py
index e2ae94ea8..f878a83ad 100644
--- a/wger/exercises/urls.py
+++ b/wger/exercises/urls.py
@@ -30,10 +30,18 @@ from wger.exercises.views import (
equipment,
exercises,
images,
- muscles
+ muscles,
+ history
)
+# sub patterns for history
+patterns_history = [
+ path('overview/',
+ history.overview,
+ name='overview'),
+]
+
# sub patterns for muscles
patterns_muscle = [
path('overview/',
@@ -162,5 +170,6 @@ urlpatterns = [
path('comment/', include((patterns_comment, 'comment'), namespace="comment")),
path('category/', include((patterns_category, 'category'), namespace="category")),
path('equipment/', include((patterns_equipment, 'equipment'), namespace="equipment")),
+ path('history/', include((patterns_history, 'history'), namespace="history")),
path('', include((patterns_exercise, 'exercise'), namespace="exercise")),
]
diff --git a/wger/exercises/views/history.py b/wger/exercises/views/history.py
new file mode 100644
index 000000000..1624ab699
--- /dev/null
+++ b/wger/exercises/views/history.py
@@ -0,0 +1,118 @@
+# -*- coding: utf-8 -*-
+
+# This file is part of wger Workout Manager.
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU Affero General Public License
+
+# Standard Library
+import logging
+import uuid
+
+# Django
+from django.conf import settings
+from django.contrib import messages
+from django.contrib.auth.decorators import permission_required
+from django.contrib.auth.mixins import (
+ LoginRequiredMixin,
+ PermissionRequiredMixin
+)
+from django.core import mail
+from django.core.exceptions import ValidationError
+from django.forms import (
+ CharField,
+ CheckboxSelectMultiple,
+ ModelChoiceField,
+ ModelForm,
+ ModelMultipleChoiceField,
+ Select,
+ Textarea
+)
+from django.http import (
+ HttpResponseForbidden,
+ HttpResponseRedirect
+)
+from django.shortcuts import (
+ get_object_or_404,
+ render
+)
+from django.template.loader import render_to_string
+from django.urls import (
+ reverse,
+ reverse_lazy
+)
+from django.utils.cache import patch_vary_headers
+from django.utils.translation import (
+ gettext as _,
+ gettext_lazy
+)
+from django.views.generic import (
+ CreateView,
+ DeleteView,
+ ListView,
+ UpdateView
+)
+
+# Third Party
+from crispy_forms.layout import (
+ Column,
+ Layout,
+ Row
+)
+
+# wger
+from django.views.generic.base import TemplateResponseMixin
+
+from wger.config.models import LanguageConfig
+from wger.exercises.models import (
+ Equipment,
+ Exercise,
+ ExerciseBase,
+ ExerciseCategory,
+ Muscle
+)
+from wger.manager.models import WorkoutLog
+from wger.utils.constants import MIN_EDIT_DISTANCE_THRESHOLD
+from wger.utils.generic_views import (
+ WgerDeleteMixin,
+ WgerFormMixin
+)
+from wger.utils.helpers import levenshtein
+from wger.utils.language import (
+ load_item_languages,
+ load_language
+)
+from wger.utils.widgets import TranslatedSelectMultiple
+from wger.weight.helpers import process_log_entries
+
+
+logger = logging.getLogger(__name__)
+
+
+
+@permission_required('exercises.change_exercise')
+def overview(request):
+ """
+ Generic view to list the history of the exercises
+ """
+ context = {}
+
+ out = []
+ history = Exercise.history.all()
+ for entry in history:
+ if entry.prev_record:
+ out.append({'record': entry,
+ 'delta': entry.diff_against(entry.prev_record)})
+
+
+ context['history'] = out
+
+ return render(request, 'history/list.html', context)