Mark threads as read once they are fetched; change viewed to read
This commit is contained in:
@@ -84,6 +84,7 @@ def inline_discussion(request, course_id, discussion_id):
|
||||
# TODO (vshnayder): since none of this code seems to be aware of the fact that
|
||||
# sometimes things go wrong, I suspect that the js client is also not
|
||||
# checking for errors on request. Check and fix as needed.
|
||||
log.error("Error loading inline discussion threads.")
|
||||
raise Http404
|
||||
|
||||
def infogetter(thread):
|
||||
@@ -117,6 +118,7 @@ def forum_form_discussion(request, course_id):
|
||||
unsafethreads, query_params = get_threads(request, course_id) # This might process a search query
|
||||
threads = [utils.safe_content(thread) for thread in unsafethreads]
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
log.error("Error loading forum discussion threads: %s" % str(err))
|
||||
raise Http404
|
||||
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
@@ -167,21 +169,16 @@ def forum_form_discussion(request, course_id):
|
||||
@login_required
|
||||
def single_thread(request, course_id, discussion_id, thread_id):
|
||||
|
||||
if request.is_ajax():
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
cc_user = cc.User.from_django_user(request.user)
|
||||
user_info = cc_user.to_dict()
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
cc_user = cc.User.from_django_user(request.user)
|
||||
user_info = cc_user.to_dict()
|
||||
|
||||
try:
|
||||
last_read_time = datetime.datetime.utcnow().replace(tzinfo=utc).strftime('%Y-%m-%dT%H:%M:%S%z')
|
||||
cc_user.update_read_states(course_id, thread_id, last_read_time)
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
# TODO log error
|
||||
pass
|
||||
if request.is_ajax():
|
||||
|
||||
try:
|
||||
thread = cc.Thread.find(thread_id).retrieve(recursive=True, user_id=request.user.id)
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
log.error("Error loading single thread.")
|
||||
raise Http404
|
||||
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
@@ -200,24 +197,14 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
})
|
||||
|
||||
else:
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
category_map = utils.get_discussion_category_map(course)
|
||||
|
||||
cc_user = cc.User.from_django_user(request.user)
|
||||
user_info = cc_user.to_dict()
|
||||
|
||||
try:
|
||||
last_read_time = datetime.datetime.utcnow().replace(tzinfo=utc).strftime('%Y-%m-%dT%H:%M:%S%z')
|
||||
cc_user.update_read_states(course_id, thread_id, last_read_time)
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
# TODO log error
|
||||
pass
|
||||
|
||||
try:
|
||||
threads, query_params = get_threads(request, course_id)
|
||||
thread = cc.Thread.find(thread_id).retrieve(recursive=True, user_id=request.user.id)
|
||||
threads.append(thread.to_dict())
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
log.error("Error loading single thread.")
|
||||
raise Http404
|
||||
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
|
||||
@@ -337,7 +337,7 @@ def safe_content(content):
|
||||
'updated_at', 'depth', 'type', 'commentable_id', 'comments_count',
|
||||
'at_position_list', 'children', 'highlighted_title', 'highlighted_body',
|
||||
'courseware_title', 'courseware_url', 'tags', 'unread_comments_count',
|
||||
'viewed',
|
||||
'read',
|
||||
]
|
||||
|
||||
if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False):
|
||||
|
||||
@@ -72,8 +72,8 @@ class Model(object):
|
||||
for k, v in kwargs.items():
|
||||
if k in self.accessible_fields:
|
||||
self.__setattr__(k, v)
|
||||
#else:
|
||||
# raise AttributeError("Field {0} does not exist".format(k))
|
||||
else:
|
||||
raise AttributeError("Field {0} does not exist".format(k))
|
||||
|
||||
def updatable_attributes(self):
|
||||
return extract(self.attributes, self.updatable_fields)
|
||||
|
||||
@@ -10,7 +10,7 @@ class Thread(models.Model):
|
||||
'closed', 'tags', 'votes', 'commentable_id', 'username', 'user_id',
|
||||
'created_at', 'updated_at', 'comments_count', 'unread_comments_count',
|
||||
'at_position_list', 'children', 'type', 'highlighted_title',
|
||||
'highlighted_body', 'endorsed', 'unread'
|
||||
'highlighted_body', 'endorsed', 'read'
|
||||
]
|
||||
|
||||
updatable_fields = [
|
||||
@@ -60,7 +60,10 @@ class Thread(models.Model):
|
||||
else:
|
||||
return super(Thread, cls).url(action, params)
|
||||
|
||||
# TODO: This is currently overriding Model._retrieve only to add parameters
|
||||
# for the request. Model._retrieve should be modified to handle this such
|
||||
# that subclasses don't need to override for this.
|
||||
def _retrieve(self, *args, **kwargs):
|
||||
url = self.url(action='get', params=self.attributes)
|
||||
response = perform_request('get', url, {'recursive': kwargs.get('recursive'), 'user_id': kwargs.get('user_id')})
|
||||
response = perform_request('get', url, {'recursive': kwargs.get('recursive'), 'user_id': kwargs.get('user_id'), 'mark_as_read': kwargs.get('mark_as_read', True)})
|
||||
self.update_attributes(**response)
|
||||
|
||||
@@ -74,13 +74,6 @@ class User(models.Model):
|
||||
response = perform_request('get', url, retrieve_params)
|
||||
self.update_attributes(**response)
|
||||
|
||||
def update_read_states(self, course_id, thread_id, last_read_time):
|
||||
url = _url_for_read_states(self.id)
|
||||
response = perform_request('put', url, { "course_id": course_id,
|
||||
"thread_id": thread_id,
|
||||
"last_read_time": last_read_time,
|
||||
})
|
||||
|
||||
def _url_for_vote_comment(comment_id):
|
||||
return "{prefix}/comments/{comment_id}/votes".format(prefix=settings.PREFIX, comment_id=comment_id)
|
||||
|
||||
@@ -90,8 +83,5 @@ def _url_for_vote_thread(thread_id):
|
||||
def _url_for_subscription(user_id):
|
||||
return "{prefix}/users/{user_id}/subscriptions".format(prefix=settings.PREFIX, user_id=user_id)
|
||||
|
||||
def _url_for_read_states(user_id):
|
||||
return "{prefix}/users/{user_id}/read_states".format(prefix=settings.PREFIX, user_id=user_id)
|
||||
|
||||
def _url_for_user_active_threads(user_id):
|
||||
return "{prefix}/users/{user_id}/active_threads".format(prefix=settings.PREFIX, user_id=user_id)
|
||||
|
||||
Reference in New Issue
Block a user