Commit 70ba1ff9 by David Ormsbee

Merge pull request #595 from MITx/feature/ibrahim/discussion_sort_preferences

Feature/ibrahim/discussion sort preferences
parents 80353b0a 6f8926e7
...@@ -112,7 +112,7 @@ def get_threads(request, course_id, discussion_id=None): ...@@ -112,7 +112,7 @@ def get_threads(request, course_id, discussion_id=None):
default_query_params = { default_query_params = {
'page': 1, 'page': 1,
'per_page': THREADS_PER_PAGE, 'per_page': THREADS_PER_PAGE,
'sort_key': 'activity', 'sort_key': 'date',
'sort_order': 'desc', 'sort_order': 'desc',
'text': '', 'text': '',
'tags': '', 'tags': '',
...@@ -120,6 +120,18 @@ def get_threads(request, course_id, discussion_id=None): ...@@ -120,6 +120,18 @@ def get_threads(request, course_id, discussion_id=None):
'course_id': course_id, '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()
# TODO: After the comment service is updated this can just be user.default_sort_key because the service returns the default value
default_query_params['sort_key'] = user.get('default_sort_key') or default_query_params['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, query_params = merge_dict(default_query_params,
strip_none(extract(request.GET, ['page', 'sort_key', 'sort_order', 'text', 'tags']))) strip_none(extract(request.GET, ['page', 'sort_key', 'sort_order', 'text', 'tags'])))
......
...@@ -432,7 +432,7 @@ main_vendor_js = [ ...@@ -432,7 +432,7 @@ main_vendor_js = [
'js/vendor/jquery.qtip.min.js', 'js/vendor/jquery.qtip.min.js',
] ]
discussion_js = glob2.glob(PROJECT_ROOT / 'static/coffee/src/discussion/*.coffee') discussion_js = sorted(glob2.glob(PROJECT_ROOT / 'static/coffee/src/discussion/*.coffee'))
# Load javascript from all of the available xmodules, and # Load javascript from all of the available xmodules, and
# prep it for use in pipeline js # prep it for use in pipeline js
...@@ -500,10 +500,10 @@ PIPELINE_JS = { ...@@ -500,10 +500,10 @@ PIPELINE_JS = {
'source_filenames': [ 'source_filenames': [
pth.replace(COMMON_ROOT / 'static/', '') pth.replace(COMMON_ROOT / 'static/', '')
for pth for pth
in glob2.glob(COMMON_ROOT / 'static/coffee/src/**/*.coffee') in sorted(glob2.glob(COMMON_ROOT / 'static/coffee/src/**/*.coffee'))
] + [ ] + [
pth.replace(PROJECT_ROOT / 'static/', '') pth.replace(PROJECT_ROOT / 'static/', '')
for pth in glob2.glob(PROJECT_ROOT / 'static/coffee/src/**/*.coffee')\ for pth in sorted(glob2.glob(PROJECT_ROOT / 'static/coffee/src/**/*.coffee'))\
if pth not in courseware_only_js and pth not in discussion_js if pth not in courseware_only_js and pth not in discussion_js
] + [ ] + [
'js/form.ext.js', 'js/form.ext.js',
......
...@@ -8,10 +8,10 @@ class User(models.Model): ...@@ -8,10 +8,10 @@ class User(models.Model):
accessible_fields = ['username', 'email', 'follower_ids', 'upvoted_ids', 'downvoted_ids', accessible_fields = ['username', 'email', 'follower_ids', 'upvoted_ids', 'downvoted_ids',
'id', 'external_id', 'subscribed_user_ids', 'children', 'course_id', 'id', 'external_id', 'subscribed_user_ids', 'children', 'course_id',
'subscribed_thread_ids', 'subscribed_commentable_ids', '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 initializable_fields = updatable_fields
base_url = "{prefix}/users".format(prefix=settings.PREFIX) base_url = "{prefix}/users".format(prefix=settings.PREFIX)
......
...@@ -506,7 +506,8 @@ $tag-text-color: #5b614f; ...@@ -506,7 +506,8 @@ $tag-text-color: #5b614f;
font-size: inherit; font-size: inherit;
font-weight: bold; font-weight: bold;
margin-left: 1%; margin-left: 1%;
padding-top: 9px; padding-top: 4px;
padding-bottom: 2px;
text-decoration: none; text-decoration: none;
} }
......
...@@ -31,9 +31,9 @@ ...@@ -31,9 +31,9 @@
<div class="discussion-sort local"> <div class="discussion-sort local">
<span class="discussion-label">Sort by:</span> <span class="discussion-label">Sort by:</span>
${link_to_sort('activity', 'top')}
${link_to_sort('date', 'date')} ${link_to_sort('date', 'date')}
${link_to_sort('activity', 'top')}
${link_to_sort('votes', 'votes')} ${link_to_sort('votes', 'votes')}
......
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