added birth date & sex to user model
This commit is contained in:
@@ -356,6 +356,7 @@ class RegistrationFormTermsOfService(RegistrationForm):
|
||||
error_messages={'required': "You must agree to the terms to register"})
|
||||
|
||||
|
||||
|
||||
class RegistrationFormUniqueEmail(RegistrationFormTermsOfService):
|
||||
"""
|
||||
Subclass of ``RegistrationFormTermsOfService`` which enforces uniqueness of
|
||||
@@ -370,6 +371,35 @@ class RegistrationFormUniqueEmail(RegistrationFormTermsOfService):
|
||||
raise forms.ValidationError("This email address is already in use. Please supply a different email address.")
|
||||
return self.cleaned_data['email']
|
||||
|
||||
class RegistrationFormSex(RegistrationFormUniqueEmail):
|
||||
sexcategories = (
|
||||
('female','female'),
|
||||
('male','male'),
|
||||
('not specified','not specified'),
|
||||
)
|
||||
|
||||
weightcategories = (
|
||||
('hwt','heavy-weight'),
|
||||
('lwt','light-weight'),
|
||||
)
|
||||
|
||||
birthdate = forms.DateTimeField(widget=SelectDateWidget(
|
||||
years=range(timezone.now().year-100,timezone.now().year-10)),
|
||||
initial = datetime.date(year=1970,
|
||||
month=4,
|
||||
day=15))
|
||||
|
||||
sex = forms.ChoiceField(required=True,
|
||||
choices=sexcategories,
|
||||
initial='not specified',
|
||||
label='Sex')
|
||||
|
||||
weightcategory = forms.ChoiceField(label='Weight Category',
|
||||
choices=weightcategories)
|
||||
|
||||
# def __init__(self, *args, **kwargs):
|
||||
# self.fields['sex'].initial = 'not specified'
|
||||
|
||||
# Time field supporting microseconds. Not used, I believe.
|
||||
class MyTimeField(forms.TimeField):
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from django import forms
|
||||
from django.forms import ModelForm
|
||||
from django.dispatch import receiver
|
||||
from django.forms.widgets import SplitDateTimeWidget
|
||||
from django.forms.extras.widgets import SelectDateWidget
|
||||
from django.forms.formsets import BaseFormSet
|
||||
from datetimewidget.widgets import DateTimeWidget
|
||||
from django.core.validators import validate_email
|
||||
@@ -210,6 +211,12 @@ class Rower(models.Model):
|
||||
('lwt','light-weight'),
|
||||
)
|
||||
|
||||
sexcategories = (
|
||||
('male','male'),
|
||||
('female','female'),
|
||||
('not specified','not specified'),
|
||||
)
|
||||
|
||||
stravatypes = (
|
||||
('Ride','Ride'),
|
||||
('Kitesurf','Kitesurf'),
|
||||
@@ -257,6 +264,11 @@ class Rower(models.Model):
|
||||
max_length=30,
|
||||
choices=weightcategories)
|
||||
|
||||
sex = models.CharField(default="not specified",
|
||||
max_length=30,
|
||||
choices=sexcategories)
|
||||
|
||||
birthdate = models.DateField(null=True,blank=True)
|
||||
# Power Zone Data
|
||||
ftp = models.IntegerField(default=226,verbose_name="Functional Threshold Power")
|
||||
|
||||
@@ -939,10 +951,17 @@ class RowerPowerZonesForm(ModelForm):
|
||||
class AccountRowerForm(ModelForm):
|
||||
class Meta:
|
||||
model = Rower
|
||||
fields = ['weightcategory','getemailnotifications',
|
||||
fields = ['sex','birthdate','weightcategory','getemailnotifications',
|
||||
'defaulttimezone','showfavoritechartnotes',
|
||||
'defaultlandingpage']
|
||||
|
||||
widgets = {
|
||||
'birthdate': SelectDateWidget(
|
||||
years=range(
|
||||
timezone.now().year-100,timezone.now().year-10)),
|
||||
}
|
||||
|
||||
|
||||
def clean_email(self):
|
||||
email = self.cleaned_data.get('email')
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ from rowers.forms import (
|
||||
SummaryStringForm,IntervalUpdateForm,StrokeDataForm,
|
||||
StatsOptionsForm,PredictedPieceForm,DateRangeForm,DeltaDaysForm,
|
||||
EmailForm, RegistrationForm, RegistrationFormTermsOfService,
|
||||
RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm,
|
||||
RegistrationFormUniqueEmail,RegistrationFormSex,
|
||||
CNsummaryForm,UpdateWindForm,
|
||||
UpdateStreamForm,WorkoutMultipleCompareForm,ChartParamChoiceForm,
|
||||
FusionMetricChoiceForm,BoxPlotChoiceForm,MultiFlexChoiceForm,
|
||||
TrendFlexModalForm,WorkoutSplitForm,WorkoutJoinParamForm,
|
||||
@@ -772,20 +773,25 @@ def add_defaultfavorites(r):
|
||||
# User registration
|
||||
def rower_register_view(request):
|
||||
if request.method == 'POST':
|
||||
form = RegistrationFormUniqueEmail(request.POST)
|
||||
#form = RegistrationFormUniqueEmail(request.POST)
|
||||
form = RegistrationFormSex(request.POST)
|
||||
if form.is_valid():
|
||||
first_name = form.cleaned_data['first_name']
|
||||
last_name = form.cleaned_data['last_name']
|
||||
email = form.cleaned_data['email']
|
||||
password = form.cleaned_data['password1']
|
||||
username = form.cleaned_data['username']
|
||||
sex = form.cleaned_data['sex']
|
||||
birthdate = form.cleaned_data['birthdate']
|
||||
weightcategory = form.cleaned_data['weightcategory']
|
||||
theuser = User.objects.create_user(username,password=password)
|
||||
theuser.first_name = first_name
|
||||
theuser.last_name = last_name
|
||||
theuser.email = email
|
||||
theuser.save()
|
||||
|
||||
therower = Rower(user=theuser)
|
||||
therower = Rower(user=theuser,sex=sex,birthdate=birthdate,
|
||||
weightcategory=weightcategory)
|
||||
|
||||
therower.save()
|
||||
|
||||
@@ -843,7 +849,7 @@ Oh, one more thing. The site is currently in beta and is developing fast. Bear w
|
||||
"registration_form.html",
|
||||
{'form':form})
|
||||
else:
|
||||
form = RegistrationFormUniqueEmail()
|
||||
form = RegistrationFormSex()
|
||||
return render(request,
|
||||
"registration_form.html",
|
||||
{'form':form,})
|
||||
@@ -10226,8 +10232,10 @@ def rower_edit_view(request,message=""):
|
||||
first_name = ucd['first_name']
|
||||
last_name = ucd['last_name']
|
||||
email = ucd['email']
|
||||
sex = cd['sex']
|
||||
defaultlandingpage = cd['defaultlandingpage']
|
||||
weightcategory = cd['weightcategory']
|
||||
birthdate = cd['birthdate']
|
||||
showfavoritechartnotes = cd['showfavoritechartnotes']
|
||||
getemailnotifications = cd['getemailnotifications']
|
||||
defaulttimezone=cd['defaulttimezone']
|
||||
@@ -10246,6 +10254,8 @@ def rower_edit_view(request,message=""):
|
||||
r.getemailnotifications = getemailnotifications
|
||||
r.defaultlandingpage = defaultlandingpage
|
||||
r.showfavoritechartnotes = showfavoritechartnotes
|
||||
r.sex = sex
|
||||
r.birthdate = birthdate
|
||||
r.save()
|
||||
form = RowerForm(instance=r)
|
||||
powerform = RowerPowerForm(instance=r)
|
||||
|
||||
Reference in New Issue
Block a user