Skip to content

Commit

Permalink
Merge pull request openedx#381 from Stanford-Online/azimpradhan/rever…
Browse files Browse the repository at this point in the history
…t-edit-course-tabs

Revert "Merge pull request #287 from Stanford-Online/azimpradhan/sysadmin-course-tabs"
  • Loading branch information
azimpradhan committed Dec 12, 2015
2 parents 74d31ca + 82061b1 commit ef0c4a9
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from courseware.courses import get_course_by_id

from xmodule.tabs import primitive_insert, primitive_delete
from contentstore.views import tabs
from opaque_keys import InvalidKeyError
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from opaque_keys.edx.keys import CourseKey
Expand All @@ -25,6 +25,7 @@ def print_course(course):
for index, item in enumerate(course.tabs):
print index + 1, '"' + item.get('type') + '"', '"' + item.get('name', '') + '"'


# course.tabs looks like this
# [{u'type': u'courseware'}, {u'type': u'course_info', u'name': u'Course Info'}, {u'type': u'textbooks'},
# {u'type': u'discussion', u'name': u'Discussion'}, {u'type': u'wiki', u'name': u'Wiki'},
Expand Down Expand Up @@ -83,15 +84,15 @@ def handle(self, *args, **options):
raise CommandError(Command.delete_option.help)
num = int(args[0])
if query_yes_no('Deleting tab {0} Confirm?'.format(num), default='no'):
primitive_delete(course, num - 1) # -1 for 0-based indexing
tabs.primitive_delete(course, num - 1) # -1 for 0-based indexing
elif options['insert']:
if len(args) != 3:
raise CommandError(Command.insert_option.help)
num = int(args[0])
tab_type = args[1]
name = args[2]
if query_yes_no('Inserting tab {0} "{1}" "{2}" Confirm?'.format(num, tab_type, name), default='no'):
primitive_insert(course, num - 1, tab_type, name) # -1 as above
tabs.primitive_insert(course, num - 1, tab_type, name) # -1 as above
except ValueError as e:
# Cute: translate to CommandError so the CLI error prints nicely.
raise CommandError(e)
34 changes: 34 additions & 0 deletions cms/djangoapps/contentstore/views/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from edxmako.shortcuts import render_to_response
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
from xmodule.tabs import CourseTabList, CourseTab, InvalidTabsException, StaticTab
from opaque_keys.edx.keys import CourseKey, UsageKey

Expand Down Expand Up @@ -167,3 +168,36 @@ def get_tab_by_locator(tab_list, usage_key_string):
url_slug=item.location.name,
)
return CourseTabList.get_tab_by_id(tab_list, static_tab.tab_id)


# "primitive" tab edit functions driven by the command line.
# These should be replaced/deleted by a more capable GUI someday.
# Note that the command line UI identifies the tabs with 1-based
# indexing, but this implementation code is standard 0-based.

def validate_args(num, tab_type):
"Throws for the disallowed cases."
if num <= 1:
raise ValueError('Tabs 1 and 2 cannot be edited')
if tab_type == 'static_tab':
raise ValueError('Tabs of type static_tab cannot be edited here (use Studio)')


def primitive_delete(course, num):
"Deletes the given tab number (0 based)."
tabs = course.tabs
validate_args(num, tabs[num].get('type', ''))
del tabs[num]
# Note for future implementations: if you delete a static_tab, then Chris Dodge
# points out that there's other stuff to delete beyond this element.
# This code happens to not delete static_tab so it doesn't come up.
modulestore().update_item(course, ModuleStoreEnum.UserID.primitive_command)


def primitive_insert(course, num, tab_type, name):
"Inserts a new tab at the given number (0 based)."
validate_args(num, tab_type)
new_tab = CourseTab.from_json({u'type': unicode(tab_type), u'name': unicode(name)})
tabs = course.tabs
tabs.insert(num, new_tab)
modulestore().update_item(course, ModuleStoreEnum.UserID.primitive_command)
18 changes: 9 additions & 9 deletions cms/djangoapps/contentstore/views/tests/test_tabs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Tests for tab functions (just primitive). """

import json
from xmodule.tabs import primitive_insert, primitive_delete
from contentstore.views import tabs
from contentstore.tests.utils import CourseTestCase
from contentstore.utils import reverse_course_url
from xmodule.x_module import STUDENT_VIEW
Expand Down Expand Up @@ -198,29 +198,29 @@ def test_delete(self):
"""Test primitive tab deletion."""
course = CourseFactory.create()
with self.assertRaises(ValueError):
primitive_delete(course, 0)
tabs.primitive_delete(course, 0)
with self.assertRaises(ValueError):
primitive_delete(course, 1)
tabs.primitive_delete(course, 1)
with self.assertRaises(IndexError):
primitive_delete(course, 6)
primitive_delete(course, 2)
tabs.primitive_delete(course, 6)
tabs.primitive_delete(course, 2)
self.assertFalse({u'type': u'textbooks'} in course.tabs)
# Check that discussion has shifted up
self.assertEquals(course.tabs[2], {'type': 'discussion', 'name': 'Discussion'})

def test_insert(self):
"""Test primitive tab insertion."""
course = CourseFactory.create()
primitive_insert(course, 2, 'notes', 'aname')
tabs.primitive_insert(course, 2, 'notes', 'aname')
self.assertEquals(course.tabs[2], {'type': 'notes', 'name': 'aname'})
with self.assertRaises(ValueError):
primitive_insert(course, 0, 'notes', 'aname')
tabs.primitive_insert(course, 0, 'notes', 'aname')
with self.assertRaises(ValueError):
primitive_insert(course, 3, 'static_tab', 'aname')
tabs.primitive_insert(course, 3, 'static_tab', 'aname')

def test_save(self):
"""Test course saving."""
course = CourseFactory.create()
primitive_insert(course, 3, 'notes', 'aname')
tabs.primitive_insert(course, 3, 'notes', 'aname')
course2 = modulestore().get_course(course.id)
self.assertEquals(course2.tabs[3], {'type': 'notes', 'name': 'aname'})
31 changes: 0 additions & 31 deletions common/lib/xmodule/xmodule/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import logging

from xblock.fields import List
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
from openedx.core.lib.api.plugins import PluginError

# We should only scrape strings for i18n in this file, since the target language is known only when
Expand Down Expand Up @@ -531,32 +529,3 @@ class UnequalTabsException(Exception):
A complaint about tab lists being unequal
"""
pass


