From: Seth Woodworth Date: Wed, 23 Jan 2013 05:37:20 +0000 (-0500) Subject: fixing note url generation when there is no slug set X-Git-Tag: release-20150131~551^2~4 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0dde7563336dc9d54dbf8571d4ecbb9c77449327;p=oweals%2Fkarmaworld.git fixing note url generation when there is no slug set --- diff --git a/karmaworld/apps/notes/models.py b/karmaworld/apps/notes/models.py index 21f0441..7b1f0b3 100644 --- a/karmaworld/apps/notes/models.py +++ b/karmaworld/apps/notes/models.py @@ -68,9 +68,12 @@ class Note(models.Model): def get_absolute_url(self): """ Resolve note url, use 'note' route and slug if slug - otherwise use note and id + otherwise use note.id """ - return u"/{0}/{1}/{2}".format(self.course.school.slug, self.course.slug, self.slug) + if self.slug == None: + return u"/{0}/{1}/{2}".format(self.course.school.slug, self.course.slug, self.slug) + else: + return u"/{0}/{1}/{2}".format(self.course.school.slug, self.course.slug, self.id) # FIXME: replace the following GOOGLE_USER in a settings.py diff --git a/karmaworld/urls.py b/karmaworld/urls.py index b41cbaa..ce56183 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -24,6 +24,10 @@ urlpatterns = patterns('', url(r'^raw/(?P\d+)$', raw_file, name='note_raw'), url(r'^(?P[^/]+)/(?P[^/]+)$', \ CourseDetailView.as_view(), name='course_detail'), + # note file as id + url(r'^(?P[^/]+)/(?P[^/]+)/(?P[\d^/]+)$', \ + NoteDetailView.as_view(), name='note_detail'), + # note file by note.slug url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)$', \ NoteDetailView.as_view(), name='note_detail'),