Thread sort key and direction for discussion api

Discussion API for thread sorting now takes the sort_by
parameter for the sort key such as by comment_count or
vote_count. Also takes the sort_direction parameter for
sorting the thread results.
This commit is contained in:
christopher lee
2015-06-19 12:21:05 -04:00
parent dccc36a452
commit ed3bb27df8
6 changed files with 190 additions and 5 deletions

View File

@@ -54,8 +54,24 @@ class ThreadListGetForm(_PaginationForm):
following = NullBooleanField(required=False)
view = ChoiceField(
choices=[(choice, choice) for choice in ["unread", "unanswered"]],
required=False,
)
order_by = ChoiceField(
choices=[(choice, choice) for choice in ["last_activity_at", "comment_count", "vote_count"]],
required=False
)
order_direction = ChoiceField(
choices=[(choice, choice) for choice in ["asc", "desc"]],
required=False
)
def clean_order_by(self):
"""Return a default choice"""
return self.cleaned_data.get("order_by") or "last_activity_at"
def clean_order_direction(self):
"""Return a default choice"""
return self.cleaned_data.get("order_direction") or "desc"
def clean_course_id(self):
"""Validate course_id"""