1. Curtis Maloney
  2. gnocchi-forum

Commits

cur...@tinbrain.net  committed 9393b49

Flattened URL stacking to simplify views and urls

  • Participants
  • Parent commits 1f86ba8
  • Branches default

Comments (0)

Files changed (3)

File gnocchi_forum/models.py

View file
  • Ignore whitespace
     @models.permalink
     def get_absolute_url(self):
         return 'thread-detail', (), {
-            'forum_slug': self.forum.slug,
-            'forum_id': self.forum.id,
             'thread_slug': self.slug,
             'thread_id': self.id,
-        },
+        }
 
     def last_post(self):
         try:

File gnocchi_forum/urls.py

View file
  • Ignore whitespace
     url(r'^$', 'forum_index', name='forum-index' ),
     url(r'^forum/(?P<forum_slug>[-\w]+)/(?P<forum_id>\d+)/$',
         'forum_detail', name='forum-detail' ),
-    url(r'^forum/(?P<forum_slug>[-\w]+)/(?P<forum_id>\d+)/(?P<thread_slug>[-\w]+)/(?P<thread_id>\d+)/$',
+    url(r'^thread/(?P<thread_slug>[-\w]+)/(?P<thread_id>\d+)/$',
         'thread_detail', name='thread-detail'),
 )

File gnocchi_forum/views.py

View file
  • Ignore whitespace
 
 #   Forum detail [ thread list ]
 def forum_detail(request, forum_slug, forum_id):
-    forum = get_object_or_404(models.Forum, id=forum_id)
+    forum = get_object_or_404(models.Forum, pk=forum_id)
     if not forum_slug == forum.slug:
         return HttpResponsePermanentRedirect(forum.get_absolute_url())
     # permssion check?
     )
 
 #   Thread detail [ post list ]
-def thread_detail(request, forum_slug, forum_id, thread_slug, thread_id):
-    thread = get_object_or_404(models.Thread, id=thread_id, forum__id=forum_id)
-    if forum_slug != thread.forum.slug or thread_slug != thread.slug:
+def thread_detail(request, thread_slug, thread_id):
+    thread = get_object_or_404(models.Thread, pk=thread_id)
+    if not thread_slug == thread.slug:
         return HttpResponsePermanentRedirect(thread.get_absolute_url())
     return object_list(request,
         queryset = thread.post_set.all(),