added OTW and workouttype to favoritechart model
This commit is contained in:
@@ -136,6 +136,12 @@ class FavoriteChart(models.Model):
|
|||||||
('finish','Finish Angle'),
|
('finish','Finish Angle'),
|
||||||
('peakforceangle','Peak Force Angle'),
|
('peakforceangle','Peak Force Angle'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
workouttypechoices = (
|
||||||
|
('ote','Erg/SkiErg'),
|
||||||
|
('otw','On The Water'),
|
||||||
|
('both','both')
|
||||||
|
)
|
||||||
|
|
||||||
plottypes = (
|
plottypes = (
|
||||||
('line','Line Chart'),
|
('line','Line Chart'),
|
||||||
@@ -143,15 +149,20 @@ class FavoriteChart(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
yparam1 = models.CharField(max_length=50,choices=y1params,verbose_name='Y1')
|
yparam1 = models.CharField(max_length=50,choices=y1params,verbose_name='Y1')
|
||||||
yparam2 = models.CharField(max_length=50,choices=y2params,verbose_name='Y2')
|
yparam2 = models.CharField(max_length=50,choices=y2params,verbose_name='Y2',default='None',blank=True)
|
||||||
xparam = models.CharField(max_length=50,choices=xparams,verbose_name='X')
|
xparam = models.CharField(max_length=50,choices=xparams,verbose_name='X')
|
||||||
plottype = models.CharField(max_length=50,choices=plottypes,default='line')
|
plottype = models.CharField(max_length=50,choices=plottypes,
|
||||||
|
default='line',
|
||||||
|
verbose_name='Chart Type')
|
||||||
|
workouttype = models.CharField(max_length=50,choices=workouttypechoices,
|
||||||
|
default='both',
|
||||||
|
verbose_name='Workout Type')
|
||||||
user = models.ForeignKey(Rower)
|
user = models.ForeignKey(Rower)
|
||||||
|
|
||||||
class FavoriteForm(ModelForm):
|
class FavoriteForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FavoriteChart
|
model = FavoriteChart
|
||||||
fields = ['xparam','yparam1','yparam2','plottype']
|
fields = ['xparam','yparam1','yparam2','plottype','workouttype']
|
||||||
|
|
||||||
class BaseFavoriteFormSet(BaseFormSet):
|
class BaseFavoriteFormSet(BaseFormSet):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
@@ -170,6 +181,15 @@ class BaseFavoriteFormSet(BaseFormSet):
|
|||||||
'Must have x parameter.',
|
'Must have x parameter.',
|
||||||
code='missing_xparam'
|
code='missing_xparam'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not yparam1:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
'Must have Y1 parameter.',
|
||||||
|
code='missing_yparam1'
|
||||||
|
)
|
||||||
|
|
||||||
|
if not yparam2:
|
||||||
|
yparam2 = 'None'
|
||||||
|
|
||||||
class Workout(models.Model):
|
class Workout(models.Model):
|
||||||
workouttypes = (
|
workouttypes = (
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<div class="grid_12 alpha">
|
||||||
|
<p> </p>
|
||||||
|
</div>
|
||||||
<div class="grid_12 alpha">
|
<div class="grid_12 alpha">
|
||||||
<div class="grid_2">
|
<div class="grid_2">
|
||||||
<p><input type="submit" value="Update Favorites" class="button green small"/></p>
|
<p><input type="submit" value="Update Favorites" class="button green small"/></p>
|
||||||
@@ -22,6 +25,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Include formset plugin - including jQuery dependency -->
|
<!-- Include formset plugin - including jQuery dependency -->
|
||||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||||
<script src="/static/js/jquery.formset.js"></script>
|
<script src="/static/js/jquery.formset.js"></script>
|
||||||
|
|||||||
@@ -163,6 +163,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if user.rower.rowerplan == 'pro' %}
|
||||||
<div id="favorites" class="grid_12 alpha">
|
<div id="favorites" class="grid_12 alpha">
|
||||||
<div class="grid_2 suffix_4 alpha">
|
<div class="grid_2 suffix_4 alpha">
|
||||||
{% if maxfav >= 0 %}
|
{% if maxfav >= 0 %}
|
||||||
@@ -193,7 +194,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% endlocaltime %}
|
{% endlocaltime %}
|
||||||
|
|||||||
@@ -198,6 +198,38 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if user.rower.rowerplan == 'pro' %}
|
||||||
|
<div id="favorites" class="grid_12 alpha">
|
||||||
|
<div class="grid_2 suffix_4 alpha">
|
||||||
|
{% if maxfav >= 0 %}
|
||||||
|
<a class="button gray small" href="/rowers/me/favoritecharts">Manage Favorites</a>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="grid_1">
|
||||||
|
{% if favoritenr > 0 %}
|
||||||
|
<a class="button blue small" href="/rowers/workout/{{ id }}/flexchart?favoritechart={{ favoritenr|add:-1 }}"><</a>
|
||||||
|
{% else %}
|
||||||
|
<p> </p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="grid_2">
|
||||||
|
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input class="grid_2 alpha button blue small" type="hidden" name="savefavorite" value="True">
|
||||||
|
<input class="grid_2 alpha button blue small" value="Make Favorite" type="Submit">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="grid_1">
|
||||||
|
{% if favoritenr < maxfav %}
|
||||||
|
<a class="button blue small" href="/rowers/workout/{{ id }}/flexchart?favoritechart={{ favoritenr|add:1 }}">></a>
|
||||||
|
{% else %}
|
||||||
|
<p> </p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% endlocaltime %}
|
{% endlocaltime %}
|
||||||
|
|||||||
@@ -2612,7 +2612,13 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
|||||||
mayedit=1
|
mayedit=1
|
||||||
|
|
||||||
|
|
||||||
favorites = FavoriteChart.objects.filter(user=r).order_by("id")
|
workouttype = 'ote'
|
||||||
|
if row.workouttype == 'water':
|
||||||
|
workouttype = 'otw'
|
||||||
|
|
||||||
|
|
||||||
|
favorites = FavoriteChart.objects.filter(user=r,
|
||||||
|
workouttype__in=[workouttype,'both']).order_by("id")
|
||||||
maxfav = len(favorites)-1
|
maxfav = len(favorites)-1
|
||||||
|
|
||||||
if 'xparam' in kwargs:
|
if 'xparam' in kwargs:
|
||||||
@@ -2633,9 +2639,13 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
|||||||
|
|
||||||
if 'yparam2' in kwargs:
|
if 'yparam2' in kwargs:
|
||||||
yparam2 = kwargs['yparam2']
|
yparam2 = kwargs['yparam2']
|
||||||
|
if yparam2 == '':
|
||||||
|
yparam2 = 'None'
|
||||||
else:
|
else:
|
||||||
if favorites:
|
if favorites:
|
||||||
yparam2 = favorites[favoritenr].yparam2
|
yparam2 = favorites[favoritenr].yparam2
|
||||||
|
if yparam2 == '':
|
||||||
|
yparam2 = 'None'
|
||||||
else:
|
else:
|
||||||
yparam2 = 'hr'
|
yparam2 = 'hr'
|
||||||
|
|
||||||
@@ -4492,18 +4502,19 @@ def workout_summary_edit_view(request,id,message="",successmessage=""
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@login_required()
|
@user_passes_test(promember,login_url="/login")
|
||||||
def rower_favoritecharts_view(request):
|
def rower_favoritecharts_view(request):
|
||||||
message = ''
|
message = ''
|
||||||
successmessage = ''
|
successmessage = ''
|
||||||
r = Rower.objects.get(user=request.user)
|
r = Rower.objects.get(user=request.user)
|
||||||
favorites = FavoriteChart.objects.filter(user=r).order_by('id')
|
favorites = FavoriteChart.objects.filter(user=r).order_by('id')
|
||||||
favorites_data = [{'yparam1':f.yparam1,
|
favorites_data = [{'yparam1':f.yparam1,
|
||||||
'yparam2':f.yparam2,
|
'yparam2':f.yparam2,
|
||||||
'xparam':f.xparam,
|
'xparam':f.xparam,
|
||||||
'plottype':f.plottype}
|
'plottype':f.plottype,
|
||||||
|
'workouttype':f.workouttype}
|
||||||
for f in favorites]
|
for f in favorites]
|
||||||
FavoriteChartFormSet = formset_factory(FavoriteForm,formset=BaseFavoriteFormSet)
|
FavoriteChartFormSet = formset_factory(FavoriteForm,formset=BaseFavoriteFormSet,extra=0)
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
favorites_formset = FavoriteChartFormSet(request.POST)
|
favorites_formset = FavoriteChartFormSet(request.POST)
|
||||||
@@ -4515,11 +4526,13 @@ def rower_favoritecharts_view(request):
|
|||||||
yparam2 = favorites_form.cleaned_data.get('yparam2')
|
yparam2 = favorites_form.cleaned_data.get('yparam2')
|
||||||
xparam = favorites_form.cleaned_data.get('xparam')
|
xparam = favorites_form.cleaned_data.get('xparam')
|
||||||
plottype = favorites_form.cleaned_data.get('plottype')
|
plottype = favorites_form.cleaned_data.get('plottype')
|
||||||
|
workouttype = favorites_form.cleaned_data.get('workouttype')
|
||||||
new_instances.append(FavoriteChart(user=r,
|
new_instances.append(FavoriteChart(user=r,
|
||||||
yparam1=yparam1,
|
yparam1=yparam1,
|
||||||
yparam2=yparam2,
|
yparam2=yparam2,
|
||||||
xparam=xparam,
|
xparam=xparam,
|
||||||
plottype=plottype))
|
plottype=plottype,
|
||||||
|
workouttype=workouttype))
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
FavoriteChart.objects.filter(user=r).delete()
|
FavoriteChart.objects.filter(user=r).delete()
|
||||||
|
|||||||
Reference in New Issue
Block a user