From 0dde7563336dc9d54dbf8571d4ecbb9c77449327 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Wed, 23 Jan 2013 00:37:20 -0500 Subject: [PATCH] fixing note url generation when there is no slug set --- karmaworld/apps/notes/models.py | 7 +++++-- karmaworld/urls.py | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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'), -- 2.25.1