From: Seth Woodworth Date: Sat, 15 Jun 2013 00:40:19 +0000 (-0400) Subject: update url routes with nicer .format()ing X-Git-Tag: release-20150131~417 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8c9b78768c196861202ba45ee2ad93a0e238a869;p=oweals%2Fkarmaworld.git update url routes with nicer .format()ing --- diff --git a/karmaworld/urls.py b/karmaworld/urls.py index 817394e..5de44f9 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -21,6 +21,25 @@ from karmaworld.apps.notes.views import PDFView # See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#hooking-adminsite-instances-into-your-urlconf admin.autodiscover() +# reused named regex capture groups +SLUG = r'(?P<{0}slug>[-A-Za-z0-9_]+)' + +""" +# ex: SLUG.format('') :> (?P[-A-Za-z0-9_]+) +# ex: SLUG.format('school_') :> (?P[-A-Za-z0-9_]+) + + ex: course url + url(r'^' + SLUG.format('school_') + '/' + SLUG.format('') + '/' + CourseDetailView.as_view(), name='course_detail'), + + (?P[^/]+)/(?P[^/]+)/(?P[\d^/]+)$', \ + NoteView.as_view(), name='note_detail_pk'), +""" + +SCHOOL_SLUG = r'(?P[-A-Za-z0-9_]+)' +COURSE_SLUG = r'(?P[-A-Za-z0-9_]+)' +NOTE_SLUG = r'(?P[-A-Za-z0-9_]+)' + # See: https://docs.djangoproject.com/en/dev/topics/http/urls/ urlpatterns = patterns('', ## Administrative URLpatterns @@ -44,15 +63,22 @@ urlpatterns = patterns('', {'document_root': settings.MEDIA_ROOT, }), # VIEW for displaying a single Course - url(r'^(?P[^/]+)/(?P[-A-Za-z0-9_]+)$', \ + url(r'^' + SLUG.format('school_') + '/' + SLUG.format('') + '$', CourseDetailView.as_view(), name='course_detail'), + ## NOTE MODEL + # Valid url cases to the Note page + # a: school/course/id + # b: school/course/id/slug + # c: s../c../slug # note file as id, for notes without titles yet url(r'^(?P[^/]+)/(?P[^/]+)/(?P[\d^/]+)$', \ NoteView.as_view(), name='note_detail_pk'), # note file by note.slug - url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)$', \ + url(r'^' + SLUG.format('school_') + '/' + SLUG.format('course_') +'/'+ SLUG.format('') +'$', NoteView.as_view(), name='note_detail'), + #url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)$', \ + # NoteView.as_view(), name='note_detail'), # ---- JSON views ----# # uploading files