Skip to content

Commit

Permalink
Move extend_template to context preprocessor
Browse files Browse the repository at this point in the history
This way, it doesn't need to be set on the individual forms. The solution with
the different templates is kind of ugly and needs to go away in the future.
  • Loading branch information
rolandgeider committed Dec 7, 2020
1 parent 4824053 commit 2beef3f
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 30 deletions.
1 change: 0 additions & 1 deletion wger/core/views/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def get_context_data(self, **kwargs):
context['form_fields'] = context['form']
context['submit_text'] = _('Send')
context['contribute_url'] = reverse('software:contribute')
context['extend_template'] = 'base_empty.html' if self.request.is_ajax() else 'base.html'
return context

def get_form_class(self):
Expand Down
16 changes: 0 additions & 16 deletions wger/core/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def registration(request):

template_data['form'] = form
template_data['title'] = _('Register')
template_data['extend_template'] = 'base.html'

return render(request, 'form.html', template_data)

Expand Down Expand Up @@ -576,11 +575,6 @@ def get_form(self, form_class=None):
)
return form

def get_context_data(self, **kwargs):
context = super(WgerPasswordChangeView, self).get_context_data(**kwargs)
context['extend_template'] = 'base.html'
return context


class WgerPasswordResetView(PasswordResetView):
template_name = 'form.html'
Expand All @@ -594,11 +588,6 @@ def get_form(self, form_class=None):
form.helper.add_input(Submit('submit', _("Save"), css_class='btn-success btn-block'))
return form

def get_context_data(self, **kwargs):
context = super(WgerPasswordResetView, self).get_context_data(**kwargs)
context['extend_template'] = 'base.html'
return context


class WgerPasswordResetConfirmView(PasswordResetConfirmView):
template_name = 'form.html'
Expand All @@ -609,8 +598,3 @@ def get_form(self, form_class=None):
form.helper.form_class = 'wger-form'
form.helper.add_input(Submit('submit', _("Save"), css_class='btn-success btn-block'))
return form

def get_context_data(self, **kwargs):
context = super(WgerPasswordResetConfirmView, self).get_context_data(**kwargs)
context['extend_template'] = 'base.html'
return context
1 change: 0 additions & 1 deletion wger/gym/views/gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ def gym_permissions_user_edit(request, user_pk):

context = {'title': member.get_full_name(),
'form': form,
'extend_template': 'base_empty.html' if request.is_ajax() else 'base.html',
'submit_text': 'Save'}

return render(request, 'form.html', context)
Expand Down
1 change: 0 additions & 1 deletion wger/manager/views/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ def add(request, pk):
context['helper'] = WorkoutLogFormHelper()
context['session_form'] = session_form
context['form'] = session_form
context['extend_template'] = 'base.html'
context['form_action'] = request.path

return render(request, 'log/add.html', context)
Expand Down
1 change: 0 additions & 1 deletion wger/manager/views/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def create(request, day_pk):
context['max_sets'] = Set.MAX_SETS
context['formsets'] = formsets
context['helper'] = WorkoutLogFormHelper()
context['extend_template'] = 'base_empty.html' if request.is_ajax() else 'base.html'
return render(request, 'set/add.html', context)


Expand Down
1 change: 0 additions & 1 deletion wger/manager/views/workout.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def copy_workout(request, pk):
template_data['form'] = workout_form
template_data['form_fields'] = [workout_form['comment']]
template_data['submit_text'] = _('Copy')
template_data['extend_template'] = 'base_empty.html' if request.is_ajax() else 'base.html'

return render(request, 'form.html', template_data)

Expand Down
2 changes: 1 addition & 1 deletion wger/nutrition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Meta:
editable=False,
on_delete=models.CASCADE)
creation_date = models.DateField(_('Creation date'), auto_now_add=True)
description = models.CharField(max_length=(80),
description = models.CharField(max_length=80,
blank=True,
verbose_name=_('Description'),
help_text=_('A description of the goal of the plan, e.g. '
Expand Down
3 changes: 3 additions & 0 deletions wger/utils/context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def processor(request):

# current gym, if available
'custom_header': get_custom_header(request),

# Template to extend in forms, kinda ugly
'extend_template': 'base_empty.html' if request.is_ajax() else 'base.html'
}

# Pseudo-intelligent navigation here
Expand Down
8 changes: 0 additions & 8 deletions wger/utils/generic_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ def get_context_data(self, **kwargs):
# Custom JS code on form (autocompleter, editor, etc.)
context['custom_js'] = self.custom_js

# Template to extend. For AJAX requests we don't need the rest of the
# template, only the form
context['extend_template'] = 'base_empty.html' if self.request.is_ajax() else 'base.html'

return context

def dispatch(self, request, *args, **kwargs):
Expand Down Expand Up @@ -273,10 +269,6 @@ def get_context_data(self, **kwargs):
# Additional delete message
context['delete_message'] = self.delete_message_extra

# Template to extend. For AJAX requests we don't need the rest of the
# template, only the form
context['extend_template'] = 'base_empty.html' if self.request.is_ajax() else 'base.html'

return context

def get_form(self, form_class=None):
Expand Down

0 comments on commit 2beef3f

Please sign in to comment.