From b5847bc9778238aba11180474ae7b351b48fbacf Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Wed, 1 Mar 2017 17:16:40 +0100
Subject: [PATCH] list of appointments is sorted by date, calendar is limited
 to appointments from month before to undefined future

---
 smash/web/templates/appointments/index.html | 3 ++-
 smash/web/views.py                          | 8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/smash/web/templates/appointments/index.html b/smash/web/templates/appointments/index.html
index 1c169f17..c440bab2 100644
--- a/smash/web/templates/appointments/index.html
+++ b/smash/web/templates/appointments/index.html
@@ -88,7 +88,7 @@
                 {{ type.code }},
               {% endfor %}
             </td>
-        			<td>{{ approach.datetime_when | date:"d-M-Y H:i" }}</td>
+        			<td>{{ approach.datetime_when | date:"Y-m-d H:i" }}</td>
         			<td>
         				<a href="{% url 'web.views.appointment_edit' approach.id %}" type="button" class="btn btn-block btn-default">Details</a>
         			</td>
@@ -127,6 +127,7 @@
 			  "lengthChange": false,
 			  "searching": true,
 			  "ordering": true,
+        "order": [[ 2, "asc"]],
 			  "info": true,
 			  "autoWidth": false
 			});
diff --git a/smash/web/views.py b/smash/web/views.py
index f79723e7..4dbf3482 100644
--- a/smash/web/views.py
+++ b/smash/web/views.py
@@ -324,8 +324,9 @@ def appointments(request):
 
 	today = datetime.datetime.now()
 	today_midnight = datetime.datetime(today.year,today.month,today.day)
+	month_ago = today +datetime.timedelta(days=-31)
 	approaching_list = Appointment.objects.filter(datetime_when__gt = today_midnight, is_finished = False).order_by('datetime_when')
-	full_list = Appointment.objects.all()
+	full_list = Appointment.objects.filter(datetime_when__gt = month_ago, is_finished = False).order_by('datetime_when')
 
 
 	for plan in planning_list:
@@ -346,7 +347,10 @@ def appointment_details(request, id):
 
 
 def appointment_add(request, id):
-	full_list = Appointment.objects.all()
+	today = datetime.datetime.now()
+	today_midnight = datetime.datetime(today.year,today.month,today.day)
+	month_ago = today +datetime.timedelta(days=-31)
+	full_list = Appointment.objects.filter(datetime_when__gt = month_ago, is_finished = False).order_by('datetime_when')
 	if request.method == 'POST':
 		form = AppointmentAddForm(request.POST, request.FILES)
 		form.fields['visit'].widget = forms.HiddenInput()
-- 
GitLab