# Tab functions
def validate_args(num, tab_type):
"Throws for the disallowed cases."
if num <= 1:
raise ValueError('Tabs 1 and 2 cannot be edited')
if tab_type == 'static_tab':
raise ValueError('Tabs of type static_tab cannot be edited here (use Studio)')


def primitive_delete(course, num):
"Deletes the given tab number (0 based)."
tabs = course.tabs
validate_args(num, tabs[num].get('type', ''))
del tabs[num]
# Note for future implementations: if you delete a static_tab, then Chris Dodge
# points out that there's other stuff to delete beyond this element.
# This code happens to not delete static_tab so it doesn't come up.
modulestore().update_item(course, ModuleStoreEnum.UserID.primitive_command)


def primitive_insert(course, num, tab_type, name):
"Inserts a new tab at the given number (0 based)."
validate_args(num, tab_type)
new_tab = CourseTab.from_json({u'type': unicode(tab_type), u'name': unicode(name)})
tabs = course.tabs
tabs.insert(num, new_tab)
modulestore().update_item(course, ModuleStoreEnum.UserID.primitive_command)
44 changes: 0 additions & 44 deletions lms/djangoapps/dashboard/sysadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import dashboard.git_import as git_import
from django_comment_client.management_utils import rename_user as rename_user_util
from dashboard.git_import import GitImportError
from dashboard.sysadmin_extensions import sysadmin_course_tabs
from dashboard.models import CourseImportLog
from external_auth.models import ExternalAuthMap
from external_auth.views import generate_password
Expand Down Expand Up @@ -382,48 +381,6 @@ def post(self, request):
return render_to_response(self.template_name, context)


class CourseTabs(SysadminDashboardView):
"""
Handles rendering the view and processing requests for Edit Course Tabs
"""

def get(self, request):
"""
Displays the form for Edit Course Tabs
"""

if not request.user.is_superuser:
raise Http404

context = {
'msg': self.msg,
'djangopid': os.getpid(),
'modeflag': {'course_tabs': 'active-section'},
'edx_platform_version': getattr(settings, 'EDX_PLATFORM_VERSION_STRING', ''),
}
return render_to_response(self.template_name, context)

def post(self, request):
"""Handle requests to Edit Course Tabs"""

if not request.user.is_superuser:
raise Http404

action = request.POST.get('action', '')
track.views.server_track(request, action, {}, page='course_tabs_sysdashboard')

if action in ['get_current_tabs', 'delete_tab', 'insert_tab']:
self.msg = sysadmin_course_tabs.process_request(action, request)

context = {
'msg': self.msg,
'djangopid': os.getpid(),
'modeflag': {'course_tabs': 'active-section'},
'edx_platform_version': getattr(settings, 'EDX_PLATFORM_VERSION_STRING', ''),
}
return render_to_response(self.template_name, context)


class Courses(SysadminDashboardView):
"""
This manages adding/updating courses from git, deleting courses, and
Expand Down Expand Up @@ -637,7 +594,6 @@ def post(self, request):
page='courses_sysdashboard')

courses = {course.id: course for course in self.get_courses()}

if action == 'add_course':
gitloc = request.POST.get('repo_location', '').strip().replace(' ', '').replace(';', '')
branch = request.POST.get('repo_branch', '').strip().replace(' ', '').replace(';', '')
Expand Down
Empty file.
110 changes: 0 additions & 110 deletions lms/djangoapps/dashboard/sysadmin_extensions/sysadmin_course_tabs.py

This file was deleted.

1 change: 0 additions & 1 deletion lms/djangoapps/dashboard/sysadmin_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'',
url(r'^$', sysadmin.Users.as_view(), name="sysadmin"),
url(r'^courses/?$', sysadmin.Courses.as_view(), name="sysadmin_courses"),
url(r'^course_tabs/?$', sysadmin.CourseTabs.as_view(), name="sysadmin_course_tabs"),
url(r'^staffing/?$', sysadmin.Staffing.as_view(), name="sysadmin_staffing"),
url(r'^gitlogs/?$', sysadmin.GitLogs.as_view(), name="gitlogs"),
url(r'^gitlogs/(?P<course_id>.+)$', sysadmin.GitLogs.as_view(),
Expand Down
Loading

0 comments on commit ef0c4a9

Please sign in to comment.