Correctly set form CSS class

Fixes #511
This commit is contained in:
Roland Geider
2020-09-12 21:46:47 +02:00
parent 96b1f50274
commit 6193aca71a
3 changed files with 16 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ Upgrade steps from 1.9:
🐛 Bug Fixes:
* `#499`_, `#505`_, `#504`_
* `#499`_, `#505`_, `#504`_, `#511`_
🧰 Maintenance:
@@ -46,6 +46,7 @@ Upgrade steps from 1.9:
.. _#501: https://github.com/wger-project/wger/issues/501
.. _#504: https://github.com/wger-project/wger/issues/504
.. _#505: https://github.com/wger-project/wger/issues/505
.. _#511: https://github.com/wger-project/wger/issues/511

View File

@@ -19,6 +19,10 @@ from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
# Third Party
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
# wger
from wger.core.forms import UserPersonalInformationForm
from wger.utils.widgets import BootstrapSelectMultiple
@@ -62,6 +66,9 @@ class GymUserPermissionForm(forms.ModelForm):
self.fields['role'] = forms.MultipleChoiceField(choices=field_choices,
initial=User,
widget=BootstrapSelectMultiple())
self.helper = FormHelper()
self.helper.form_class = 'wger-form'
self.helper.add_input(Submit('submit', _("Save"), css_class='btn-success btn-block'))
class GymUserAddForm(GymUserPermissionForm, UserPersonalInformationForm):

View File

@@ -310,11 +310,13 @@ def gym_permissions_user_edit(request, user_pk):
form = GymUserPermissionForm(initial={'role': initial_data},
available_roles=form_group_permission)
context = {}
context['title'] = member.get_full_name()
context['form'] = form
context['extend_template'] = 'base_empty.html' if request.is_ajax() else 'base.html'
context['submit_text'] = 'Save'
# Set form action to absolute path
form.helper.form_action = request.path
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)