Self hosted FLOSS fitness/workout, nutrition and weight tracker
Move forms to core app
Roland Geiderafa77597c53b
diff --git a/wger/core/forms.py b/wger/core/forms.pynew file mode 100644index 000000000..b99ac4fe3--- /dev/null+++ b/wger/core/forms.py@@ -0,0 +1,98 @@+# -*- 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 captcha.fields import ReCaptchaField+from django.contrib.auth.forms import UserCreationForm+from django.contrib.auth.models import User as Django_User+from django.core.exceptions import ValidationError+from django.forms import ModelForm, EmailField, Form, CharField, widgets+from django.utils.translation import ugettext as _++from wger.manager.models import UserProfile+++class UserPreferencesForm(ModelForm):+ class Meta:+ model = UserProfile+ fields = ('show_comments',+ 'show_english_ingredients',+ 'workout_reminder_active',+ 'workout_reminder',+ 'workout_duration',+ 'notification_language',+ 'timer_active',+ 'timer_pause')+++class UserEmailForm(ModelForm):+ email = EmailField(label=_("Email"),+ help_text=_("Only needed to reset your password in case you forget it."),+ required=False)++ class Meta:+ model = Django_User+ fields = ('email', )++ def clean_email(self):+ # Email must be unique systemwide+ email = self.cleaned_data["email"]+ if not email:+ return email+ try:+ Django_User.objects.get(email=email)+ except Django_User.DoesNotExist:+ return email+ raise ValidationError(_("This email is already used."))+++class RegistrationForm(UserCreationForm, UserEmailForm):+ '''+ Registration form+ '''+ captcha = ReCaptchaField(attrs={'theme': 'clean'},+ label=_('Confirmation text'),+ help_text=_('As a security measure, please enter the previous words'),)+++class RegistrationFormNoCaptcha(UserCreationForm, UserEmailForm):+ '''+ Registration form without captcha field++ This is used when registering through an app, in that case there is not+ such a spam danger and simplifies the registration process on a mobile+ device.+ '''+ pass+++class FeedbackRegisteredForm(Form):+ '''+ Feedback form used for logged in users+ '''+ comment = CharField(max_length=500,+ min_length=10,+ widget=widgets.Textarea,+ help_text=_('What do you want to say?'),+ required=True)+++class FeedbackAnonymousForm(FeedbackRegisteredForm):+ '''+ Feedback form used for anonymous users (has additionally a reCaptcha field)+ '''+ captcha = ReCaptchaField(attrs={'theme': 'clean'},+ label=_('Confirmation text'),+ help_text=_('As a security measure, please enter the previous words'),)diff --git a/wger/core/views/misc.py b/wger/core/views/misc.pyindex fe8001e33..de0d86552 100644--- a/wger/core/views/misc.py+++ b/wger/core/views/misc.py@@ -29,7 +29,8 @@ from django.contrib import messagesfrom django.contrib.auth.decorators import login_requiredfrom django.contrib.auth import login as django_login-from wger.manager import forms+from wger.core.forms import FeedbackRegisteredForm+from wger.core.forms import FeedbackAnonymousFormfrom wger.core.demo import create_demo_entriesfrom wger.core.demo import create_temporary_userfrom wger.manager.models import DaysOfWeek@@ -164,9 +165,9 @@ class FeedbackClass(FormView):(either with reCaptcha field or not)'''if self.request.user.userprofile.is_temporary:- return forms.FeedbackAnonymousForm+ return FeedbackAnonymousFormelse:- return forms.FeedbackRegisteredForm+ return FeedbackRegisteredFormdef form_valid(self, form):'''diff --git a/wger/core/views/user.py b/wger/core/views/user.pyindex f79d37b20..2839560c7 100644--- a/wger/core/views/user.py+++ b/wger/core/views/user.py@@ -30,15 +30,16 @@ from django.contrib.auth.decorators import login_requiredfrom django.contrib.auth.models import User as Django_Userfrom django.contrib.auth.views import login as django_loginviewfrom django.contrib import messages+from tastypie.models import ApiKeyfrom wger.exercises.models import Language-from wger.manager.forms import UserPreferencesForm-from wger.manager.forms import UserEmailForm-from wger.manager.forms import RegistrationForm-from wger.manager.forms import RegistrationFormNoCaptchafrom wger.utils.constants import USER_TABfrom wger.utils.user_agents import check_request_amazon, check_request_android+from wger.core.forms import UserPreferencesForm+from wger.core.forms import UserEmailForm+from wger.core.forms import RegistrationForm+from wger.core.forms import RegistrationFormNoCaptchalogger = logging.getLogger('wger.custom')diff --git a/wger/manager/forms.py b/wger/manager/forms.pyindex 969217ea1..44a9b7849 100644--- a/wger/manager/forms.py+++ b/wger/manager/forms.py@@ -20,26 +20,21 @@ This file contains forms used in the applicationfrom django.forms import Formfrom django.forms import ModelForm-from django.forms import EmailFieldfrom django.forms import DateFieldfrom django.forms import CharFieldfrom django.forms import DecimalField-from django.forms import ValidationErrorfrom django.forms import widgetsfrom django.forms import ModelChoiceField-from django.contrib.auth.forms import UserCreationForm-from django.contrib.auth.models import User as Django_Userfrom django.utils.translation import ugettext as _from captcha.fields import ReCaptchaFieldfrom wger.exercises.models import Exercise-from wger.manager.models import UserProfile, WorkoutSession+from wger.manager.models import WorkoutSessionfrom wger.manager.models import Workoutfrom wger.manager.models import Dayfrom wger.manager.models import Setfrom wger.manager.models import WorkoutLog-from wger.utils.widgets import TranslatedSelectMultiplefrom wger.utils.widgets import ExerciseAjaxSelectfrom wger.utils.constants import DATE_FORMATS@@ -47,60 +42,6 @@ from wger.utils.widgets import Html5DateInputfrom wger.utils.widgets import Html5NumberInput-class UserPreferencesForm(ModelForm):- class Meta:- model = UserProfile- fields = ('show_comments',- 'show_english_ingredients',- 'workout_reminder_active',- 'workout_reminder',- 'workout_duration',- 'notification_language',- 'timer_active',- 'timer_pause')---class UserEmailForm(ModelForm):- email = EmailField(label=_("Email"),- help_text=_("Only needed to reset your password in case you forget it."),- required=False)-- class Meta:- model = Django_User- fields = ('email', )-- def clean_email(self):- # Email must be unique systemwide- email = self.cleaned_data["email"]- if not email:- return email- try:- Django_User.objects.get(email=email)- except Django_User.DoesNotExist:- return email- raise ValidationError(_("This email is already used."))---class RegistrationForm(UserCreationForm, UserEmailForm):- '''- Registration form- '''- captcha = ReCaptchaField(attrs={'theme': 'clean'},- label=_('Confirmation text'),- help_text=_('As a security measure, please enter the previous words'),)---class RegistrationFormNoCaptcha(UserCreationForm, UserEmailForm):- '''- Registration form without captcha field-- This is used when registering through an app, in that case there is not- such a spam danger and simplifies the registration process on a mobile- device.- '''- pass--class DemoUserForm(Form):captcha = ReCaptchaField(attrs={'theme': 'clean'},label=_('Confirmation text'),@@ -119,26 +60,6 @@ class WorkoutCopyForm(Form):required=False)-class FeedbackRegisteredForm(Form):- '''- Feedback form used for logged in users- '''- comment = CharField(max_length=500,- min_length=10,- widget=widgets.Textarea,- help_text=_('What do you want to say?'),- required=True)---class FeedbackAnonymousForm(FeedbackRegisteredForm):- '''- Feedback form used for anonymous users (has additionally a reCaptcha field)- '''- captcha = ReCaptchaField(attrs={'theme': 'clean'},- label=_('Confirmation text'),- help_text=_('As a security measure, please enter the previous words'),)--class DayForm(ModelForm):class Meta:model = Day