Self hosted FLOSS fitness/workout, nutrition and weight tracker
Move forms in gym app to own file
Roland Geider3349fa6bd02b
diff --git a/wger/core/forms.py b/wger/core/forms.pyindex 1343bbc90..563950bd1 100644--- a/wger/core/forms.py+++ b/wger/core/forms.py@@ -80,47 +80,6 @@ class UserPersonalInformationForm(UserEmailForm):fields = ('first_name', 'last_name', 'email')-class GymUserAddForm(UserPersonalInformationForm):- '''- Form used when adding a user to a gym- '''- USER = 'user'- GYM_ADMIN = 'admin'- TRAINER = 'trainer'- ROLES = (- (USER, _('User')),- (TRAINER, _('Trainer')),- (GYM_ADMIN, _('Gym administrator')),- )-- role = forms.ChoiceField(choices=ROLES,- initial=USER)- username = forms.RegexField(label=_("Username"),- max_length=30,- regex=r'^[\w.@+-]+$',- help_text=_("Required. 30 characters or fewer. Letters, digits and "- "@/./+/-/_ only."),- error_messages={- 'invalid': _("This value may contain only letters, numbers and "- "@/.//-/_ characters.")})-- class Meta:- model = User- fields = ('first_name', 'last_name', 'username', 'email', 'role',)-- def clean_username(self):- '''- Since User.username is unique, this check is redundant,- but it sets a nicer error message than the ORM. See #13147.- '''- username = self.cleaned_data["username"]- try:- User._default_manager.get(username=username)- except User.DoesNotExist:- return username- raise forms.ValidationError(_("A user with that username already exists."))--class PasswordConfirmationForm(Form):'''A simple password confirmation form.diff --git a/wger/gym/forms.py b/wger/gym/forms.pynew file mode 100644index 000000000..446515cea--- /dev/null+++ b/wger/gym/forms.py@@ -0,0 +1,61 @@+# -*- 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++from django.contrib.auth.models import User+from django import forms+from django.utils.translation import ugettext as _+from wger.core.forms import UserPersonalInformationForm+++class GymUserAddForm(UserPersonalInformationForm):+ '''+ Form used when adding a user to a gym+ '''+ USER = 'user'+ GYM_ADMIN = 'admin'+ TRAINER = 'trainer'+ ROLES = (+ (USER, _('User')),+ (TRAINER, _('Trainer')),+ (GYM_ADMIN, _('Gym administrator')),+ )++ role = forms.ChoiceField(choices=ROLES,+ initial=USER)+ username = forms.RegexField(label=_("Username"),+ max_length=30,+ regex=r'^[\w.@+-]+$',+ help_text=_("Required. 30 characters or fewer. Letters, digits and "+ "@/./+/-/_ only."),+ error_messages={+ 'invalid': _("This value may contain only letters, numbers and "+ "@/.//-/_ characters.")})++ class Meta:+ model = User+ fields = ('first_name', 'last_name', 'username', 'email', 'role',)++ def clean_username(self):+ '''+ Since User.username is unique, this check is redundant,+ but it sets a nicer error message than the ORM. See #13147.+ '''+ username = self.cleaned_data["username"]+ try:+ User._default_manager.get(username=username)+ except User.DoesNotExist:+ return username+ raise forms.ValidationError(_("A user with that username already exists."))diff --git a/wger/gym/views/gym.py b/wger/gym/views/gym.pyindex 5e0f7a630..ec2b4c180 100644--- a/wger/gym/views/gym.py+++ b/wger/gym/views/gym.py@@ -31,7 +31,7 @@ from django.views.generic import DeleteViewfrom django.views.generic import CreateViewfrom django.views.generic import UpdateView-from wger.core.forms import GymUserAddForm+from wger.gym.forms import GymUserAddFormfrom wger.gym.helpers import get_user_last_activity, is_any_gym_adminfrom wger.gym.models import Gym, GymConfigfrom wger.gym.models import GymAdminConfig