Skip to content

Commit

Permalink
Remove unused code and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Nov 28, 2024
1 parent 140137b commit 1d14386
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 501 deletions.
148 changes: 5 additions & 143 deletions wger/manager/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
"""
This file contains forms used in the application
"""

# Third Party
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit

# Django
from django.forms import (
BooleanField,
CharField,
ChoiceField,
DecimalField,
Form,
IntegerField,
ModelChoiceField,
ModelForm,
ModelMultipleChoiceField,
widgets,
Expand All @@ -35,27 +33,8 @@
gettext_lazy,
)

# Third Party
from crispy_forms.helper import FormHelper
from crispy_forms.layout import (
Column,
Layout,
Row,
Submit,
)

# wger
from wger.core.models import (
RepetitionUnit,
WeightUnit,
)
from wger.exercises.models import Exercise
from wger.manager.consts import RIR_OPTIONS
from wger.manager.models import (
Workout,
WorkoutLog,
WorkoutSession,
)
from wger.manager.models import Workout


class WorkoutForm(ModelForm):
Expand Down Expand Up @@ -98,123 +77,6 @@ def clean(self, value):
return sorted(qs, key=lambda x: int_list.index(x.pk))


class WorkoutLogForm(ModelForm):
"""
Helper form for a WorkoutLog.
These fields are re-defined here only to make them optional. Otherwise
all the entries in the formset would be required, which is not really what
we want. This form is one prime candidate to rework with some modern JS
framework, there is a ton of ugly logic like this just to make it work.
"""

repetition_unit = ModelChoiceField(
queryset=RepetitionUnit.objects.all(),
label=_('Unit'),
required=False,
)
weight_unit = ModelChoiceField(
queryset=WeightUnit.objects.all(),
label=_('Unit'),
required=False,
)
exercise_base = ModelChoiceField(
queryset=Exercise.objects.all(),
label=_('Exercise'),
required=False,
)
reps = IntegerField(
label=_('Repetitions'),
required=False,
)
weight = DecimalField(
label=_('Weight'),
initial=0,
required=False,
)
rir = ChoiceField(
label=_('RiR'),
choices=RIR_OPTIONS,
required=False,
)

class Meta:
model = WorkoutLog
exclude = ('workout',)


class WorkoutLogFormHelper(FormHelper):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.form_method = 'post'
self.layout = Layout(
'id',
Row(
Column('reps', css_class='col-2'),
Column('repetition_unit', css_class='col-3'),
Column('weight', css_class='col-2'),
Column('weight_unit', css_class='col-3'),
Column('rir', css_class='col-2'),
css_class='form-row',
),
)
self.form_show_labels = False
self.form_tag = False
self.disable_csrf = True
self.render_required_fields = True


class HelperWorkoutSessionForm(ModelForm):
"""
A helper form used in the workout log view
"""

class Meta:
model = WorkoutSession
exclude = ('user', 'workout')

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Row(
Column('date', css_class='col-6'),
Column('impression', css_class='col-6'),
css_class='form-row',
),
'notes',
Row(
Column('time_start', css_class='col-6'),
Column('time_end', css_class='col-6'),
css_class='form-row',
),
)
self.helper.form_tag = False


class WorkoutSessionForm(ModelForm):
"""
Workout Session form
"""

class Meta:
model = WorkoutSession
exclude = ('user', 'workout', 'date')

def __init__(self, *args, **kwargs):
super(WorkoutSessionForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
'impression',
'notes',
Row(
Column('time_start', css_class='col-6'),
Column('time_end', css_class='col-6'),
css_class='form-row',
),
)


class WorkoutScheduleDownloadForm(Form):
"""
Form for the workout schedule download
Expand Down
16 changes: 7 additions & 9 deletions wger/manager/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.platypus import (
Image,
KeepTogether,
ListFlowable,
ListItem,
Paragraph,
Table,
)
Expand Down Expand Up @@ -76,11 +73,13 @@ def render_workout_day(
set_count = 1
day_markers.append(len(data))

data.append([
Paragraph(
f'<para align="center">{_("Rest day") if day_data.day.is_rest else day_data.day.name}</para>',
styleSheet['SubHeader'],
)]
data.append(
[
Paragraph(
f'<para align="center">{_("Rest day") if day_data.day.is_rest else day_data.day.name}</para>',
styleSheet['SubHeader'],
)
]
)

# Note: the _('Date') will be on the 3rd cell, but since we make a span
Expand All @@ -92,7 +91,6 @@ def render_workout_day(
exercise_start = len(data)
slot_count = 0
for slot in day_data.slots_display_mode:

slot_count += 1

group_exercise_marker[slot_count] = {'start': len(data), 'end': len(data)}
Expand Down
3 changes: 2 additions & 1 deletion wger/manager/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def update_cache_rir_config(sender, instance: RiRConfig, **kwargs):


def update_cache_log(sender, instance: WorkoutLog, **kwargs):
reset_routine_cache(instance.routine)
if instance.routine:
reset_routine_cache(instance.routine)


post_save.connect(update_activity_cache, sender=WorkoutSession)
Expand Down
79 changes: 0 additions & 79 deletions wger/manager/templates/log/add.html

This file was deleted.

35 changes: 1 addition & 34 deletions wger/manager/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

# Django
from django.conf.urls import include
from django.contrib.auth.decorators import login_required
from django.urls import (
path,
re_path,
Expand All @@ -27,13 +26,11 @@
from wger.core.views.react import ReactView
from wger.manager.views import (
ical,
log,
pdf,
routine,
schedule,
schedule_step,
workout,
workout_session,
)

# sub patterns for workout logs
Expand All @@ -43,16 +40,6 @@
ReactView.as_view(login_required=True),
name='log',
),
path(
'<int:pk>/edit', # JS
log.WorkoutLogUpdateView.as_view(),
name='edit',
),
path(
'<int:pk>/delete',
log.WorkoutLogDeleteView.as_view(),
name='delete',
),
]

# sub patterns for templates
Expand Down Expand Up @@ -146,25 +133,6 @@
),
]

# sub patterns for workout sessions
patterns_session = [
re_path(
r'^(?P<workout_pk>\d+)/add/(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$',
workout_session.WorkoutSessionAddView.as_view(),
name='add',
),
path(
'<int:pk>/edit',
workout_session.WorkoutSessionUpdateView.as_view(),
name='edit',
),
re_path(
r'^(?P<pk>\d+)/delete/(?P<logs>session|logs)?$',
workout_session.WorkoutSessionDeleteView.as_view(),
name='delete',
),
]

# sub patterns for schedules
patterns_schedule = [
path(
Expand Down Expand Up @@ -272,9 +240,8 @@
path('', include((patterns_workout, 'workout'), namespace='workout')),
path('', include((patterns_routine, 'routine'), namespace='routine')),
path('template/', include((patterns_templates, 'template'), namespace='template')),
path('<int:routine_pk>/day/', include((patterns_days, 'day'), namespace='template')),
path('<int:routine_pk>/day/', include((patterns_days, 'day'), namespace='day')),
path('log/', include((patterns_log, 'log'), namespace='log')),
path('session/', include((patterns_session, 'session'), namespace='session')),
path('schedule/', include((patterns_schedule, 'schedule'), namespace='schedule')),
path('schedule/step/', include((patterns_step, 'step'), namespace='step')),
]
Loading

0 comments on commit 1d14386

Please sign in to comment.