Commit ef3cbc51 by Clinton Blackburn

Sorting data chronologically

This will better serve the needs of the dashboard.
parent 6fc3d10a
...@@ -42,7 +42,7 @@ class BaseCourseEnrollment(models.Model): ...@@ -42,7 +42,7 @@ class BaseCourseEnrollment(models.Model):
class CourseEnrollmentDaily(BaseCourseEnrollment): class CourseEnrollmentDaily(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta): class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_daily' db_table = 'course_enrollment_daily'
ordering = ('-date', 'course') ordering = ('date', 'course')
unique_together = [('course', 'date',)] unique_together = [('course', 'date',)]
...@@ -51,7 +51,7 @@ class CourseEnrollmentByBirthYear(BaseCourseEnrollment): ...@@ -51,7 +51,7 @@ class CourseEnrollmentByBirthYear(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta): class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_birth_year' db_table = 'course_enrollment_birth_year'
ordering = ('-date', 'birth_year', 'course') ordering = ('date', 'course', 'birth_year')
unique_together = [('course', 'date', 'birth_year')] unique_together = [('course', 'date', 'birth_year')]
...@@ -71,7 +71,7 @@ class CourseEnrollmentByEducation(BaseCourseEnrollment): ...@@ -71,7 +71,7 @@ class CourseEnrollmentByEducation(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta): class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_education_level' db_table = 'course_enrollment_education_level'
ordering = ('-date', 'education_level', 'course') ordering = ('date', 'course', 'education_level')
unique_together = [('course', 'date', 'education_level')] unique_together = [('course', 'date', 'education_level')]
...@@ -80,7 +80,7 @@ class CourseEnrollmentByGender(BaseCourseEnrollment): ...@@ -80,7 +80,7 @@ class CourseEnrollmentByGender(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta): class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_gender' db_table = 'course_enrollment_gender'
ordering = ('-date', 'gender', 'course') ordering = ('date', 'course', 'gender')
unique_together = [('course', 'date', 'gender')] unique_together = [('course', 'date', 'gender')]
...@@ -120,5 +120,5 @@ class CourseEnrollmentByCountry(BaseCourseEnrollment): ...@@ -120,5 +120,5 @@ class CourseEnrollmentByCountry(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta): class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_location' db_table = 'course_enrollment_location'
ordering = ('-date', 'country', 'course') ordering = ('date', 'course', 'country')
unique_together = [('course', 'date', 'country')] unique_together = [('course', 'date', 'country')]
...@@ -84,6 +84,7 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication): ...@@ -84,6 +84,7 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
class CourseEnrollmentViewTestCase(object): class CourseEnrollmentViewTestCase(object):
model = None model = None
path = None path = None
order_by = []
def _get_non_existent_course_id(self): def _get_non_existent_course_id(self):
course_id = random.randint(100, 9999) course_id = random.randint(100, 9999)
...@@ -108,8 +109,8 @@ class CourseEnrollmentViewTestCase(object): ...@@ -108,8 +109,8 @@ class CourseEnrollmentViewTestCase(object):
response = self.authenticated_get('/api/v0/courses/%s%s' % (self.course.course_id, self.path,)) response = self.authenticated_get('/api/v0/courses/%s%s' % (self.course.course_id, self.path,))
self.assertEquals(response.status_code, 200) self.assertEquals(response.status_code, 200)
# Validate the actual data # Validate the data is correct and sorted chronologically
expected = self.get_expected_response(*self.model.objects.filter(date=self.date)) expected = self.get_expected_response(*self.model.objects.filter(date=self.date).order_by('date', *self.order_by)) # pylint: disable=line-too-long
self.assertEquals(response.data, expected) self.assertEquals(response.data, expected)
def test_get_csv(self): def test_get_csv(self):
...@@ -167,6 +168,7 @@ class CourseEnrollmentViewTestCase(object): ...@@ -167,6 +168,7 @@ class CourseEnrollmentViewTestCase(object):
class CourseEnrollmentByBirthYearViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase): class CourseEnrollmentByBirthYearViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase):
path = '/enrollment/birth_year' path = '/enrollment/birth_year'
model = models.CourseEnrollmentByBirthYear model = models.CourseEnrollmentByBirthYear
order_by = ['birth_year']
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
...@@ -197,6 +199,7 @@ class CourseEnrollmentByBirthYearViewTests(TestCaseWithAuthentication, CourseEnr ...@@ -197,6 +199,7 @@ class CourseEnrollmentByBirthYearViewTests(TestCaseWithAuthentication, CourseEnr
class CourseEnrollmentByEducationViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase): class CourseEnrollmentByEducationViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase):
path = '/enrollment/education/' path = '/enrollment/education/'
model = models.CourseEnrollmentByEducation model = models.CourseEnrollmentByEducation
order_by = ['education_level']
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
...@@ -219,6 +222,7 @@ class CourseEnrollmentByEducationViewTests(TestCaseWithAuthentication, CourseEnr ...@@ -219,6 +222,7 @@ class CourseEnrollmentByEducationViewTests(TestCaseWithAuthentication, CourseEnr
class CourseEnrollmentByGenderViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase): class CourseEnrollmentByGenderViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase):
path = '/enrollment/gender/' path = '/enrollment/gender/'
model = models.CourseEnrollmentByGender model = models.CourseEnrollmentByGender
order_by = ['gender']
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
......
...@@ -91,6 +91,8 @@ class CourseEnrollmentByBirthYearView(BaseCourseEnrollmentView): ...@@ -91,6 +91,8 @@ class CourseEnrollmentByBirthYearView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone. If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31) Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive) start_date -- Date after which all data should be returned (inclusive)
...@@ -109,6 +111,8 @@ class CourseEnrollmentByEducationView(BaseCourseEnrollmentView): ...@@ -109,6 +111,8 @@ class CourseEnrollmentByEducationView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone. If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31) Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive) start_date -- Date after which all data should be returned (inclusive)
...@@ -131,6 +135,8 @@ class CourseEnrollmentByGenderView(BaseCourseEnrollmentView): ...@@ -131,6 +135,8 @@ class CourseEnrollmentByGenderView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone. If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31) Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive) start_date -- Date after which all data should be returned (inclusive)
...@@ -146,6 +152,8 @@ class CourseEnrollmentView(BaseCourseEnrollmentView): ...@@ -146,6 +152,8 @@ class CourseEnrollmentView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone. If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31) Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive) start_date -- Date after which all data should be returned (inclusive)
...@@ -168,6 +176,8 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView): ...@@ -168,6 +176,8 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone. If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31) Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive) start_date -- Date after which all data should be returned (inclusive)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment