add push_to_lms to Studio; uses MITX_FEATURES['ENABLE_PUSH_TO_LMS']
This commit is contained in:
@@ -14,6 +14,7 @@ from .item import *
|
||||
from .import_export import *
|
||||
from .preview import *
|
||||
from .public import *
|
||||
from .push_to_lms import *
|
||||
from .user import *
|
||||
from .tabs import *
|
||||
from .transcripts_ajax import *
|
||||
|
||||
39
cms/djangoapps/contentstore/views/push_to_lms.py
Normal file
39
cms/djangoapps/contentstore/views/push_to_lms.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django_future.csrf import ensure_csrf_cookie
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from mitxmako.shortcuts import render_to_response
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
from .access import get_location_and_verify_access
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@login_required
|
||||
def push_to_lms(request, org, course, name):
|
||||
"""
|
||||
This method serves up the 'Push to LMS' page
|
||||
"""
|
||||
location = get_location_and_verify_access(request, org, course, name)
|
||||
|
||||
course_module = modulestore().get_item(location)
|
||||
|
||||
log.debug('push_to_lms course_module=%s' % course_module)
|
||||
|
||||
msg = ""
|
||||
|
||||
if 'action' in request.GET and course_module.lms.giturl:
|
||||
# do the push, using script
|
||||
doexport = getattr(settings, 'CMS_EXPORT_COURSE_SCRIPT', '')
|
||||
if doexport and os.path.exists(doexport):
|
||||
cmd = '{0} {1} {2} {3}'.format(doexport, course_module.id, request.user, course_module.lms.giturl)
|
||||
msg = os.popen(cmd).read()
|
||||
|
||||
return render_to_response('push_to_lms.html', {
|
||||
'context_course': course_module,
|
||||
'msg': msg,
|
||||
})
|
||||
56
cms/templates/push_to_lms.html
Normal file
56
cms/templates/push_to_lms.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<%! from django.utils.translation import ugettext as _ %>
|
||||
<%inherit file="base.html" />
|
||||
<%namespace name='static' file='static_content.html'/>
|
||||
|
||||
<%! from django.core.urlresolvers import reverse %>
|
||||
<%block name="title">${_("Push Course to LMS")}</%block>
|
||||
<%block name="bodyclass">is-signedin course tools export</%block>
|
||||
|
||||
<%block name="content">
|
||||
<div class="wrapper-mast wrapper">
|
||||
<header class="mast has-subtitle">
|
||||
<h1 class="page-header">
|
||||
<small class="subtitle">${_("Tools")}</small>
|
||||
<span class="sr">> </span>${_("Push to LMS")}
|
||||
</h1>
|
||||
</header>
|
||||
</div>
|
||||
|
||||
<div class="main-wrapper">
|
||||
<div class="inner-wrapper">
|
||||
|
||||
<article class="export-overview">
|
||||
<div class="description">
|
||||
<h2>${_("About Push to LMS")}</h2>
|
||||
<p>${_("Use this to export your course to its github site.")}</p>
|
||||
<p>${_("This will then trigger an automatic update of the main LMS site")}
|
||||
${_("and update the contents of your course visible there to students.")}</p>
|
||||
|
||||
<ul>
|
||||
<li>${_("Your course:")} <font color="green">${context_course.id}</font></li>
|
||||
<li>${_("Course github site:")} <font color="blue">${context_course.lms.giturl}</font></li>
|
||||
% if msg:
|
||||
<li>msg: <pre>${msg|n}</pre></li>
|
||||
% endif
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- default state -->
|
||||
<div class="export-form-wrapper">
|
||||
<form action="${reverse('push_to_lms', kwargs=dict(org=context_course.location.org, course=context_course.location.course, name=context_course.location.name))}" method="post" enctype="multipart/form-data" class="export-form">
|
||||
<h2>${_("Push Course:")}</h2>
|
||||
|
||||
% if not context_course.lms.giturl:
|
||||
<p style="color:red">${_("giturl must be defined in your course settings before you can push to LMS")}</p>
|
||||
% else:
|
||||
<a href="${reverse('push_to_lms', kwargs=dict(org=context_course.location.org, course=context_course.location.course, name=context_course.location.name))}?action=push" class="button-export">${_("Push to LMS")}</a>
|
||||
% endif
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</%block>
|
||||
@@ -104,6 +104,11 @@
|
||||
<li class="nav-item nav-course-tools-export">
|
||||
<a href="${export_url}">${_("Export")}</a>
|
||||
</li>
|
||||
% if settings.MITX_FEATURES.get('ENABLE_PUSH_TO_LMS') and 'allow_push_to_lms' in context_course.advanced_modules:
|
||||
<li class="nav-item nav-course-tools-push">
|
||||
<a href="${reverse('push_to_lms', kwargs=dict(org=ctx_loc.org, course=ctx_loc.course, name=ctx_loc.name))}">${_("Push to LMS")}</a>
|
||||
</li>
|
||||
% endif
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
12
cms/urls.py
12
cms/urls.py
@@ -96,8 +96,16 @@ urlpatterns += patterns('',
|
||||
url(r'^i18n.js$', 'django.views.i18n.javascript_catalog', js_info_dict),
|
||||
)
|
||||
|
||||
if settings.FEATURES.get('ENABLE_SERVICE_STATUS'):
|
||||
urlpatterns += patterns('',
|
||||
|
||||
if settings.FEATURES.get('ENABLE_PUSH_TO_LMS'):
|
||||
urlpatterns += (url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/push/(?P<name>[^/]+)$',
|
||||
'contentstore.views.push_to_lms', name='push_to_lms'),)
|
||||
|
||||
if settings.ENABLE_JASMINE:
|
||||
urlpatterns += (url(r'^_jasmine/', include('django_jasmine.urls')),)
|
||||
|
||||
if settings.MITX_FEATURES.get('ENABLE_SERVICE_STATUS'):
|
||||
urlpatterns += (
|
||||
url(r'^status/', include('service_status.urls')),
|
||||
)
|
||||
|
||||
|
||||
78
scripts/cms_export_to_github
Executable file
78
scripts/cms_export_to_github
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# python script to export course from CMS to github
|
||||
#
|
||||
# Usage: python cms_export_to_github <course_location> <username> <github_ssl_url> [<repo_dir>]
|
||||
#
|
||||
|
||||
import os, sys, string, re
|
||||
import datetime
|
||||
|
||||
DIR = "/mnt/data_export"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# usage
|
||||
|
||||
def usage():
|
||||
print "Usage: python cms_export_to_github <course_location> <username> <github_ssl_url> [<repo_dir>]"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
try:
|
||||
course_loc = sys.argv.pop(1)
|
||||
username = sys.argv.pop(1)
|
||||
repo = sys.argv.pop(1)
|
||||
except:
|
||||
usage()
|
||||
sys.exit(0)
|
||||
|
||||
if course_loc.startswith('i4x://'):
|
||||
course_loc = course_loc[6:]
|
||||
|
||||
m = re.match('git@[^ ]+\.git', repo)
|
||||
if not m:
|
||||
print "Oops, not a git ssh url?"
|
||||
print repo
|
||||
print "Expecting something like git@github.com:mitocw/edx4edx_lite.git"
|
||||
sys.exit(-1)
|
||||
|
||||
if len(sys.argv)>1:
|
||||
rdir = sys.argv.pop(1)
|
||||
rdir = os.path.basename(rdir)
|
||||
else:
|
||||
rdir = repo.rsplit('/',1)[-1].rsplit('.git',1)[0]
|
||||
print "rdir = %s" % rdir
|
||||
|
||||
rdirp = '%s/%s' % (DIR, rdir)
|
||||
if os.path.exists(rdirp):
|
||||
print "directory already exists, doing a git pull instead of git clone"
|
||||
cmd = 'cd %s/%s; git pull' % (DIR, rdir)
|
||||
else:
|
||||
cmd = 'cd %s; git clone "%s"' % (DIR, repo)
|
||||
|
||||
print cmd
|
||||
ret_git = os.popen(cmd).read()
|
||||
print ret_git
|
||||
|
||||
if not os.path.exists('%s/%s' % (DIR, rdir)):
|
||||
print "git clone failed!"
|
||||
sys.exit(-1)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# export course
|
||||
|
||||
cmd = "./DJANGO-ADMIN-CMS export %s %s" % (course_loc, rdirp)
|
||||
print cmd
|
||||
ret_export = os.popen(cmd).read()
|
||||
print ret_export
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# push to github
|
||||
|
||||
dt = datetime.datetime.now()
|
||||
cmd = 'cd %s; git add .; git commit -a -m "(%s) Export %s"; git push' % (rdirp, username, dt)
|
||||
print cmd
|
||||
ret_push = os.popen(cmd).read()
|
||||
print ret_push
|
||||
|
||||
|
||||
7
scripts/cms_export_to_github_local
Executable file
7
scripts/cms_export_to_github_local
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd ~/mitx_all
|
||||
source STARTUP
|
||||
cd edx-platform
|
||||
|
||||
python scripts/cms_export_to_github $*
|
||||
Reference in New Issue
Block a user