Increased specificity of penfield get_article conditions for 404 raising. Corrected...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Fri, 5 Nov 2010 21:19:00 +0000 (17:19 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Fri, 5 Nov 2010 21:19:00 +0000 (17:19 -0400)
contrib/penfield/models.py
models/base.py

index 6550f8a..8248340 100644 (file)
@@ -387,7 +387,7 @@ class NewsletterView(MultiView, FeedMultiViewMixin):
        def get_articles_by_issue(self, request, numbering, extra_context=None):
                try:
                        issue = self.newsletter.issues.get(numbering=numbering)
-               except:
+               except NewsletterIssue.DoesNotExist:
                        raise Http404
                context = extra_context or {}
                context.update({'issue': issue})
@@ -403,7 +403,7 @@ class NewsletterView(MultiView, FeedMultiViewMixin):
                        articles = articles.filter(date__day=day)
                try:
                        article = articles.get(slug=slug)
-               except:
+               except NewsletterArticle.DoesNotExist:
                        raise Http404
                context = self.get_context()
                context.update(extra_context or {})
index dabe491..ae15d16 100644 (file)
@@ -291,6 +291,11 @@ class TreeManager(models.Manager):
                """
                segments = path.split(pathsep)
                
+               # Check for a trailing pathsep so we can restore it later.
+               trailing_pathsep = False
+               if segments[-1] == '':
+                       trailing_pathsep = True
+               
                # Clean out blank segments. Handles multiple consecutive pathseps.
                while True:
                        try:
@@ -318,6 +323,12 @@ class TreeManager(models.Manager):
                        kwargs[prefix[:-2]] = root
                        return kwargs
                
+               def build_path(segments):
+                       path = pathsep.join(segments)
+                       if trailing_pathsep and segments and segments[-1] != '':
+                               path += pathsep
+                       return path
+               
                def find_obj(segments, depth, deepest_found):
                        try:
                                obj = self.get(**make_query_kwargs(segments[:depth]))
@@ -341,13 +352,13 @@ class TreeManager(models.Manager):
                                depth = (len(segments) + depth)/2
                                
                                if deepest_found == depth:
-                                       return obj, pathsep.join(segments[deepest_found:]) or None
+                                       return obj, build_path(segments[deepest_found:]) or None
                                
                                try:
                                        return find_obj(segments, depth, deepest_found)
                                except self.model.DoesNotExist:
                                        # Then the deepest one was already found.
-                                       return obj, pathsep.join(segments[deepest_found:])
+                                       return obj, build_path(segments[deepest_found:])
                
                return find_obj(segments, len(segments), 0)