Commit b13c5acd by Ibrahim Awwal

Save the user's selected sort order on the comments service.

Requires cs_comments_service to have the field default_sort_key on users.
parent 7655e9ee
......@@ -102,7 +102,7 @@ def get_threads(request, course_id, discussion_id=None):
default_query_params = {
'page': 1,
'per_page': THREADS_PER_PAGE,
'sort_key': 'activity',
'sort_key': 'date',
'sort_order': 'desc',
'text': '',
'tags': '',
......@@ -110,6 +110,17 @@ def get_threads(request, course_id, discussion_id=None):
'course_id': course_id,
}
if not request.GET.get('sort_key'):
# If the user did not select a sort key, use their last used sort key
user = cc.User.from_django_user(request.user)
user.retrieve()
default_query_params['sort_key'] = user.default_sort_key
else:
# If the user clicked a sort key, update their default sort key
user = cc.User.from_django_user(request.user)
user.default_sort_key = request.GET.get('sort_key')
user.save()
query_params = merge_dict(default_query_params,
strip_none(extract(request.GET, ['page', 'sort_key', 'sort_order', 'text', 'tags'])))
......
......@@ -8,10 +8,10 @@ class User(models.Model):
accessible_fields = ['username', 'email', 'follower_ids', 'upvoted_ids', 'downvoted_ids',
'id', 'external_id', 'subscribed_user_ids', 'children', 'course_id',
'subscribed_thread_ids', 'subscribed_commentable_ids',
'threads_count', 'comments_count',
'threads_count', 'comments_count', 'default_sort_key'
]
updatable_fields = ['username', 'external_id', 'email']
updatable_fields = ['username', 'external_id', 'email', 'default_sort_key']
initializable_fields = updatable_fields
base_url = "{prefix}/users".format(prefix=settings.PREFIX)
......
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