From ed6317f37c9b0e09006cf51680e0ca087b4ea6a4 Mon Sep 17 00:00:00 2001 From: Arjun Singh Date: Thu, 23 Aug 2012 10:03:36 -0700 Subject: [PATCH] getting rid of terrible hack in favor of re enabling the dispatcher to sync w/ the comment service --- common/djangoapps/student/models.py | 2 +- lms/djangoapps/django_comment_client/base/views.py | 2 +- lms/djangoapps/django_comment_client/forum/views.py | 6 +++--- lms/lib/comment_client/user.py | 10 ---------- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 55204f19f6..9cde878d21 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -273,7 +273,7 @@ def add_user_to_default_group(user, group): utg.users.add(User.objects.get(username=user)) utg.save() -# @receiver(post_save, sender=User) +@receiver(post_save, sender=User) def update_user_information(sender, instance, created, **kwargs): try: cc_user = cc.User.from_django_user(instance) diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 280e6d2780..dd9da857c6 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -51,7 +51,7 @@ def ajax_content_response(request, course_id, content, template_name): 'content': content, } html = render_to_string(template_name, context) - user_info = cc.User.from_django_user(request.user).safe_attributes() + user_info = cc.User.from_django_user(request.user).to_dict() annotated_content_info = utils.get_annotated_content_info(course_id, content, request.user, user_info) return JsonResponse({ 'html': html, diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 38f8fa985d..eda574cb6e 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -64,7 +64,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs): 'user': (lambda: reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])), }[discussion_type]() - user_info = cc.User.from_django_user(request.user).safe_attributes() + user_info = cc.User.from_django_user(request.user).to_dict() def infogetter(thread): return utils.get_annotated_content_infos(course_id, thread, request.user, user_info) @@ -176,7 +176,7 @@ def render_single_thread(request, discussion_id, course_id, thread_id): thread = cc.Thread.find(thread_id).retrieve(recursive=True).to_dict() - user_info = cc.User.from_django_user(request.user).safe_attributes() + user_info = cc.User.from_django_user(request.user).to_dict() annotated_content_info = utils.get_annotated_content_infos(course_id, thread=thread, user=request.user, user_info=user_info) @@ -194,7 +194,7 @@ def single_thread(request, course_id, discussion_id, thread_id): if request.is_ajax(): - user_info = cc.User.from_django_user(request.user).safe_attributes() + user_info = cc.User.from_django_user(request.user).to_dict() thread = cc.Thread.find(thread_id).retrieve(recursive=True) annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info) context = {'thread': thread.to_dict(), 'course_id': course_id} diff --git a/lms/lib/comment_client/user.py b/lms/lib/comment_client/user.py index 1f61e9d625..ae4abf91b7 100644 --- a/lms/lib/comment_client/user.py +++ b/lms/lib/comment_client/user.py @@ -33,16 +33,6 @@ class User(models.Model): params = {'source_type': source.type, 'source_id': source.id} response = perform_request('delete', _url_for_subscription(self.id), params) - # TODO this is a hack to compensate for the fact that synchronization isn't - # happening properly. - def safe_attributes(self): - try: - return self.to_dict() - except: - self.save() - self._retrieve() - return self.to_dict() - def vote(self, voteable, value): if voteable.type == 'thread': url = _url_for_vote_thread(voteable.id)