Commit af18880a by Clinton Blackburn

Updated Course ID Regex

This regex is nearly identical to the one used by LMS. The only difference is the internal capture groups have been replaced with character sets to avoid issues with the Swagger UI attempting to parse the internal capture groups and pass them along as arguments.
parent 29437878
import re
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from analytics_data_api.v0.views import courses as views from analytics_data_api.v0.views import courses as views
COURSE_ID_PATTERN = r'(?P<course_id>[^/+]+[/+][^/+]+[/+][^/]+)'
COURSE_URLS = [ COURSE_URLS = [
('activity', views.CourseActivityWeeklyView, 'activity'), ('activity', views.CourseActivityWeeklyView, 'activity'),
('recent_activity', views.CourseActivityMostRecentWeekView, 'recent_activity'), ('recent_activity', views.CourseActivityMostRecentWeekView, 'recent_activity'),
...@@ -18,4 +16,5 @@ COURSE_URLS = [ ...@@ -18,4 +16,5 @@ COURSE_URLS = [
urlpatterns = [] urlpatterns = []
for path, view, name in COURSE_URLS: for path, view, name in COURSE_URLS:
urlpatterns += patterns('', url(r'^(?P<course_id>.+)/' + re.escape(path) + r'/$', view.as_view(), name=name)) regex = r'^{0}/{1}/$'.format(COURSE_ID_PATTERN, path)
urlpatterns += patterns('', url(regex, view.as_view(), name=name))
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