From 0c08be888583ee6a6ece79265affbfbba4d127a9 Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 6 Apr 2015 13:51:33 -0400 Subject: [PATCH] initial day view --- lifting/urls.py | 5 ++++- lifting/views.py | 16 +++++++++++++++- templates/lifting/day.html | 12 ++++++++++++ templates/lifting/month.html | 4 +++- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 templates/lifting/day.html diff --git a/lifting/urls.py b/lifting/urls.py index 1e96603..85e6d63 100644 --- a/lifting/urls.py +++ b/lifting/urls.py @@ -3,7 +3,10 @@ from django.conf.urls import url from lifting import views urlpatterns = [ - url(r'^(?P\d{4})/(?P\d{1,2})/$', views.month, name='lifting-month'), + url(r'^(?P\d{4})/(?P\d{1,2})/$', views.month_lifts, + name='lifting-month'), + url(r'^(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/$', views.day_lifts, + name='lifting-day'), url(r'^fitnotes/$', views.fitnotes_upload), ] diff --git a/lifting/views.py b/lifting/views.py index 699632d..b336086 100644 --- a/lifting/views.py +++ b/lifting/views.py @@ -14,7 +14,7 @@ from .models import Set @login_required -def month(request, year, month): +def month_lifts(request, year, month): year, month = int(year), int(month) sets_by_day = defaultdict(set) @@ -50,6 +50,20 @@ def month(request, year, month): 'prev_date': prev_date, 'next_date': next_date }) +@login_required +def day_lifts(request, year, month, day): + year, month, day = int(year), int(month), int(day) + + sets = list(Set.objects.filter(user=request.user, date__year=year, date__month=month, + date__day=day)) + date = datetime.date(year, month, day) + prev_date = date - datetime.timedelta(days=1) + next_date = date + datetime.timedelta(days=1) + + return render(request, 'lifting/day.html', {'date': date, 'sets': sets, + 'prev_date': prev_date, 'next_date': next_date + }) + class FitnotesUploadForm(forms.Form): file = forms.FileField() diff --git a/templates/lifting/day.html b/templates/lifting/day.html new file mode 100644 index 0000000..6e45cf2 --- /dev/null +++ b/templates/lifting/day.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% block content %} + +
+
+ ← Previous +

{{date|date:"F d Y"}}

+ Next → +
+
+ +{% endblock %} diff --git a/templates/lifting/month.html b/templates/lifting/month.html index 1b8417e..50ba001 100644 --- a/templates/lifting/month.html +++ b/templates/lifting/month.html @@ -29,7 +29,9 @@ {% for day in week %} {% if day %} -
{{day.number}}
+
    {% for set in day.sets %}