Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove more unused classes

Roland Geider787fd1ed5fb2
diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.py
index 8be0a4821..f98b5ab8f 100644
--- a/wger/exercises/views/exercises.py
+++ b/wger/exercises/views/exercises.py
@@ -15,32 +15,16 @@
# Standard Library
import logging
-import uuid
# Django
-from django.conf import settings
from django.contrib.auth.mixins import (
LoginRequiredMixin,
PermissionRequiredMixin,
)
-from django.core.exceptions import ValidationError
-from django.forms import (
- CharField,
- CheckboxSelectMultiple,
- ModelChoiceField,
- ModelForm,
- ModelMultipleChoiceField,
- Select,
- Textarea,
-)
-from django.http import (
- HttpResponsePermanentRedirect,
- HttpResponseRedirect,
-)
-from django.shortcuts import (
- get_object_or_404,
- render,
-)
+
+from django.http import HttpResponsePermanentRedirect
+
+from django.shortcuts import get_object_or_404
from django.urls import (
reverse,
reverse_lazy,
@@ -55,20 +39,8 @@ from django.views.generic import (
)
# wger
-from wger.exercises.models import (
- Equipment,
- Exercise,
- ExerciseCategory,
- Muscle,
-)
-from wger.manager.models import WorkoutLog
-from wger.utils.constants import MIN_EDIT_DISTANCE_THRESHOLD
+from wger.exercises.models import Exercise
from wger.utils.generic_views import WgerDeleteMixin
-from wger.utils.helpers import levenshtein
-from wger.utils.language import load_language
-from wger.utils.widgets import TranslatedSelectMultiple
-from wger.weight.helpers import process_log_entries
-
logger = logging.getLogger(__name__)
@@ -96,78 +68,6 @@ def view(request, id, slug=None):
)
-class ExerciseForm(ModelForm):
- # Redefine some fields here to set some properties
- # (some of this could be done with a crispy form helper and would be
- # a cleaner solution)
- category = ModelChoiceField(queryset=ExerciseCategory.objects.all(), widget=Select())
- muscles = ModelMultipleChoiceField(
- queryset=Muscle.objects.all(),
- widget=CheckboxSelectMultiple(),
- required=False,
- )
-
- muscles_secondary = ModelMultipleChoiceField(
- queryset=Muscle.objects.all(),
- widget=CheckboxSelectMultiple(),
- required=False,
- )
-
- equipment = ModelMultipleChoiceField(
- queryset=Equipment.objects.all(),
- widget=CheckboxSelectMultiple(),
- required=False,
- )
-
- description = CharField(
- label=_('Description'),
- widget=Textarea,
- required=False,
- )
-
- class Meta:
- model = Exercise
- widgets = {'equipment': TranslatedSelectMultiple()}
- fields = [
- 'name',
- 'category',
- 'description',
- 'muscles',
- 'muscles_secondary',
- 'equipment',
- 'license',
- 'license_author',
- ]
-
- class Media:
- js = (settings.STATIC_URL + 'yarn/tinymce/tinymce.min.js', )
-
- def clean_name(self):
- """
- Throws a validation error if the newly submitted name is too similar to
- an existing exercise's name
- """
- name = self.cleaned_data['name']
-
- if not self.instance.id:
- language = load_language()
- exercises = Exercise.objects.all() \
- .filter(language=language)
- for exercise in exercises:
- exercise_name = str(exercise)
- min_edit_dist = levenshtein(exercise_name.casefold(), name.casefold())
- if min_edit_dist < MIN_EDIT_DISTANCE_THRESHOLD:
- raise ValidationError(
- _('%(name)s is too similar to existing exercise '
- '"%(exercise_name)s"'),
- params={
- 'name': name,
- 'exercise_name': exercise_name
- },
- )
- return name
-
-
class ExerciseDeleteView(
WgerDeleteMixin,
LoginRequiredMixin,
diff --git a/wger/utils/helpers.py b/wger/utils/helpers.py
index c7f624980..2396b7f95 100644
--- a/wger/utils/helpers.py
+++ b/wger/utils/helpers.py
@@ -37,7 +37,6 @@ from django.utils.http import (
urlsafe_base64_encode,
)
-
logger = logging.getLogger(__name__)
@@ -215,39 +214,11 @@ def normalize_decimal(d):
normalized = d.normalize()
sign, digits, exponent = normalized.as_tuple()
if exponent > 0:
- return decimal.Decimal((sign, digits + (0, ) * exponent, 0))
+ return decimal.Decimal((sign, digits + (0,) * exponent, 0))
else:
return normalized
-def levenshtein(s1, s2):
- """
- The Levenshtein distance
-
- This is used as a string metric for measuring the difference between
- two sequences. We use this to determine whether or not similar
- exercises have been added
-
- Source: Wikipedia
-
- :param input: two input strings
- :return: number of characters different between the strings
- """
- if len(s1) > len(s2):
- s1, s2 = s2, s1
-
- distances = range(len(s1) + 1)
- for i2, c2 in enumerate(s2):
- distances_ = [i2 + 1]
- for i1, c1 in enumerate(s1):
- if c1 == c2:
- distances_.append(distances[i1])
- else:
- distances_.append(1 + min((distances[i1], distances[i1 + 1], distances_[-1])))
- distances = distances_
- return distances[-1]
-
-
def random_string(length=32):
"""
Generates a random string