def user_profile(request, course_key, user_id):
    """
    Renders a response to display the user profile page (shown after clicking
    on a post author's username).
    """
    try:
        context = create_user_profile_context(request, course_key, user_id)
        if request.is_ajax():
            return utils.JsonResponse({
                'discussion_data':
                context['threads'],
                'page':
                context['page'],
                'num_pages':
                context['num_pages'],
                'annotated_content_info':
                context['annotated_content_info'],
            })
        else:
            tab_view = CourseTabView()

            # To avoid mathjax loading from 'mathjax_include.html'
            # as that file causes multiple loadings of Mathjax on
            # 'user_profile' page
            context['load_mathjax'] = False

            return tab_view.get(request,
                                str(course_key),
                                'discussion',
                                profile_page_context=context)
    except User.DoesNotExist:
        raise Http404  # lint-amnesty, pylint: disable=raise-missing-from
    except ValueError:
        return HttpResponseServerError("Invalid group_id")
Beispiel #2
0
def single_thread(request, course_key, discussion_id, thread_id):
    """
    Renders a response to display a single discussion thread.  This could either be a page refresh
    after navigating to a single thread, a direct link to a single thread, or an AJAX call from the
    discussions UI loading the responses/comments for a single thread.

    Depending on the HTTP headers, we'll adjust our response accordingly.
    """
    course = get_course_with_access(request.user,
                                    'load',
                                    course_key,
                                    check_if_enrolled=True)
    request.user.is_community_ta = utils.is_user_community_ta(
        request.user, course.id)

    if request.is_ajax():
        cc_user = cc.User.from_django_user(request.user)
        user_info = cc_user.to_dict()
        is_staff = has_permission(request.user, 'openclose_thread', course.id)

        try:
            _check_team_discussion_access(request, course, discussion_id)
        except TeamDiscussionHiddenFromUserException:
            return HttpResponseForbidden(TEAM_PERMISSION_MESSAGE)

        thread = _load_thread_for_viewing(
            request,
            course,
            discussion_id=discussion_id,
            thread_id=thread_id,
            raise_event=True,
        )

        with function_trace("get_annotated_content_infos"):
            annotated_content_info = utils.get_annotated_content_infos(
                course_key, thread, request.user, user_info=user_info)

        content = utils.prepare_content(thread.to_dict(), course_key, is_staff,
                                        request.user.is_community_ta)
        with function_trace("add_courseware_context"):
            add_courseware_context([content], course, request.user)

        return utils.JsonResponse({
            'content':
            content,
            'annotated_content_info':
            annotated_content_info,
        })
    else:
        course_id = str(course.id)
        tab_view = CourseTabView()
        return tab_view.get(request,
                            course_id,
                            'discussion',
                            discussion_id=discussion_id,
                            thread_id=thread_id)
Beispiel #3
0
def forum_form_discussion(request, course_key):
    """
    Renders the main Discussion page, potentially filtered by a search query
    """
    course = get_course_with_access(request.user,
                                    'load',
                                    course_key,
                                    check_if_enrolled=True)
    request.user.is_community_ta = utils.is_user_community_ta(
        request.user, course.id)
    if request.is_ajax():
        user = cc.User.from_django_user(request.user)
        user_info = user.to_dict()

        try:
            unsafethreads, query_params = get_threads(
                request, course,
                user_info)  # This might process a search query
            is_staff = has_permission(request.user, 'openclose_thread',
                                      course.id)
            threads = [
                utils.prepare_content(thread, course_key, is_staff,
                                      request.user.is_community_ta)
                for thread in unsafethreads
            ]
        except cc.utils.CommentClientMaintenanceError:
            return HttpResponseServerError(
                'Forum is in maintenance mode',
                status=status.HTTP_503_SERVICE_UNAVAILABLE)
        except ValueError:
            return HttpResponseServerError("Invalid group_id")

        with function_trace("get_metadata_for_threads"):
            annotated_content_info = utils.get_metadata_for_threads(
                course_key, threads, request.user, user_info)

        with function_trace("add_courseware_context"):
            add_courseware_context(threads, course, request.user)

        return utils.JsonResponse({
            'discussion_data':
            threads,  # TODO: Standardize on 'discussion_data' vs 'threads'
            'annotated_content_info':
            annotated_content_info,
            'num_pages':
            query_params['num_pages'],
            'page':
            query_params['page'],
            'corrected_text':
            query_params['corrected_text'],
        })
    else:
        course_id = str(course.id)
        tab_view = CourseTabView()
        return tab_view.get(request, course_id, 'discussion')
Beispiel #4
0
        url(r'^courses/{}/discussion/'.format(settings.COURSE_ID_PATTERN, ),
            include('lms.djangoapps.discussion.django_comment_client.urls')),
    ]

if is_forum_daily_digest_enabled():
    urlpatterns += notification_prefs_urls

urlpatterns += [
    url(r'^bulk_email/', include('lms.djangoapps.bulk_email.urls')),
]

urlpatterns += [
    url(
        r'^courses/{}/tab/(?P<tab_type>[^/]+)/$'.format(
            settings.COURSE_ID_PATTERN, ),
        CourseTabView.as_view(),
        name='course_tab_view',
    ),
]

urlpatterns += [
    # This MUST be the last view in the courseware--it's a catch-all for custom tabs.
    url(
        r'^courses/{}/(?P<tab_slug>[^/]+)/$'.format(
            settings.COURSE_ID_PATTERN, ),
        StaticCourseTabView.as_view(),
        name='static_tab',
    ),
]

if settings.FEATURES.get('ENABLE_STUDENT_HISTORY_VIEW'):