render discussion_profile_page as a fragment
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
## mako
|
||||
|
||||
<%! main_css = "style-discussion-main" %>
|
||||
<%namespace name='static' file='../static_content.html'/>
|
||||
|
||||
<%page expression_filter="h"/>
|
||||
<%inherit file="../main.html" />
|
||||
<%namespace name='static' file='../static_content.html'/>
|
||||
<%def name="online_help_token()"><% return "discussions" %></%def>
|
||||
|
||||
<%!
|
||||
import json
|
||||
from django.utils.translation import ugettext as _, ungettext
|
||||
@@ -16,13 +14,6 @@ from django_comment_client.permissions import has_permission
|
||||
from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_string
|
||||
%>
|
||||
|
||||
<%block name="bodyclass">discussion discussion-user-profile</%block>
|
||||
<%block name="pagetitle">${_("Discussion - {course_number}").format(course_number=course.display_number_with_default)}</%block>
|
||||
|
||||
<%block name="headextra">
|
||||
<%include file="_js_head_dependencies.html" />
|
||||
</%block>
|
||||
|
||||
<%block name="js_extra">
|
||||
<%include file="_js_body_dependencies.html" />
|
||||
<%static:require_module module_name="discussion/js/discussion_profile_page_factory" class_name="DiscussionProfilePageFactory">
|
||||
@@ -48,9 +39,6 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str
|
||||
</%static:require_module>
|
||||
</%block>
|
||||
|
||||
<%include file="../courseware/course_navigation.html" args="active_page='discussion'" />
|
||||
|
||||
<%block name="content">
|
||||
<section class="discussion inline-discussion discussion-user-profile-board page-content-container">
|
||||
<header class="page-header">
|
||||
<div class="page-header-main">
|
||||
@@ -89,7 +77,6 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str
|
||||
</main>
|
||||
</div>
|
||||
</section>
|
||||
</%block>
|
||||
|
||||
<%include file="_underscore_templates.html" />
|
||||
<%include file="_thread_list_template.html" />
|
||||
|
||||
@@ -1463,7 +1463,11 @@ class ForumDiscussionXSSTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTe
|
||||
Test that XSS attack is prevented
|
||||
"""
|
||||
mock_threads.return_value = [], 1, 1
|
||||
mock_from_django_user.return_value.to_dict.return_value = {}
|
||||
mock_from_django_user.return_value.to_dict.return_value = {
|
||||
'upvoted_ids': [],
|
||||
'downvoted_ids': [],
|
||||
'subscribed_thread_ids': []
|
||||
}
|
||||
mock_request.side_effect = make_mock_request_impl(course=self.course, text='dummy')
|
||||
|
||||
url = reverse('user_profile',
|
||||
|
||||
@@ -564,7 +564,8 @@ def user_profile(request, course_key, user_id):
|
||||
'annotated_content_info': context['annotated_content_info'],
|
||||
})
|
||||
else:
|
||||
return render_to_response('discussion/discussion_profile_page.html', context)
|
||||
tab_view = CourseTabView()
|
||||
return tab_view.get(request, unicode(course_key), 'discussion', profile_page_context=context)
|
||||
except User.DoesNotExist:
|
||||
raise Http404
|
||||
except ValueError:
|
||||
@@ -655,7 +656,15 @@ class DiscussionBoardFragmentView(EdxFragmentView):
|
||||
"""
|
||||
Component implementation of the discussion board.
|
||||
"""
|
||||
def render_to_fragment(self, request, course_id=None, discussion_id=None, thread_id=None, **kwargs):
|
||||
def render_to_fragment(
|
||||
self,
|
||||
request,
|
||||
course_id=None,
|
||||
discussion_id=None,
|
||||
thread_id=None,
|
||||
profile_page_context=None,
|
||||
**kwargs
|
||||
):
|
||||
"""
|
||||
Render the discussion board to a fragment.
|
||||
|
||||
@@ -668,8 +677,8 @@ class DiscussionBoardFragmentView(EdxFragmentView):
|
||||
Returns:
|
||||
Fragment: The fragment representing the discussion board
|
||||
"""
|
||||
course_key = CourseKey.from_string(course_id)
|
||||
try:
|
||||
course_key = CourseKey.from_string(course_id)
|
||||
base_context = _create_base_discussion_view_context(request, course_key)
|
||||
# Note:
|
||||
# After the thread is rendered in this fragment, an AJAX
|
||||
@@ -689,11 +698,15 @@ class DiscussionBoardFragmentView(EdxFragmentView):
|
||||
else None
|
||||
)
|
||||
context = _create_discussion_board_context(request, base_context, thread=thread)
|
||||
html = render_to_string('discussion/discussion_board_fragment.html', context)
|
||||
inline_js = render_to_string('discussion/discussion_board_js.template', context)
|
||||
if profile_page_context:
|
||||
# EDUCATOR-2119: styles are hard to reconcile if the profile page isn't also a fragment
|
||||
html = render_to_string('discussion/discussion_profile_page.html', profile_page_context)
|
||||
else:
|
||||
html = render_to_string('discussion/discussion_board_fragment.html', context)
|
||||
|
||||
fragment = Fragment(html)
|
||||
self.add_fragment_resource_urls(fragment)
|
||||
inline_js = render_to_string('discussion/discussion_board_js.template', context)
|
||||
fragment.add_javascript(inline_js)
|
||||
if not settings.REQUIRE_DEBUG:
|
||||
fragment.add_javascript_url(staticfiles_storage.url('discussion/js/discussion_board_factory.js'))
|
||||
|
||||
Reference in New Issue
Block a user