From 293bd30a59a9c33df4135ece2cb71734e752a563 Mon Sep 17 00:00:00 2001 From: Nate Hardison Date: Thu, 30 May 2013 18:56:00 -0700 Subject: [PATCH] Use chat settings when deciding whether to render Only render the chat widget if both the site has enabled it in the `MITX_FEATURES` and if the course has enabled it. In addition, fail gracefully with a log warning if the `JABBER_DOMAIN` is not set, and do not try to render the widget. However, do go ahead and render the rest of the courseware. --- lms/djangoapps/courseware/views.py | 23 +++++++++++++++++++---- lms/templates/courseware/courseware.html | 6 +++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 9dc9f77bbe..f1e1f7660c 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -240,21 +240,27 @@ def chat_settings(course, user): Returns a dict containing the settings required to connect to a Jabber chat server and room. """ + domain = getattr(settings, "JABBER_DOMAIN", None) + if domain is None: + log.warning('You must set JABBER_DOMAIN in the settings to ' + 'enable the chat widget') + return None + return { - 'domain': settings.JABBER_DOMAIN, + 'domain': domain, # Jabber doesn't like slashes, so replace with dashes 'room': "{ID}_class".format(ID=course.id.replace('/', '-')), 'username': "{USER}@{DOMAIN}".format( - USER=user.username, DOMAIN=settings.JABBER_DOMAIN + USER=user.username, DOMAIN=domain ), # TODO: clearly this needs to be something other than the username # should also be something that's not necessarily tied to a # particular course 'password': "{USER}@{DOMAIN}".format( - USER=user.username, DOMAIN=settings.JABBER_DOMAIN + USER=user.username, DOMAIN=domain ), } @@ -323,8 +329,17 @@ def index(request, course_id, chapter=None, section=None, 'xqa_server': settings.MITX_FEATURES.get('USE_XQA_SERVER', 'http://xqa:server@content-qa.mitx.mit.edu/xqa') } - if course.show_chat: + # Only show the chat if it's enabled by the course and in the + # settings. + show_chat = course.show_chat and settings.MITX_FEATURES['ENABLE_CHAT'] + if show_chat: context['chat'] = chat_settings(course, user) + # If we couldn't load the chat settings, then don't show + # the widget in the courseware. + if context['chat'] is None: + show_chat = False + + context['show_chat'] = show_chat chapter_descriptor = course.get_child_by(lambda m: m.url_name == chapter) if chapter_descriptor is not None: diff --git a/lms/templates/courseware/courseware.html b/lms/templates/courseware/courseware.html index 2fa3adec0c..e009e535e3 100644 --- a/lms/templates/courseware/courseware.html +++ b/lms/templates/courseware/courseware.html @@ -6,7 +6,7 @@ <%block name="headextra"> <%static:css group='course'/> <%include file="../discussion/_js_head_dependencies.html" /> - % if course.show_chat: + % if show_chat: ## It'd be better to have this in a place like lms/css/vendor/candy, ## but the candy_res/ folder contains images and other junk, and it @@ -115,7 +115,7 @@ % endif -% if course.show_chat: +% if show_chat: @@ -189,7 +189,7 @@ -% if course.show_chat: +% if show_chat:
Open Chat