Skip to content

armgit / wger

Public Imported from GitHub
0

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.py
new file mode 100644
index 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.py
index fe8001e33..de0d86552 100644
--- a/wger/core/views/misc.py
+++ b/wger/core/views/misc.py
@@ -29,7 +29,8 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth import login as django_login
-from wger.manager import forms
+from wger.core.forms import FeedbackRegisteredForm
+from wger.core.forms import FeedbackAnonymousForm
from wger.core.demo import create_demo_entries
from wger.core.demo import create_temporary_user
from 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 FeedbackAnonymousForm
else:
- return forms.FeedbackRegisteredForm
+ return FeedbackRegisteredForm
def form_valid(self, form):
'''
diff --git a/wger/core/views/user.py b/wger/core/views/user.py
index 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_required
from django.contrib.auth.models import User as Django_User
from django.contrib.auth.views import login as django_loginview
from django.contrib import messages
+
from tastypie.models import ApiKey
from 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 RegistrationFormNoCaptcha
from wger.utils.constants import USER_TAB
from 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 RegistrationFormNoCaptcha
logger = logging.getLogger('wger.custom')
diff --git a/wger/manager/forms.py b/wger/manager/forms.py
index 969217ea1..44a9b7849 100644
--- a/wger/manager/forms.py
+++ b/wger/manager/forms.py
@@ -20,26 +20,21 @@ This file contains forms used in the application
from django.forms import Form
from django.forms import ModelForm
-from django.forms import EmailField
from django.forms import DateField
from django.forms import CharField
from django.forms import DecimalField
-from django.forms import ValidationError
from django.forms import widgets
from django.forms import ModelChoiceField
-from django.contrib.auth.forms import UserCreationForm
-from django.contrib.auth.models import User as Django_User
from django.utils.translation import ugettext as _
from captcha.fields import ReCaptchaField
from wger.exercises.models import Exercise
-from wger.manager.models import UserProfile, WorkoutSession
+from wger.manager.models import WorkoutSession
from wger.manager.models import Workout
from wger.manager.models import Day
from wger.manager.models import Set
from wger.manager.models import WorkoutLog
-
from wger.utils.widgets import TranslatedSelectMultiple
from wger.utils.widgets import ExerciseAjaxSelect
from wger.utils.constants import DATE_FORMATS
@@ -47,60 +42,6 @@ from wger.utils.widgets import Html5DateInput
from 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