all lifts view
This commit is contained in:
parent
e9b9abef20
commit
aa1e7efff9
@ -11,6 +11,9 @@ SET_TYPES = (
|
|||||||
class Exercise(models.Model):
|
class Exercise(models.Model):
|
||||||
names = ArrayField(models.CharField(max_length=200))
|
names = ArrayField(models.CharField(max_length=200))
|
||||||
|
|
||||||
|
def display_name(self):
|
||||||
|
return self.names[0].title()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ', '.join(self.names)
|
return ', '.join(self.names)
|
||||||
|
|
||||||
|
@ -5,6 +5,9 @@ from lifting.utils import round_to
|
|||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
def remove_exponent(d):
|
||||||
|
return d.quantize(decimal.Decimal(1)) if d == d.to_integral() else d.normalize()
|
||||||
|
|
||||||
|
|
||||||
class MassNode(template.Node):
|
class MassNode(template.Node):
|
||||||
def __init__(self, weight):
|
def __init__(self, weight):
|
||||||
@ -14,12 +17,17 @@ class MassNode(template.Node):
|
|||||||
try:
|
try:
|
||||||
weight_kg = self.weight.resolve(context)
|
weight_kg = self.weight.resolve(context)
|
||||||
if context['user'].profile.lifting_units == 'i':
|
if context['user'].profile.lifting_units == 'i':
|
||||||
return round_to(weight_kg * decimal.Decimal("2.2046"), decimal.Decimal("0.125"))
|
return remove_exponent(round_to(weight_kg * decimal.Decimal("2.2046"),
|
||||||
|
decimal.Decimal("0.125")))
|
||||||
else:
|
else:
|
||||||
return weight_kg
|
return remove_exponent(weight_kg)
|
||||||
except template.VariableDoesNotExist:
|
except template.VariableDoesNotExist:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
class MassLabelNode(template.Node):
|
||||||
|
def render(self, context):
|
||||||
|
return {'i': 'lbs', 'm': 'kg'}[context['user'].profile.lifting_units]
|
||||||
|
|
||||||
|
|
||||||
@register.tag
|
@register.tag
|
||||||
def mass_unit(parser, token):
|
def mass_unit(parser, token):
|
||||||
@ -30,3 +38,8 @@ def mass_unit(parser, token):
|
|||||||
"{!r} tag requires exactly one argument".format(tag_name)
|
"{!r} tag requires exactly one argument".format(tag_name)
|
||||||
)
|
)
|
||||||
return MassNode(weight)
|
return MassNode(weight)
|
||||||
|
|
||||||
|
|
||||||
|
@register.tag
|
||||||
|
def mass_label(parser, token):
|
||||||
|
return MassLabelNode()
|
||||||
|
@ -7,6 +7,8 @@ urlpatterns = [
|
|||||||
name='lifting-month'),
|
name='lifting-month'),
|
||||||
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', views.day_lifts,
|
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', views.day_lifts,
|
||||||
name='lifting-day'),
|
name='lifting-day'),
|
||||||
|
url(r'^lifts/$', views.lift_list),
|
||||||
|
url(r'^lifts/(?P<lift_id>\d+)/$', views.by_lift),
|
||||||
|
|
||||||
url(r'^fitnotes/$', views.fitnotes_upload),
|
url(r'^fitnotes/$', views.fitnotes_upload),
|
||||||
]
|
]
|
||||||
|
@ -8,9 +8,10 @@ from django.shortcuts import render
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.views.generic import dates
|
from django.views.generic import dates
|
||||||
|
from django.db.models import Count, Max
|
||||||
|
|
||||||
from . import importers
|
from . import importers
|
||||||
from .models import Set
|
from .models import Set, Exercise
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -65,6 +66,20 @@ def day_lifts(request, year, month, day):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def lift_list(request):
|
||||||
|
lifts = Exercise.objects.filter(sets__user=request.user).annotate(
|
||||||
|
total=Count('sets'), max_kg=Max('sets__weight_kg'),
|
||||||
|
last_date=Max('sets__date'),
|
||||||
|
)
|
||||||
|
return render(request, 'lifting/lift_list.html', {'lifts': lifts})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def by_lift(request, lift_id):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FitnotesUploadForm(forms.Form):
|
class FitnotesUploadForm(forms.Form):
|
||||||
file = forms.FileField()
|
file = forms.FileField()
|
||||||
|
|
||||||
|
39
templates/lifting/lift_list.html
Normal file
39
templates/lifting/lift_list.html
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load lifting %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<section class="row header-row">
|
||||||
|
<section class="col-sm-12">
|
||||||
|
<h3>All Lifts</h3>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="row">
|
||||||
|
<section class="col-sm-12">
|
||||||
|
<table class="table lifts-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Exercise</th>
|
||||||
|
<th>Total Sets</th>
|
||||||
|
<th>Last Set</th>
|
||||||
|
<th>Max Weight</th>
|
||||||
|
<th>Estimated 1RM</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for lift in lifts %}
|
||||||
|
<tr>
|
||||||
|
<td>{{lift.display_name}}</td>
|
||||||
|
<td>{{lift.total}}</td>
|
||||||
|
<td>{{lift.last_date}}</td>
|
||||||
|
<td>{% mass_unit lift.max_kg %} {% mass_label %}</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user