From c7209a736e33e786b3d42474d591fbd95b7954c3 Mon Sep 17 00:00:00 2001
From: Calen Pennington <calen.pennington@gmail.com>
Date: Mon, 17 Sep 2012 16:30:37 -0400
Subject: [PATCH] Add links from the editing page for the cms to the
 corresponding page in the lms

---
 cms/djangoapps/contentstore/views.py | 10 +++++++++-
 cms/envs/aws.py                      |  2 ++
 cms/envs/dev.py                      |  2 ++
 cms/templates/unit.html              |  1 +
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py
index 74ff6657eab..25617e0da1c 100644
--- a/cms/djangoapps/contentstore/views.py
+++ b/cms/djangoapps/contentstore/views.py
@@ -8,6 +8,7 @@ from django.contrib.auth.decorators import login_required
 from django.core.context_processors import csrf
 from django_future.csrf import ensure_csrf_cookie
 from django.core.urlresolvers import reverse
+from django.conf import settings
 
 from xmodule.modulestore import Location
 from xmodule.x_module import ModuleSystem
@@ -111,7 +112,14 @@ def edit_item(request):
         'category': item.category,
         'url_name': item.url_name,
         'previews': get_module_previews(request, item),
-        'metadata': item.metadata
+        '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,
+        )
     })
 
 
diff --git a/cms/envs/aws.py b/cms/envs/aws.py
index f03e10c9b1f..b70de13b56f 100644
--- a/cms/envs/aws.py
+++ b/cms/envs/aws.py
@@ -19,6 +19,8 @@ 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']
+
 SITE_NAME = ENV_TOKENS['SITE_NAME']
 
 LOG_DIR = ENV_TOKENS['LOG_DIR']
diff --git a/cms/envs/dev.py b/cms/envs/dev.py
index 13436ac5a52..19b4dec8b2f 100644
--- a/cms/envs/dev.py
+++ b/cms/envs/dev.py
@@ -36,6 +36,8 @@ DATABASES = {
     }
 }
 
+LMS_BASE = "http://localhost:8000"
+
 REPOS = {
     'edx4edx': {
         'branch': 'master',
diff --git a/cms/templates/unit.html b/cms/templates/unit.html
index b2501c3d36b..e0c1213b433 100644
--- a/cms/templates/unit.html
+++ b/cms/templates/unit.html
@@ -42,6 +42,7 @@
       </section>
     </section>
     ${contents}
+    <a class="lms-link" href="${lms_link}">View in LMS</a>
     <section class="previews">
       % for preview in previews:
         <section class="preview">
-- 
GitLab