fixing note url generation when there is no slug set
authorSeth Woodworth <seth@sethish.com>
Wed, 23 Jan 2013 05:37:20 +0000 (00:37 -0500)
committerSeth Woodworth <seth@sethish.com>
Wed, 23 Jan 2013 05:37:20 +0000 (00:37 -0500)
karmaworld/apps/notes/models.py
karmaworld/urls.py

index 21f0441d99eed9a383f6994d80de8211cc323479..7b1f0b3c7d3a0bf0bfaba1cb58d332dd0455451a 100644 (file)
@@ -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
index b41cbaa39aed9e26fed7d6fa41abc853c7abfa00..ce561832fe61757915a9f8e45e93dc8f396cf7c5 100644 (file)
@@ -24,6 +24,10 @@ urlpatterns = patterns('',
     url(r'^raw/(?P<pk>\d+)$', raw_file, name='note_raw'),
     url(r'^(?P<school_slug>[^/]+)/(?P<slug>[^/]+)$', \
         CourseDetailView.as_view(), name='course_detail'),
+    # note file as id
+    url(r'^(?P<school_slug>[^/]+)/(?P<course_slug>[^/]+)/(?P<pk>[\d^/]+)$', \
+        NoteDetailView.as_view(), name='note_detail'),
+    # note file by note.slug
     url(r'^(?P<school_slug>[^/]+)/(?P<course_slug>[^/]+)/(?P<slug>[^/]+)$', \
         NoteDetailView.as_view(), name='note_detail'),