Exemplo n.º 1
0
    def get_discussion_data(self, request, course_key):
        """
        Collects and formats the discussion data from a particular user and course.

        Args:
            request (HttpRequest)
            course_key (CourseKey)
        """
        try:
            context = create_user_profile_context(request, course_key,
                                                  request.user.id)
        except Exception as e:
            # TODO: LEARNER-3854: Clean-up error handling if continuing support.
            return {
                'content_authored': 0,
                'thread_votes': 0,
            }

        threads = context['threads']
        profiled_user = context['profiled_user']

        # TODO: LEARNER-3854: If implementing Learner Analytics, rename to content_authored_count.
        content_authored = profiled_user['threads_count'] + profiled_user[
            'comments_count']
        thread_votes = 0
        for thread in threads:
            if thread['user_id'] == profiled_user['external_id']:
                thread_votes += thread['votes']['count']
        discussion_data = {
            'content_authored': content_authored,
            'thread_votes': thread_votes,
        }
        return discussion_data
Exemplo n.º 2
0
    def get_discussion_data(self, request, course_key):
        """
        Collects and formats the discussion data from a particular user and course.

        Args:
            request (HttpRequest)
            course_key (CourseKey)
        """
        try:
            context = create_user_profile_context(request, course_key, request.user.id)
        except Exception as e:
            # TODO: LEARNER-3854: Clean-up error handling if continuing support.
            return {
                'content_authored': 0,
                'thread_votes': 0,
            }

        threads = context['threads']
        profiled_user = context['profiled_user']

        # TODO: LEARNER-3854: If implementing Learner Analytics, rename to content_authored_count.
        content_authored = profiled_user['threads_count'] + profiled_user['comments_count']
        thread_votes = 0
        for thread in threads:
            if thread['user_id'] == profiled_user['external_id']:
                thread_votes += thread['votes']['count']
        discussion_data = {
            'content_authored': content_authored,
            'thread_votes': thread_votes,
        }
        return discussion_data