Commits

Anonymous committed 1f86ba8

Changed to more google-friendly URLs
Fixed typo in Categories

Comments (0)

Files changed (3)

gnocchi_forum/models.py

 
     class Meta:
         ordering = ('-order',)
-        verbose_name_plural = 'Gategories'
+        verbose_name_plural = 'Categories'
 
     def __unicode__(self):
         return self.name
         return (
             'forum-detail',
             (),
-            {'forum': self.slug},
+            {'forum_slug': self.slug, 'forum_id': self.pk},
         )
 
 class Thread(models.Model):
     @models.permalink
     def get_absolute_url(self):
         return 'thread-detail', (), {
-            'forum': self.forum.slug,
-            'thread': self.slug,
+            'forum_slug': self.forum.slug,
+            'forum_id': self.forum.id,
+            'thread_slug': self.slug,
+            'thread_id': self.id,
         },
 
     def last_post(self):

gnocchi_forum/urls.py

 
 urlpatterns = patterns('gnocchi_forum.views',
     url(r'^$', 'forum_index', name='forum-index' ),
-    url(r'^forum/(?P<forum>[-\w]+)/$', 'forum_detail', name='forum-detail' ),
-    url(r'^forum/(?P<forum>[-\w]+)/(?P<thread>[-\w]+)/$', 'thread_detail',
-        name='thread-detail'
-    ),
+    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+)/$',
+        'thread_detail', name='thread-detail'),
 )

gnocchi_forum/views.py

     )
 
 #   Forum detail [ thread list ]
-def forum_detail(request, forum):
-    forum = get_object_or_404(models.Forum, slug=forum)
+def forum_detail(request, forum_slug, forum_id):
+    forum = get_object_or_404(models.Forum, id=forum_id)
+    if not forum_slug == forum.slug:
+        return HttpResponsePermanentRedirect(forum.get_absolute_url())
     # permssion check?
     return object_list(request,
         queryset = forum.thread_set.annotate(
     )
 
 #   Thread detail [ post list ]
-def thread_detail(request, forum, thread):
-    thread = get_object_or_404(models.Thread, slug=thread, forum__slug=forum)
+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:
+        return HttpResponsePermanentRedirect(thread.get_absolute_url())
     return object_list(request,
         queryset = thread.post_set.all(),
         template_name='forum/thread_detail.html',