diff --git a/fitnotes/importer.py b/fitnotes/importer.py index 70d92c9..b5cf32d 100644 --- a/fitnotes/importer.py +++ b/fitnotes/importer.py @@ -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()} diff --git a/fitnotes/urls.py b/fitnotes/urls.py index 26cb2e9..663ba1c 100644 --- a/fitnotes/urls.py +++ b/fitnotes/urls.py @@ -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), ] diff --git a/fitnotes/views.py b/fitnotes/views.py index 17f90d6..a538c19 100644 --- a/fitnotes/views.py +++ b/fitnotes/views.py @@ -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': diff --git a/inventory/migrations/3000_initial_data.py b/inventory/migrations/3000_initial_data.py new file mode 100644 index 0000000..ac552d9 --- /dev/null +++ b/inventory/migrations/3000_initial_data.py @@ -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), + ] diff --git a/lifting/templatetags/lifting.py b/lifting/templatetags/lifting.py index 5b7f82e..79f17d4 100644 --- a/lifting/templatetags/lifting.py +++ b/lifting/templatetags/lifting.py @@ -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 diff --git a/lifting/views.py b/lifting/views.py index c872fb3..04a20fa 100644 --- a/lifting/views.py +++ b/lifting/views.py @@ -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 diff --git a/web/urls.py b/web/urls.py index 3076103..018aacb 100644 --- a/web/urls.py +++ b/web/urls.py @@ -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)