Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Cleanup unused workout templates, logic and urls

Roland Geider3c8e8bdd259d
diff --git a/wger/manager/templates/workout/overview.html b/wger/manager/templates/workout/overview.html
deleted file mode 100644
index 11075aa44..000000000
--- a/wger/manager/templates/workout/overview.html
+++ /dev/null
@@ -1,42 +0,0 @@
-{% extends "base.html" %}
-{% load i18n %}
-{% load static %}
-
-{% block title %}{{ title }}{% endblock %}
-
-
-{% block content %}
- <div class="list-group">
- {% for workout in workouts %}
- <a href="{{ workout.get_absolute_url }}" class="list-group-item list-group-item-action">
- <span class="glyphicon glyphicon-chevron-right float-end"></span>
-
- {% if workout == current_workout %}
- <span class="badge bg-secondary float-end">
- <em>{% translate "active" %}</em>
- </span>
- {% endif %}
-
- <p class="list-group-item-heading h5">{{ workout }}</p>
- <p class="list-group-item-text">{{ workout.creation_date }}</p>
- </a>
- {% empty %}
- {% if template_overview %}
- {% translate "No templates found." %}
- {% else %}
- <a href="{% url 'manager:workout:add' %}" class="list-group-item list-group-item-action">
- {% translate "No workouts found." %}<br>{% translate "Add one now." %}
- </a>
- {% endif %}
- {% endfor %}
- </div>
-{% endblock %}
-
-
-{% block options %}
- {% if not template_overview %}
- <a href="{% url 'manager:workout:add' %}" class="btn btn-success btn-sm">
- {% translate "Add workout" %}
- </a>
- {% endif %}
-{% endblock %}
diff --git a/wger/manager/templates/workout/template_view.html b/wger/manager/templates/workout/template_view.html
deleted file mode 100644
index caa9da780..000000000
--- a/wger/manager/templates/workout/template_view.html
+++ /dev/null
@@ -1,92 +0,0 @@
-{% extends "base.html" %}
-{% load i18n %}
-{% load static %}
-{% load wger_extras %}
-
-{# #}
-{# Opengraph #}
-{# #}
-{% block opengraph %}
- {{ block.super }}
- <meta property="og:title" content="{% translate 'Workout template' %}">
- <meta property="og:description" content="{{ workout }} / {{owner_user.username}}">
-{% endblock %}
-
-
-{# #}
-{# Title #}
-{# #}
-{% block title %}{% translate 'Workout template' %}{% endblock %}
-
-
-{# #}
-{# Header #}
-{# #}
-{% block header %}
-
-{% endblock %}
-
-
-{# #}
-{# Content #}
-{# #}
-{% block content %}
-
-
-{% if workout.name %}
- <h4>{{workout.name }}</h4>
-{% endif %}
-
-{% if workout.description %}
- <p>{{ workout.description }}</p>
-{% endif %}
-
-{% for day in workout.canonical_representation.day_list %}
- <div id="div-day-{{ day.obj.id }}">
- {% render_day day.obj is_owner %}
- </div>
-{% endfor %}
-
-{% if is_owner %}
-<div class="col text-center">
- <a href="{% url 'manager:template:make-workout' workout.id %}" class="btn btn-outline-primary">
- {% translate "Mark as workout" %}
- </a>
-</div>
-{% endif %}
-{% endblock %}
-
-
-
-{# #}
-{# Side bar #}
-{# #}
-{% block sidebar %}
-<h4>{% translate "Muscles trained" %}</h4>
-
-<p>
- {% translate "Images show combined muscles as trained by the exercises on the workout." %}
-</p>
-
-<div class="row">
- <div class="col-6">
- {% render_muscles muscles.front muscles.frontsecondary %}
- </div>
- <div class="col-6">
- {% render_muscles muscles.back muscles.backsecondary %}
- </div>
-</div>
-{% endblock %}
-
-
-
-{# #}
-{# Options #}
-{# #}
-{% block options %}
-<a href="{% url 'manager:workout:copy' workout.id %}" class="btn btn-success">
- <span class="{% fa_class 'clone' %}"></span>
- {% translate "Use this template" %}
-</a>
-
-{% endblock %}
diff --git a/wger/manager/templates/workout/view.html b/wger/manager/templates/workout/view.html
deleted file mode 100644
index 496fbaf03..000000000
--- a/wger/manager/templates/workout/view.html
+++ /dev/null
@@ -1,209 +0,0 @@
-{% extends "base.html" %}
-{% load i18n l10n static wger_extras %}
-
-{# #}
-{# Opengraph #}
-{# #}
-{% block opengraph %}
- {{ block.super }}
- <meta property="og:title" content="{% translate 'Workout' %}">
- <meta property="og:description" content="{{ workout }} / {{ owner_user.username }}">
-{% endblock %}
-
-
-{# #}
-{# Title #}
-{# #}
-{% block title %}{% translate "Workout" %}{% endblock %}
-
-
-{# #}
-{# Header #}
-{# #}
-{% block header %}
-{% endblock %}
-
-
-{# #}
-{# Content #}
-{# #}
-{% block content %}
- <div id="react-page"></div>
-{% endblock %}
-
-
-
-{# #}
-{# Side bar #}
-{# #}
-{% block sidebar %}
- <h4>{% translate "Steps" %}</h4>
-
- <ol>
- <li>{% translate "Add training days" %}</li>
- <li>{% translate "Add workout sets to days" %}</li>
- <li>{% translate "Set the repetitions for each set" %}</li>
- </ol>
-
-
- <h4>{% translate "Muscles trained" %}</h4>
-
- <p>
- {% translate "Images show combined muscles as trained by the exercises on the workout." %}
- </p>
-
- <div class="row">
- <div class="col-6">
- {% render_muscles workout.canonical_representation.muscles.front workout.canonical_representation.muscles.front_secondary %}
- </div>
- <div class="col-6">
- {% render_muscles workout.canonical_representation.muscles.back workout.canonical_representation.muscles.back_secondary %}
- </div>
- </div>
-
-
- <div class="modal fade" id="export-ical-popup">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <h4 class="modal-title">{% translate "Export calendar file" %}</h4>
- <button type="button" class="close" data-bs-dismiss="modal" aria-hidden="true">
- &times;
- </button>
- </div>
- <div class="modal-body">
- <p>{% translate "Export this workout as a calendar file." %}</p>
- <p>{% blocktranslate %}You can then import the file it into your calendar
- application for example google calendar, outlook or iCal. This will create
- an appointment for each training day with the appropriate
- exercises.{% endblocktranslate %}</p>
- <p>
- <a href="{% url 'manager:workout:ical' workout.id uid token %}"
- class="btn btn-block btn-light">
- {% translate "Export calendar file" %}
- </a>
- </p>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-light"
- data-bs-dismiss="modal">{% translate "Close" %}</button>
- </div>
- </div>
- </div>
- </div>
-
- <div class="modal fade" id="download-pdf-popup">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <h4 class="modal-title">{% translate "Download as PDF" %}</h4>
- <button type="button" class="close float-end" data-bs-dismiss="modal"
- aria-hidden="true">&times;
- </button>
- </div>
- <div class="modal-body">
- <form class="wger-form">
- <div id="pdf-download-info" data-workout-id="{{ workout.id|unlocalize }}"
- data-uid="{{ uid }}"
- data-token="{{ token }}"></div>
- <div class="form-group form-check-inline">
- <input type="radio" name="pdf_type" class="form-check-input"
- id="id_type_log" value="log"
- checked>
- <label class="form-check-label" for="id_type_log">
- {% translate "Log" %}
- </label>
- </div>
- <div class="form-group form-check-inline">
- <input type="radio" name="pdf_type" id="id_type_table"
- class="form-check-input"
- value="table">
- <label class="form-check-label" for="id_type_table">
- {% translate "Table" %}
- </label>
- </div>
- <div class="form-group form-check">
- <input type="checkbox" class="form-check-input" name="images"
- id="id_images" checked>
- <label for="id_images" class="form-check-label">
- {% translate "with images" %}
- </label>
- </div>
- <div class="form-group form-check">
- <input type="checkbox" class="form-check-input" name="comments"
- id="id_comments" checked>
- <label for="id_comments" class="form-check-label">
- {% translate "with comments" %}
- </label>
- </div>
- </form>
-
- <p>
- <a href="" class="btn btn-block btn-light" id="download-pdf-button">
- {% translate "Download" %}
- </a>
- </p>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-light"
- data-bs-dismiss="modal">{% translate "Close" %}</button>
- </div>
- </div>
- </div>
- </div>
-
- {% if workout.canonical_representation.day_list %}
- <h4>{% translate "Logs" %}</h4>
- <p>
- <a class="btn btn-primary btn-sm"
- href="{% url 'manager:log:log' workout.id %}">{% translate 'View logs' %}</a>
- </p>
- {% endif %}
-
-{% endblock %}
-
-
-
-{# #}
-{# Options #}
-{# #}
-{% block options %}
- <div class="btn-group" role="group">
- <div class="btn-group" role="group">
- <button id="btnGroupWorkout" type="button"
- class="btn btn-primary btn-sm dropdown-toggle"
- data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- <span class="{% fa_class 'cog' %}"></span>
- {% translate "Options" %}
- </button>
- <div class="dropdown-menu" aria-labelledby="btnGroupWorkout">
- {% if is_owner %}
- {% translate 'Edit' as text %}
- {% url 'manager:workout:edit' workout.id as url %}
- {% modal_link url=url text=text css_class='dropdown-item' %}
- {% endif %}
- <a class="dropdown-item" data-bs-toggle="modal"
- data-bs-target="#download-pdf-popup">
- <span class="{% fa_class 'download' %}"></span>
- {% translate "Download as PDF" %}
- </a>
- <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#export-ical-popup">
- <span class="{% fa_class 'calendar' %}"></span>
- {% translate "Export calendar file" %}
- </a>
-
- {% translate 'Mark as template' as text %}
- {% url 'manager:workout:make-template' workout.id as url %}
- {% modal_link url=url text=text css_class='dropdown-item' %}
-
- {% if is_owner %}
- <div class="dropdown-divider"></div>
-
- {% translate 'Delete' as text %}
- {% url 'manager:workout:delete' workout.id as url %}
- {% modal_link url=url text=text css_class='dropdown-item' %}
- {% endif %}
- </div>
- </div>
- </div>
-{% endblock %}
diff --git a/wger/manager/urls.py b/wger/manager/urls.py
index 3a1591f91..23d7dda97 100644
--- a/wger/manager/urls.py
+++ b/wger/manager/urls.py
@@ -25,32 +25,25 @@ from wger.manager.views import (
ical,
pdf,
routine,
- workout,
)
-
# sub patterns for templates
patterns_templates = [
path(
- 'overview',
- workout.template_overview,
+ 'overview/private',
+ ReactView.as_view(login_required=True),
name='overview',
),
path(
- 'public',
- workout.public_template_overview,
+ 'overview/public',
+ ReactView.as_view(login_required=True),
name='public',
),
path(
'<int:pk>/view',
- workout.template_view,
+ ReactView.as_view(login_required=True),
name='view',
),
- path(
- '<int:pk>/make-workout',
- workout.make_workout,
- name='make-workout',
- ),
]
# sub patterns for days
@@ -62,16 +55,7 @@ patterns_days = [
),
]
-# sub patterns for workouts
-patterns_workout = [
- path(
- '<int:pk>/make-template',
- workout.WorkoutMarkAsTemplateView.as_view(),
- name='make-template',
- ),
-]
-
-# sub patterns for workouts
+# sub patterns for routines
patterns_routine = [
path(
'overview',
@@ -136,8 +120,7 @@ patterns_routine = [
]
urlpatterns = [
- path('', include((patterns_workout, 'workout'), namespace='workout')),
path('', include((patterns_routine, 'routine'), namespace='routine')),
- path('template/', include((patterns_templates, 'template'), namespace='template')),
+ path('templates/', include((patterns_templates, 'template'), namespace='template')),
path('<int:routine_pk>/day/', include((patterns_days, 'day'), namespace='day')),
]
diff --git a/wger/manager/views/workout.py b/wger/manager/views/workout.py
deleted file mode 100644
index 745c8bd65..000000000
--- a/wger/manager/views/workout.py
+++ /dev/null
@@ -1,122 +0,0 @@
-# -*- 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
-
-# Django
-from django.contrib.auth.decorators import login_required
-from django.contrib.auth.mixins import LoginRequiredMixin
-from django.http import (
- HttpResponseForbidden,
- HttpResponseRedirect,
-)
-from django.shortcuts import (
- get_object_or_404,
- render,
-)
-from django.utils.translation import gettext as _
-from django.views.generic import UpdateView
-
-# wger
-from wger.manager.forms import WorkoutMakeTemplateForm
-from wger.manager.models import (
- Routine,
- Workout,
-)
-from wger.utils.generic_views import WgerFormMixin
-
-
-logger = logging.getLogger(__name__)
-
-
-# ************************
-# Workout functions
-# ************************
-
-
-@login_required
-def template_overview(request):
- """ """
- return render(
- request,
- 'workout/overview.html',
- {
- 'workouts': Workout.templates.filter(user=request.user),
- 'title': _('Your templates'),
- 'template_overview': True,
- },
- )
-
-
-@login_required
-def public_template_overview(request):
- """ """
- return render(
- request,
- 'workout/overview.html',
- {
- 'workouts': Workout.templates.filter(is_public=True),
- 'title': _('Public templates'),
- 'template_overview': True,
- },
- )
-
-
-@login_required()
-def template_view(request, pk):
- """
- Show the template with the given ID
- """
- template = get_object_or_404(Workout.templates, pk=pk)
-
- if not template.is_public and request.user != template.user:
- return HttpResponseForbidden()
-
- context = {
- 'workout': template,
- 'muscles': template.canonical_representation['muscles'],
- 'is_owner': template.user == request.user,
- 'owner_user': template.user,
- }
- return render(request, 'workout/template_view.html', context)
-
-
-def make_workout(request, pk):
- workout = get_object_or_404(Workout.both, pk=pk)
-
- if request.user != workout.user:
- return HttpResponseForbidden()
-
- workout.is_template = False
- workout.is_public = False
- workout.save()
-
- return HttpResponseRedirect(workout.get_absolute_url())
-
-
-class WorkoutMarkAsTemplateView(WgerFormMixin, LoginRequiredMixin, UpdateView):
- """
- Generic view to update an existing workout routine
- """
-
- model = Routine
- form_class = WorkoutMakeTemplateForm
-
- def get_context_data(self, **kwargs):
- context = super(WorkoutMarkAsTemplateView, self).get_context_data(**kwargs)
- context['title'] = _('Mark as template')
- return context