calendar view more functional now

This commit is contained in:
James Turk 2015-04-06 11:43:36 -04:00
parent fc52f7245f
commit da59374b7e
5 changed files with 55 additions and 8 deletions

9
lifting/urls.py Normal file
View File

@ -0,0 +1,9 @@
from django.conf.urls import url
from lifting import views
urlpatterns = [
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$', views.month, name='lifting-month'),
url(r'^fitnotes/$', views.fitnotes_upload),
]

View File

@ -33,8 +33,23 @@ def month(request, year, month):
days_by_week = [days[0:7], days[7:14], days[14:21], days[21:28], days[28:35], days[35:42]]
return render(request, 'month.html', { 'date': date,
'days': days_by_week
# prev and next month
if date.month == 1:
prev_date = datetime.date(year-1, 12, 1)
next_date = datetime.date(year, 2, 1)
elif date.month == 12:
prev_date = datetime.date(year, 11, 1)
next_date = datetime.date(year+1, 1, 1)
else:
prev_date = datetime.date(year, month-1, 1)
next_date = datetime.date(year, month+1, 1)
return render(request, 'month.html', {'date': date,
'days': days_by_week,
'prev_date': prev_date,
'next_date': next_date,
})

View File

@ -1,13 +1,33 @@
.header-row {
padding-bottom: 2em;
text-align: center;
}
.month-name {
display: inline;
padding: 0 2em;
}
.calendar-month {
table-layout: fixed;
}
.calendar-month > thead > tr > th {
text-align: center;
}
.calendar-month > tbody > tr > td {
border: 1px solid #666;
padding: 0 0 2em 0;
}
.calendar-day {
height: 8em;
}
.day-number {
width: 100%;
text-align: right;
padding: 0 1em 0 0;
background-color: #ddd;
}
.month-day-list {
padding-left: 1em;
}
.month-day-list li {
list-style: none;
}

View File

@ -1,9 +1,11 @@
{% extends "base.html" %}
{% block content %}
<section class="row">
<section class="col-sm-6">
<h3>{{date|date:"F Y"}}</h3>
<section class="row header-row">
<section class="col-sm-12">
<a href="{% url 'lifting-month' prev_date.year prev_date.month %}">&larr; Previous</a>
<h3 class="month-name">{{date|date:"F Y"}}</h3>
<a href="{% url 'lifting-month' next_date.year next_date.month %}">Next &rarr;</a>
</section>
</section>
@ -28,7 +30,7 @@
<td class="calendar-day">
{% if day %}
<div class="day-number">{{day.number}}</div>
<ul>
<ul class="month-day-list">
{% for set in day.sets %}
<li>
{{set}}

View File

@ -3,10 +3,11 @@ from django.conf.urls import include, url
from django.contrib import admin
from django.conf.urls.static import static
import lifting.urls
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'),
url(r'^lifting/', include(lifting.urls.urlpatterns)),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)