Private
Public Access
1
0

flexall using form

This commit is contained in:
Sander Roosendaal
2018-10-08 13:08:49 +02:00
parent 3a968b45fe
commit 320bc860c5
4 changed files with 153 additions and 220 deletions

View File

@@ -7,12 +7,38 @@ from django.contrib.auth.models import User
from django.contrib.admin.widgets import AdminDateWidget
from django.forms.extras.widgets import SelectDateWidget
from django.utils import timezone,translation
from django.forms import ModelForm
from django.forms import ModelForm, Select
import dataprep
import types
import datetime
from django.forms import formset_factory
from utils import landingpages
from metrics import axes
class SelectWidget(Select):
"""
Subclass of Django's select widget that allows disabling options.
"""
def __init__(self, *args, **kwargs):
self._disabled_choices = []
super(SelectWidget, self).__init__(*args, **kwargs)
@property
def disabled_choices(self):
return self._disabled_choices
@disabled_choices.setter
def disabled_choices(self, other):
self._disabled_choices = other
def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
option_dict = super(SelectWidget, self).create_option(
name, value, label, selected, index, subindex=subindex, attrs=attrs
)
if value in self.disabled_choices:
option_dict['attrs']['disabled'] = 'disabled'
return option_dict
# login form
class LoginForm(forms.Form):
@@ -29,6 +55,7 @@ class EmailForm(forms.Form):
message = forms.CharField()
# Upload the CrewNerd Summary CSV
class CNsummaryForm(forms.Form):
file = forms.FileField(required=True,validators=[must_be_csv])
@@ -919,3 +946,59 @@ class VirtualRaceSelectForm(forms.Form):
self.fields['country'] = forms.ChoiceField(
choices = get_countries(),initial='All'
)
class FlexAxesForm(forms.Form):
axchoices = (
(ax[0],ax[1]) for ax in axes if ax[0] not in ['cumdist','None']
)
yaxchoices = (
(ax[0], ax[1]) for ax in axes if ax[0] not in ['cumdist','distance','time']
)
yaxchoices2 = (
(ax[0], ax[1]) for ax in axes if ax[0] not in ['cumdist','distance','time']
)
xaxis = forms.ChoiceField(
choices=axchoices,label='X-Axis',widget=SelectWidget,required=True)
yaxis1 = forms.ChoiceField(
choices=yaxchoices,label='Left Axis',widget=SelectWidget,required=True)
yaxis2 = forms.ChoiceField(
choices=yaxchoices2,label='Right Axis',widget=SelectWidget,required=True)
def __init__(self,request,*args,**kwargs):
super(FlexAxesForm, self).__init__(*args, **kwargs)
rower = Rower.objects.get(user=request.user)
axchoicespro = (
('',ax[1]) if ax[4] == 'pro' and ax[0] else (ax[0],ax[1]) for ax in axes
)
axchoicesbasicx = []
axchoicesbasicy = []
for ax in axes:
if ax[4] != 'pro' and ax[0] != 'cumdist':
if ax[0] != 'None':
axchoicesbasicx.insert(0,(ax[0],ax[1]))
if ax[0] not in ['cumdist','distance','time']:
axchoicesbasicy.insert(0,(ax[0],ax[1]))
else:
if ax[0] != 'None':
axchoicesbasicx.insert(0,('None',ax[1]+' (PRO)'))
if ax[0] not in ['cumdist','distance','time']:
axchoicesbasicy.insert(0,('None',ax[1]+' (PRO)'))
if rower.rowerplan == 'basic':
self.fields['xaxis'].choices = axchoicesbasicx
self.fields['yaxis1'].choices = axchoicesbasicy
self.fields['yaxis2'].choices = axchoicesbasicy