|
|
@@ -1,7 +1,7 @@
|
|
1
|
1
|
from django.shortcuts import render
|
|
2
|
2
|
from census.models import Course,Count,Lesson
|
|
3
|
3
|
from django import forms
|
|
4
|
|
-from django.db.models.aggregates import Max
|
|
|
4
|
+from django.db.models.aggregates import Min
|
|
5
|
5
|
from datetime import *
|
|
6
|
6
|
from django.http import HttpResponseRedirect
|
|
7
|
7
|
|
|
|
@@ -56,7 +56,7 @@ class addCountForm(forms.ModelForm):
|
|
56
|
56
|
|
|
57
|
57
|
def home(request):
|
|
58
|
58
|
#Retrieving the course list and the statistics
|
|
59
|
|
- courses = Course.objects.annotate(latest_lesson_date=Max('lesson__date')).filter(latest_lesson_date__lte=datetime.today()).order_by('-latest_lesson_date')
|
|
|
59
|
+ courses = Course.objects.annotate(first_lesson_date=Min('lesson__date')).filter(first_lesson_date__lte=datetime.today()).order_by('-first_lesson_date')
|
|
60
|
60
|
#courses = Course.objects.all().order_by('-promotion')
|
|
61
|
61
|
for course in courses:
|
|
62
|
62
|
course = getCourseStatistics(course)
|
|
|
@@ -83,7 +83,7 @@ def addcount(request):
|
|
83
|
83
|
if request.method == 'POST':
|
|
84
|
84
|
# create a form instance and populate it with data from the request:
|
|
85
|
85
|
form = addCountForm(request.POST)
|
|
86
|
|
- form.fields["lesson"].queryset = Lesson.objects.filter(date__lte=datetime.now(),date__gte=datetime.now()-datetime.timedelta(30)).order_by('-date')
|
|
|
86
|
+ form.fields["lesson"].queryset = Lesson.objects.filter(date__lte=datetime.now(),date__gte=datetime.now()-timedelta(30)).order_by('-date')
|
|
87
|
87
|
# check whether it's valid:
|
|
88
|
88
|
if form.is_valid():
|
|
89
|
89
|
count = form.save()
|