Commit 9099f0dc by bmedx

CMS urls cleanup for Django 1.11

- Remove usage of django.urls.patterns
- Change urls tuples to lists
- Make all string view names callables
parent 6939a581
""" Course Import API URLs. """
from django.conf import settings
from django.conf.urls import (
patterns,
url,
)
from django.conf.urls import url
from cms.djangoapps.contentstore.api import views
urlpatterns = patterns(
'',
url(
r'^v0/import/{course_id}/$'.format(
course_id=settings.COURSE_ID_PATTERN,
),
views.CourseImportView.as_view(), name='course_import'
),
)
urlpatterns = [
url(r'^v0/import/{course_id}/$'.format(course_id=settings.COURSE_ID_PATTERN,),
views.CourseImportView.as_view(), name='course_import'),
]
......@@ -274,7 +274,7 @@ def reverse_url(handler_name, key_name=None, key_value=None, kwargs=None):
kwargs_for_reverse = {key_name: unicode(key_value)} if key_name else None
if kwargs:
kwargs_for_reverse.update(kwargs)
return reverse('contentstore.views.' + handler_name, kwargs=kwargs_for_reverse)
return reverse(handler_name, kwargs=kwargs_for_reverse)
def reverse_course_url(handler_name, course_key, kwargs=None):
......
......@@ -368,11 +368,11 @@ def certificates_list_handler(request, course_key_string):
return JsonResponse({"error": msg}, status=403)
if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):
certificate_url = reverse_course_url('certificates.certificates_list_handler', course_key)
certificate_url = reverse_course_url('certificates_list_handler', course_key)
course_outline_url = reverse_course_url('course_handler', course_key)
upload_asset_url = reverse_course_url('assets_handler', course_key)
activation_handler_url = reverse_course_url(
handler_name='certificates.certificate_activation_handler',
handler_name='certificate_activation_handler',
course_key=course_key
)
course_modes = [
......@@ -429,7 +429,7 @@ def certificates_list_handler(request, course_key_string):
course.certificates['certificates'].append(new_certificate.certificate_data)
response = JsonResponse(CertificateManager.serialize_certificate(new_certificate), status=201)
response["Location"] = reverse_course_url(
'certificates.certificates_detail_handler',
'certificates_detail_handler',
course.id,
kwargs={'certificate_id': new_certificate.id}
)
......
......@@ -264,7 +264,7 @@ def course_handler(request, course_key_string=None):
return HttpResponseBadRequest()
elif request.method == 'GET': # assume html
if course_key_string is None:
return redirect(reverse("home"))
return redirect(reverse('home'))
else:
return course_index(request, CourseKey.from_string(course_key_string))
else:
......@@ -572,7 +572,7 @@ def course_listing(request):
u'libraries': [format_library_for_view(lib) for lib in libraries],
u'show_new_library_button': get_library_creator_status(user),
u'user': user,
u'request_course_creator_url': reverse(u'contentstore.views.request_course_creator'),
u'request_course_creator_url': reverse('request_course_creator'),
u'course_creator_status': _get_course_creator_status(user),
u'rerun_creator_status': GlobalStaff().has_user(user),
u'allow_unicode_course_id': settings.FEATURES.get(u'ALLOW_UNICODE_COURSE_ID', False),
......
......@@ -210,7 +210,7 @@ class CertificatesListHandlerTestCase(
"""
Return url for the handler.
"""
return reverse_course_url('certificates.certificates_list_handler', self.course.id)
return reverse_course_url('certificates_list_handler', self.course.id)
def test_can_create_certificate(self):
"""
......@@ -441,7 +441,7 @@ class CertificatesDetailHandlerTestCase(
"""
cid = cid if cid > 0 else self._id
return reverse_course_url(
'certificates.certificates_detail_handler',
'certificates_detail_handler',
self.course.id,
kwargs={'certificate_id': cid},
)
......@@ -764,7 +764,7 @@ class CertificatesDetailHandlerTestCase(
"""
Activate and Deactivate the course certificate
"""
test_url = reverse_course_url('certificates.certificate_activation_handler', self.course.id)
test_url = reverse_course_url('certificate_activation_handler', self.course.id)
self._add_course_certificates(count=1, signatory_count=2, asset_path_format=signatory_path)
is_active = True
......@@ -795,7 +795,7 @@ class CertificatesDetailHandlerTestCase(
Tests certificate Activate and Deactivate should not be allowed if user
does not have write permissions on course.
"""
test_url = reverse_course_url('certificates.certificate_activation_handler', self.course.id)
test_url = reverse_course_url('certificate_activation_handler', self.course.id)
self._add_course_certificates(count=1, signatory_count=2, asset_path_format=signatory_path)
user = UserFactory()
self.client.login(username=user.username, password='test')
......@@ -814,7 +814,7 @@ class CertificatesDetailHandlerTestCase(
Certificate activation should fail when user has not read access to course then permission denied exception
should raised.
"""
test_url = reverse_course_url('certificates.certificate_activation_handler', self.course.id)
test_url = reverse_course_url('certificate_activation_handler', self.course.id)
test_user_client, test_user = self.create_non_staff_authed_user_client()
CourseEnrollment.enroll(test_user, self.course.id)
self._add_course_certificates(count=1, signatory_count=2, asset_path_format=signatory_path)
......
......@@ -112,7 +112,7 @@ class ItemTest(CourseTestCase):
data['display_name'] = display_name
if boilerplate is not None:
data['boilerplate'] = boilerplate
return self.client.ajax_post(reverse('contentstore.views.xblock_handler'), json.dumps(data))
return self.client.ajax_post(reverse('xblock_handler'), json.dumps(data))
def _create_vertical(self, parent_usage_key=None):
"""
......@@ -653,7 +653,7 @@ class DuplicateHelper(object):
if display_name is not None:
data['display_name'] = display_name
resp = self.client.ajax_post(reverse('contentstore.views.xblock_handler'), json.dumps(data))
resp = self.client.ajax_post(reverse('xblock_handler'), json.dumps(data))
return self.response_usage_key(resp)
......@@ -864,7 +864,7 @@ class TestMoveItem(ItemTest):
data['target_index'] = target_index
return self.client.patch(
reverse('contentstore.views.xblock_handler'),
reverse('xblock_handler'),
json.dumps(data),
content_type='application/json'
)
......@@ -1147,7 +1147,7 @@ class TestMoveItem(ItemTest):
data = {'move_source_locator': unicode(self.html_usage_key)}
with self.assertRaises(InvalidKeyError):
self.client.patch(
reverse('contentstore.views.xblock_handler'),
reverse('xblock_handler'),
json.dumps(data),
content_type='application/json'
)
......@@ -1157,7 +1157,7 @@ class TestMoveItem(ItemTest):
Test patch request without providing a move source locator.
"""
response = self.client.patch(
reverse('contentstore.views.xblock_handler')
reverse('xblock_handler')
)
self.assertEqual(response.status_code, 400)
response = json.loads(response.content)
......@@ -1308,7 +1308,7 @@ class TestMoveItem(ItemTest):
}
with self.assertRaises(ItemNotFoundError):
self.client.patch(
reverse('contentstore.views.xblock_handler'),
reverse('xblock_handler'),
json.dumps(data),
content_type='application/json'
)
......
"""
URLs for the maintenance app.
"""
from django.conf.urls import patterns, url
from django.conf.urls import url
from .views import ForcePublishCourseView, MaintenanceIndexView
urlpatterns = patterns(
'',
urlpatterns = [
url(r'^$', MaintenanceIndexView.as_view(), name='maintenance_index'),
url(r'^force_publish_course/?$', ForcePublishCourseView.as_view(), name='force_publish_course'),
)
]
"""
URL patterns for Javascript files used to load all of the XModule JS in one wad.
"""
from django.conf.urls import patterns, url
from django.conf.urls import url
from pipeline_js.views import xmodule_js_files, requirejs_xmodule
urlpatterns = patterns(
'pipeline_js.views',
url(r'^files\.json$', 'xmodule_js_files', name='xmodule_js_files'),
url(r'^xmodule\.js$', 'requirejs_xmodule', name='requirejs_xmodule'),
)
urlpatterns = [
url(r'^files\.json$', xmodule_js_files, name='xmodule_js_files'),
url(r'^xmodule\.js$', requirejs_xmodule, name='requirejs_xmodule'),
]
......@@ -21,7 +21,7 @@
<%block name="requirejs">
require(["js/factories/edit_tabs"], function (EditTabsFactory) {
EditTabsFactory("${context_course.location | n, js_escaped_string}", "${reverse('contentstore.views.tabs_handler', kwargs={'course_key_string': context_course.id})}");
EditTabsFactory("${context_course.location | n, js_escaped_string}", "${reverse('tabs_handler', kwargs={'course_key_string': context_course.id})}");
});
</%block>
......
......@@ -119,7 +119,7 @@ from openedx.core.djangolib.js_utils import (
ManageCourseUsersFactory(
"${context_course.display_name_with_default | h}",
${users | n, dump_js_escaped_json},
"${reverse('contentstore.views.course_team_handler', kwargs={'course_key_string': unicode(context_course.id), 'email': '@@EMAIL@@'}) | n, js_escaped_string}",
"${reverse('course_team_handler', kwargs={'course_key_string': unicode(context_course.id), 'email': '@@EMAIL@@'}) | n, js_escaped_string}",
${request.user.id | n, dump_js_escaped_json},
${allow_actions | n, dump_js_escaped_json}
);
......
......@@ -112,7 +112,7 @@ from openedx.core.djangolib.js_utils import (
ManageLibraryUsersFactory(
"${context_library.display_name_with_default | h}",
${users | n, dump_js_escaped_json},
"${reverse('contentstore.views.course_team_handler', kwargs={'course_key_string': library_key, 'email': '@@EMAIL@@'}) | n, js_escaped_string}",
"${reverse('course_team_handler', kwargs={'course_key_string': library_key, 'email': '@@EMAIL@@'}) | n, js_escaped_string}",
${request.user.id | n, dump_js_escaped_json},
${allow_actions | n, dump_js_escaped_json}
);
......
......@@ -19,21 +19,21 @@
% if context_course:
<%
course_key = context_course.id
index_url = reverse('contentstore.views.course_handler', kwargs={'course_key_string': unicode(course_key)})
course_team_url = reverse('contentstore.views.course_team_handler', kwargs={'course_key_string': unicode(course_key)})
assets_url = reverse('contentstore.views.assets_handler', kwargs={'course_key_string': unicode(course_key)})
textbooks_url = reverse('contentstore.views.textbooks_list_handler', kwargs={'course_key_string': unicode(course_key)})
videos_url = reverse('contentstore.views.videos_handler', kwargs={'course_key_string': unicode(course_key)})
import_url = reverse('contentstore.views.import_handler', kwargs={'course_key_string': unicode(course_key)})
course_info_url = reverse('contentstore.views.course_info_handler', kwargs={'course_key_string': unicode(course_key)})
export_url = reverse('contentstore.views.export_handler', kwargs={'course_key_string': unicode(course_key)})
settings_url = reverse('contentstore.views.settings_handler', kwargs={'course_key_string': unicode(course_key)})
grading_url = reverse('contentstore.views.grading_handler', kwargs={'course_key_string': unicode(course_key)})
advanced_settings_url = reverse('contentstore.views.advanced_settings_handler', kwargs={'course_key_string': unicode(course_key)})
tabs_url = reverse('contentstore.views.tabs_handler', kwargs={'course_key_string': unicode(course_key)})
index_url = reverse('course_handler', kwargs={'course_key_string': unicode(course_key)})
course_team_url = reverse('course_team_handler', kwargs={'course_key_string': unicode(course_key)})
assets_url = reverse('assets_handler', kwargs={'course_key_string': unicode(course_key)})
textbooks_url = reverse('textbooks_list_handler', kwargs={'course_key_string': unicode(course_key)})
videos_url = reverse('videos_handler', kwargs={'course_key_string': unicode(course_key)})
import_url = reverse('import_handler', kwargs={'course_key_string': unicode(course_key)})
course_info_url = reverse('course_info_handler', kwargs={'course_key_string': unicode(course_key)})
export_url = reverse('export_handler', kwargs={'course_key_string': unicode(course_key)})
settings_url = reverse('settings_handler', kwargs={'course_key_string': unicode(course_key)})
grading_url = reverse('grading_handler', kwargs={'course_key_string': unicode(course_key)})
advanced_settings_url = reverse('advanced_settings_handler', kwargs={'course_key_string': unicode(course_key)})
tabs_url = reverse('tabs_handler', kwargs={'course_key_string': unicode(course_key)})
certificates_url = ''
if settings.FEATURES.get("CERTIFICATES_HTML_VIEW") and context_course.cert_html_view_enabled:
certificates_url = reverse('contentstore.views.certificates.certificates_list_handler', kwargs={'course_key_string': unicode(course_key)})
certificates_url = reverse('certificates_list_handler', kwargs={'course_key_string': unicode(course_key)})
%>
<h2 class="info-course">
<span class="sr">${_("Current Course:")}</span>
......@@ -93,7 +93,7 @@
<a href="${course_team_url}">${_("Course Team")}</a>
</li>
<li class="nav-item nav-course-settings-group-configurations">
<a href="${reverse('contentstore.views.group_configurations_list_handler', kwargs={'course_key_string': unicode(course_key)})}">${_("Group Configurations")}</a>
<a href="${reverse('group_configurations_list_handler', kwargs={'course_key_string': unicode(course_key)})}">${_("Group Configurations")}</a>
</li>
<li class="nav-item nav-course-settings-advanced">
<a href="${advanced_settings_url}">${_("Advanced Settings")}</a>
......@@ -133,10 +133,10 @@
% elif context_library:
<%
library_key = context_library.location.course_key
index_url = reverse('contentstore.views.library_handler', kwargs={'library_key_string': unicode(library_key)})
import_url = reverse('contentstore.views.import_handler', kwargs={'course_key_string': unicode(library_key)})
lib_users_url = reverse('contentstore.views.manage_library_users', kwargs={'library_key_string': unicode(library_key)})
export_url = reverse('contentstore.views.export_handler', kwargs={'course_key_string': unicode(library_key)})
index_url = reverse('library_handler', kwargs={'library_key_string': unicode(library_key)})
import_url = reverse('import_handler', kwargs={'course_key_string': unicode(library_key)})
lib_users_url = reverse('manage_library_users', kwargs={'library_key_string': unicode(library_key)})
export_url = reverse('export_handler', kwargs={'course_key_string': unicode(library_key)})
%>
<h2 class="info-course">
<span class="sr">${_("Current Library:")}</span>
......
......@@ -110,7 +110,7 @@ class SSLClientTest(ModuleStoreTestCase):
redirects them to the signup page on CMS.
"""
self.client.get(
reverse('contentstore.views.login_page'),
reverse('login'),
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL)
)
......@@ -152,7 +152,7 @@ class SSLClientTest(ModuleStoreTestCase):
"""
response = self.client.get(
reverse('contentstore.views.login_page'),
reverse('login'),
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL)
)
self.assertEqual(response.status_code, 302)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment