fix fitnotes for now
This commit is contained in:
parent
ffafa87cb8
commit
d31dbfbb54
@ -3,11 +3,26 @@ from django.db import transaction
|
||||
from lifting.models import Lift, Set
|
||||
|
||||
|
||||
DEFAULT_MAPPING = {
|
||||
'flat barbell bench press': 'barbell bench press',
|
||||
'barbell curl': 'barbell curl',
|
||||
'deadlift': 'barbell deadlift',
|
||||
'barbell squat': 'barbell squat',
|
||||
'overhead press': 'standing overhead press',
|
||||
'barbell front squat': 'barbell front squat',
|
||||
'barbell row': 'barbell row',
|
||||
'pull up': 'pull up',
|
||||
'chin up': 'chin up',
|
||||
'push up': 'push up',
|
||||
'dumbbell curl': 'dumbbell curl',
|
||||
}
|
||||
|
||||
|
||||
def _clean_name(name):
|
||||
return name.lower()
|
||||
|
||||
|
||||
def import_fitnotes_db(filename, user, fitnotes_to_lift):
|
||||
def import_fitnotes_db(filename, user, fitnotes_to_lift=DEFAULT_MAPPING):
|
||||
# lift name => id
|
||||
lift_ids = {_clean_name(l.name): l.id for l in Lift.objects.all()}
|
||||
|
||||
|
@ -3,5 +3,5 @@ from django.conf.urls import url
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^fitnotes/$', views.fitnotes_upload),
|
||||
url(r'^upload/$', views.fitnotes_upload),
|
||||
]
|
||||
|
@ -1,6 +1,13 @@
|
||||
import os
|
||||
import tempfile
|
||||
from django import forms
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from . import importer
|
||||
|
||||
class FitnotesUploadForm(forms.Form):
|
||||
file = forms.FileField()
|
||||
|
||||
@login_required
|
||||
def fitnotes_upload(request):
|
||||
if request.method == 'POST':
|
||||
|
54
inventory/migrations/3000_initial_data.py
Normal file
54
inventory/migrations/3000_initial_data.py
Normal file
@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
def make_bars(apps, schema_editor):
|
||||
Bar = apps.get_model('inventory', 'Bar')
|
||||
Bar.objects.bulk_create([
|
||||
Bar(name="Women's Olympic", weight_kg='15'),
|
||||
Bar(name="Men's Olympic", weight_kg='20'),
|
||||
])
|
||||
|
||||
|
||||
def reverse_bars(apps, schema_editor):
|
||||
Bar = apps.get_model('inventory', 'Bar')
|
||||
Bar.objects.all().delete()
|
||||
|
||||
|
||||
def make_lifts(apps, schema_editor):
|
||||
Lift = apps.get_model('inventory', 'Lift')
|
||||
Lift.objects.bulk_create([
|
||||
# bodybuilding.com links?
|
||||
Lift(name="Barbell Bench Press"),
|
||||
Lift(name="Barbell Curl"),
|
||||
Lift(name="Barbell Deadlift"),
|
||||
Lift(name="Barbell Squat"),
|
||||
Lift(name="Barbell Front Squat"),
|
||||
Lift(name="Barbell Deadlift"),
|
||||
Lift(name="Standing Overhead Press"),
|
||||
Lift(name="Barbell Row"),
|
||||
|
||||
Lift(name="Pull Up"),
|
||||
Lift(name="Chin Up"),
|
||||
Lift(name="Push Up"),
|
||||
|
||||
Lift(name="Dumbbell Curl"),
|
||||
])
|
||||
|
||||
def reverse_lifts(apps, schema_editor):
|
||||
Lift = apps.get_model('inventory', 'Lift')
|
||||
Lift.objects.all().delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(make_bars, reverse_code=reverse_bars),
|
||||
migrations.RunPython(make_lifts, reverse_code=reverse_lifts),
|
||||
]
|
@ -12,7 +12,7 @@ class MassNode(template.Node):
|
||||
def render(self, context):
|
||||
try:
|
||||
weight_kg = self.weight.resolve(context)
|
||||
if context['user'].profile.lifting_units == 'i':
|
||||
if context['user'].lifting_options.lifting_units == 'i':
|
||||
return to_lb(weight_kg)
|
||||
else:
|
||||
return remove_exponent(weight_kg)
|
||||
@ -21,7 +21,7 @@ class MassNode(template.Node):
|
||||
|
||||
class MassLabelNode(template.Node):
|
||||
def render(self, context):
|
||||
return {'i': 'lb', 'm': 'kg'}[context['user'].profile.lifting_units]
|
||||
return {'i': 'lb', 'm': 'kg'}[context['user'].lifting_options.lifting_units]
|
||||
|
||||
|
||||
@register.tag
|
||||
|
@ -10,7 +10,6 @@ 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 inventory.models import Lift
|
||||
|
||||
@ -83,10 +82,6 @@ def by_lift(request, lift_id):
|
||||
return render(request, 'lifting/by_lift.html', {'lift': lift, 'sets': sets})
|
||||
|
||||
|
||||
class FitnotesUploadForm(forms.Form):
|
||||
file = forms.FileField()
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_profile(request):
|
||||
form = request.user.profile
|
||||
|
@ -4,11 +4,11 @@ from django.contrib import admin
|
||||
from django.conf.urls.static import static
|
||||
|
||||
import lifting.urls
|
||||
import profiles.urls
|
||||
import fitnotes.urls
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^profile/', include(profiles.urls.urlpatterns)),
|
||||
url(r'^lifting/', include(lifting.urls.urlpatterns)),
|
||||
url(r'^fitnotes/', include(fitnotes.urls.urlpatterns)),
|
||||
|
||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
Loading…
Reference in New Issue
Block a user