lifting portion of form works
This commit is contained in:
parent
2f9fbc4d90
commit
f0a8f6b75c
@ -1,5 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from common import to_lb
|
from common import remove_exponent, to_lb
|
||||||
|
|
||||||
|
|
||||||
class Bar(models.Model):
|
class Bar(models.Model):
|
||||||
@ -7,7 +7,8 @@ class Bar(models.Model):
|
|||||||
weight_kg = models.DecimalField(max_digits=7, decimal_places=3)
|
weight_kg = models.DecimalField(max_digits=7, decimal_places=3)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{} ({}lb / {}kg)'.format(self.name, self.weight_kg, self.weight_lb)
|
return '{} ({}kg / {}lb)'.format(self.name, remove_exponent(self.weight_kg),
|
||||||
|
self.weight_lb)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def weight_lb(self):
|
def weight_lb(self):
|
||||||
@ -17,6 +18,10 @@ class Bar(models.Model):
|
|||||||
class Lift(models.Model):
|
class Lift(models.Model):
|
||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def display_name(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
from django import template
|
from django import template
|
||||||
from django.template.defaultfilters import stringfilter
|
from django.template.defaultfilters import stringfilter
|
||||||
from common import to_lb
|
from common import to_lb, remove_exponent
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
register.filter('decimal', remove_exponent)
|
||||||
|
|
||||||
|
|
||||||
class MassNode(template.Node):
|
class MassNode(template.Node):
|
||||||
def __init__(self, weight):
|
def __init__(self, weight):
|
||||||
self.weight = template.Variable(weight)
|
self.weight = template.Variable(weight)
|
||||||
|
@ -10,5 +10,5 @@ urlpatterns = [
|
|||||||
url(r'^lifts/$', views.lift_list, name='lift-list'),
|
url(r'^lifts/$', views.lift_list, name='lift-list'),
|
||||||
url(r'^lifts/(?P<lift_id>\d+)/$', views.by_lift, name='lift-detail'),
|
url(r'^lifts/(?P<lift_id>\d+)/$', views.by_lift, name='lift-detail'),
|
||||||
|
|
||||||
url(r'^edit/$', views.edit_profile, name='edit-profile'),
|
url(r'^options/$', views.edit_options, name='edit-options'),
|
||||||
]
|
]
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
import calendar
|
||||||
import datetime
|
import datetime
|
||||||
|
import decimal
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import calendar
|
from collections import defaultdict, Counter
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django import forms
|
from django import forms
|
||||||
@ -10,8 +11,9 @@ 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 django.db.models import Count, Max
|
||||||
|
|
||||||
|
from inventory.models import Lift, Bar
|
||||||
from .models import Set
|
from .models import Set
|
||||||
from inventory.models import Lift
|
from .forms import LiftingOptionsForm
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -83,7 +85,25 @@ def by_lift(request, lift_id):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def edit_profile(request):
|
def edit_options(request):
|
||||||
form = request.user.profile
|
lifting_options = request.user.lifting_options
|
||||||
|
|
||||||
return render(request, 'profiles/edit.html', {'form': form})
|
if request.method == 'POST':
|
||||||
|
print(request.POST)
|
||||||
|
plates = []
|
||||||
|
for weight, number in zip(request.POST.getlist('plate_weight'),
|
||||||
|
request.POST.getlist('plate_number')):
|
||||||
|
if weight and number:
|
||||||
|
plates += [decimal.Decimal(weight)] * int(number)
|
||||||
|
|
||||||
|
lifting_options.plate_pairs = plates
|
||||||
|
lifting_options.default_bar_id = int(request.POST.get('barbell'))
|
||||||
|
lifting_options.lifting_units = request.POST.get('lifting_units')
|
||||||
|
lifting_options.save()
|
||||||
|
|
||||||
|
bars = Bar.objects.all()
|
||||||
|
plates = sorted(Counter(lifting_options.plate_pairs).items())
|
||||||
|
|
||||||
|
return render(request, 'profiles/edit.html', {'lifting_options': lifting_options,
|
||||||
|
'bars': bars, 'plates': plates,
|
||||||
|
})
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% load lifting %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<section class="panel panel-default">
|
<section class="panel panel-default">
|
||||||
@ -37,22 +41,21 @@
|
|||||||
<label class="col-sm-4 control-label">Lifting Units:</label>
|
<label class="col-sm-4 control-label">Lifting Units:</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<div class="radio">
|
<div class="radio">
|
||||||
<input type="radio" name="lifting_unit" value="i">lbs</input>
|
<input type="radio" name="lifting_units" value="i" {% if lifting_options.lifting_units == "i" %}checked{% endif %} >lb</input>
|
||||||
</div>
|
</div>
|
||||||
<div class="radio">
|
<div class="radio">
|
||||||
<input type="radio" name="lifting_unit" value="m">kg</input>
|
<input type="radio" name="lifting_units" value="m" {% if lifting_options.lifting_units == "m" %}checked{% endif %}>kg</input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-4 control-label">Barbell:</label>
|
<label class="col-sm-4 control-label">Barbell:</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
|
{% for bar in bars %}
|
||||||
<div class="radio">
|
<div class="radio">
|
||||||
<input type="radio" name="barbell" value="1">Men's Olympic (44lbs / 20kg) </input>
|
<input type="radio" name="barbell" value="{{bar.id}}" {% if lifting_options.default_bar_id == bar.id %}checked{% endif %}>{{bar}}</input>
|
||||||
</div>
|
|
||||||
<div class="radio">
|
|
||||||
<input type="radio" name="barbell" value="2">Women's Olympic (33lbs / 15kg) </input>
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -63,37 +66,28 @@
|
|||||||
<tr><td>Weight</td><td># of Pairs</td></tr>
|
<tr><td>Weight</td><td># of Pairs</td></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
{% for weight, n in plates %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><input type="text" class="form-control" name="plate_weight" value="45"></input></td>
|
<td><input type="text" class="form-control" name="plate_weight" value="{{weight|decimal}}"></input></td>
|
||||||
<td><input type="text" class="form-control" name="plate_number" value="2"></input></td>
|
<td><input type="text" class="form-control" name="plate_number" value="{{n}}"></input></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><input type="text" class="form-control" name="plate_weight" value="25"></input></td>
|
<td><input type="text" class="form-control" name="plate_weight" value=""></input></td>
|
||||||
<td><input type="text" class="form-control" name="plate_number" value="1"></input></td>
|
<td><input type="text" class="form-control" name="plate_number" value=""></input></td>
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><input type="text" class="form-control" name="plate_weight" value="10"></input></td>
|
|
||||||
<td><input type="text" class="form-control" name="plate_number" value="1"></input></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><input type="text" class="form-control" name="plate_weight" value="5"></input></td>
|
|
||||||
<td><input type="text" class="form-control" name="plate_number" value="2"></input></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><input type="text" class="form-control" name="plate_weight" value="2.5"></input></td>
|
|
||||||
<td><input type="text" class="form-control" name="plate_number" value="1"></input></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><input type="text" class="form-control" name="plate_weight" value="1.25"></input></td>
|
|
||||||
<td><input type="text" class="form-control" name="plate_number" value="1"></input></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-12"><input type="submit" class="form-control" value="Save Changes"></input> </div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user