From 2223d2007b40727e9fa5e47a462ea4f859de71a9 Mon Sep 17 00:00:00 2001
From: Calen Pennington <calen.pennington@gmail.com>
Date: Thu, 20 Sep 2012 10:53:36 -0400
Subject: [PATCH] Only display the LMS link if it's set up, and don't error if
 it isn't

---
 cms/djangoapps/contentstore/views.py | 17 +++++++++++------
 cms/envs/aws.py                      |  2 +-
 cms/envs/common.py                   |  2 ++
 cms/templates/unit.html              |  2 ++
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py
index 25617e0da1c..9e655fa7b34 100644
--- a/cms/djangoapps/contentstore/views.py
+++ b/cms/djangoapps/contentstore/views.py
@@ -106,6 +106,16 @@ def edit_item(request):
     item = modulestore().get_item(item_location)
     item.get_html = wrap_xmodule(item.get_html, item, "xmodule_edit.html")
 
+    if settings.LMS_BASE is not None:
+        lms_link = "{lms_base}/courses/{course_id}/jump_to/{location}".format(
+            lms_base=settings.LMS_BASE,
+            # TODO: These will need to be changed to point to the particular instance of this problem in the particular course
+            course_id=[course.id for course in modulestore().get_courses() if course.location.org == item.location.org and course.location.course == item.location.course][0],
+            location=item.location,
+        )
+    else:
+        lms_link = None
+
     return render_to_response('unit.html', {
         'contents': item.get_html(),
         'js_module': item.js_module_name,
@@ -114,12 +124,7 @@ def edit_item(request):
         'previews': get_module_previews(request, item),
         'metadata': item.metadata,
         # TODO: It would be nice to able to use reverse here in some form, but we don't have the lms urls imported
-        'lms_link': "{lms_base}/courses/{course_id}/jump_to/{location}".format(
-            lms_base=settings.LMS_BASE,
-            # TODO: These will need to be changed to point to the particular instance of this problem in the particular course
-            course_id=[course.id for course in modulestore().get_courses() if course.location.org == item.location.org and course.location.course == item.location.course][0],
-            location=item.location,
-        )
+        'lms_link': lms_link,
     })
 
 
diff --git a/cms/envs/aws.py b/cms/envs/aws.py
index b70de13b56f..34312eb25bd 100644
--- a/cms/envs/aws.py
+++ b/cms/envs/aws.py
@@ -19,7 +19,7 @@ DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
 with open(ENV_ROOT / "cms.env.json") as env_file:
     ENV_TOKENS = json.load(env_file)
 
-LMS_BASE = ENV_TOKENS['LMS_BASE']
+LMS_BASE = ENV_TOKENS.get('LMS_BASE')
 
 SITE_NAME = ENV_TOKENS['SITE_NAME']
 
diff --git a/cms/envs/common.py b/cms/envs/common.py
index f1440c72926..d111db80955 100644
--- a/cms/envs/common.py
+++ b/cms/envs/common.py
@@ -88,6 +88,8 @@ TEMPLATE_CONTEXT_PROCESSORS = (
     'django.core.context_processors.csrf',  # necessary for csrf protection
 )
 
+LMS_BASE = None
+
 ################################# Jasmine ###################################
 JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee'
 
diff --git a/cms/templates/unit.html b/cms/templates/unit.html
index e0c1213b433..0db507f897c 100644
--- a/cms/templates/unit.html
+++ b/cms/templates/unit.html
@@ -42,7 +42,9 @@
       </section>
     </section>
     ${contents}
+    % if lms_link is not None:
     <a class="lms-link" href="${lms_link}">View in LMS</a>
+    % endif
     <section class="previews">
       % for preview in previews:
         <section class="preview">
-- 
GitLab