initial month view
This commit is contained in:
parent
0a8658a441
commit
32fac6e442
@ -1,11 +1,41 @@
|
||||
import datetime
|
||||
import os
|
||||
import tempfile
|
||||
import calendar
|
||||
from collections import defaultdict
|
||||
|
||||
from django.shortcuts import render
|
||||
from django import forms
|
||||
from django.contrib.auth.decorators import login_required
|
||||
import os
|
||||
from django.views.generic import dates
|
||||
|
||||
from . import importers
|
||||
from .models import Set
|
||||
|
||||
|
||||
@login_required
|
||||
def month(request, year, month):
|
||||
year, month = int(year), int(month)
|
||||
|
||||
sets_by_day = defaultdict(list)
|
||||
for workset in Set.objects.filter(user=request.user, date__year=year, date__month=month):
|
||||
sets_by_day[workset.date.day].append(workset)
|
||||
date = datetime.date(year, month, 1)
|
||||
first_day, max_days = calendar.monthrange(year, month)
|
||||
# make first_day use 0 for sunday
|
||||
first_day = (first_day + 1) % 7
|
||||
|
||||
# start calendar with a few blank days
|
||||
days = [None]*first_day
|
||||
|
||||
for day in range(max_days+1):
|
||||
days.append({'number': day, 'sets': sets_by_day[day]})
|
||||
|
||||
days_by_week = [days[0:7], days[7:14], days[14:21], days[21:28], days[28:35]
|
||||
|
||||
return render(request, 'month.html', { 'date': date,
|
||||
'days': days_by_week
|
||||
})
|
||||
|
||||
|
||||
class FitnotesUploadForm(forms.Form):
|
||||
|
@ -11,6 +11,7 @@
|
||||
<link rel="stylesheet" href="{% static 'css/icon.css' %}" type="text/css" />
|
||||
<link rel="stylesheet" href="{% static 'css/font.css' %}" type="text/css" />
|
||||
<link rel="stylesheet" href="{% static 'css/app.css' %}" type="text/css" />
|
||||
<link rel="stylesheet" href="{% static 'css/bia.css' %}" type="text/css" />
|
||||
</head>
|
||||
<body class="" >
|
||||
<section class="vbox">
|
||||
|
42
templates/month.html
Normal file
42
templates/month.html
Normal file
@ -0,0 +1,42 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
||||
<section class="row">
|
||||
<section class="col-sm-6">
|
||||
<h3>{{date|date:"F Y"}}</h3>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section class="row">
|
||||
<section class="col-sm-12">
|
||||
<table class="calendar-month">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sunday</th>
|
||||
<th>Monday</th>
|
||||
<th>Tuesday</th>
|
||||
<th>Wednesday</th>
|
||||
<th>Thursday</th>
|
||||
<th>Friday</th>
|
||||
<th>Saturday</th>
|
||||
<tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for week in days %}
|
||||
<tr>
|
||||
{% for day in week %}
|
||||
<td>
|
||||
{% if day %}
|
||||
<span class="calendar-day">{{day.number}}</span>
|
||||
{{day.sets|length}}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
{% endblock %}
|
@ -7,4 +7,6 @@ urlpatterns = [
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
|
||||
url(r'^fitnotes-upload/$', 'lifting.views.fitnotes_upload'),
|
||||
url(r'^lifting/(?P<year>\d{4})/(?P<month>\d{1,2})/$', 'lifting.views.month'),
|
||||
|
||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
Loading…
Reference in New Issue
Block a user