all lifts view

This commit is contained in:
James Turk 2015-04-07 17:33:05 -04:00
parent e9b9abef20
commit aa1e7efff9
5 changed files with 75 additions and 3 deletions

View File

@ -11,6 +11,9 @@ SET_TYPES = (
class Exercise(models.Model):
names = ArrayField(models.CharField(max_length=200))
def display_name(self):
return self.names[0].title()
def __str__(self):
return ', '.join(self.names)

View File

@ -5,6 +5,9 @@ from lifting.utils import round_to
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):
def __init__(self, weight):
@ -14,12 +17,17 @@ class MassNode(template.Node):
try:
weight_kg = self.weight.resolve(context)
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:
return weight_kg
return remove_exponent(weight_kg)
except template.VariableDoesNotExist:
return ''
class MassLabelNode(template.Node):
def render(self, context):
return {'i': 'lbs', 'm': 'kg'}[context['user'].profile.lifting_units]
@register.tag
def mass_unit(parser, token):
@ -30,3 +38,8 @@ def mass_unit(parser, token):
"{!r} tag requires exactly one argument".format(tag_name)
)
return MassNode(weight)
@register.tag
def mass_label(parser, token):
return MassLabelNode()

View File

@ -7,6 +7,8 @@ urlpatterns = [
name='lifting-month'),
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', views.day_lifts,
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),
]

View File

@ -8,9 +8,10 @@ from django.shortcuts import render
from django import forms
from django.contrib.auth.decorators import login_required
from django.views.generic import dates
from django.db.models import Count, Max
from . import importers
from .models import Set
from .models import Set, Exercise
@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):
file = forms.FileField()

View 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 %}