list all exercises by month

This commit is contained in:
James Turk 2015-04-03 17:09:38 -04:00
parent 32fac6e442
commit 6eedca2b7e
3 changed files with 26 additions and 7 deletions

View File

@ -17,9 +17,9 @@ from .models import Set
def month(request, year, month): def month(request, year, month):
year, month = int(year), int(month) year, month = int(year), int(month)
sets_by_day = defaultdict(list) sets_by_day = defaultdict(set)
for workset in Set.objects.filter(user=request.user, date__year=year, date__month=month): for workset in Set.objects.filter(user=request.user, date__year=year, date__month=month):
sets_by_day[workset.date.day].append(workset) sets_by_day[workset.date.day].add(workset.exercise)
date = datetime.date(year, month, 1) date = datetime.date(year, month, 1)
first_day, max_days = calendar.monthrange(year, month) first_day, max_days = calendar.monthrange(year, month)
# make first_day use 0 for sunday # make first_day use 0 for sunday
@ -31,7 +31,7 @@ def month(request, year, month):
for day in range(max_days+1): for day in range(max_days+1):
days.append({'number': day, 'sets': sets_by_day[day]}) 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] 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, return render(request, 'month.html', { 'date': date,
'days': days_by_week 'days': days_by_week

13
static/css/bia.css Normal file
View File

@ -0,0 +1,13 @@
.calendar-month {
table-layout: fixed;
}
.calendar-month > tbody > tr > td {
border: 1px solid #666;
padding: 0 0 2em 0;
}
.day-number {
width: 100%;
text-align: right;
padding: 0 1em 0 0;
background-color: #ddd;
}

View File

@ -9,7 +9,7 @@
<section class="row"> <section class="row">
<section class="col-sm-12"> <section class="col-sm-12">
<table class="calendar-month"> <table class="table calendar-month">
<thead> <thead>
<tr> <tr>
<th>Sunday</th> <th>Sunday</th>
@ -25,10 +25,16 @@
{% for week in days %} {% for week in days %}
<tr> <tr>
{% for day in week %} {% for day in week %}
<td> <td class="calendar-day">
{% if day %} {% if day %}
<span class="calendar-day">{{day.number}}</span> <div class="day-number">{{day.number}}</div>
{{day.sets|length}} <ul>
{% for set in day.sets %}
<li>
{{set}}
</li>
{% endfor %}
</ul>
{% endif %} {% endif %}
</td> </td>
{% endfor %} {% endfor %}