Skip to content

Commit

Permalink
Fixed breadcrump indexing after pathlib port.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Apr 17, 2015
1 parent 6b8b6b9 commit d17ac3a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions docs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,17 @@ def document_url(doc):

class DocumentManager(models.Manager):

def parents(self, path):
"""Iterate over this path's parents, in ascending order."""
for segment in os.path.split(str(path))[1:]: # ignores the root element
yield Path(segment)

def breadcrumbs(self, document):
or_queries = [models.Q(path=path)
for path in self.parents(Path(document.path))]
if or_queries:
# get an ascending list of parent paths except the root path ('.')
parent_paths = list(Path(document.path).parents)[:-1]
if parent_paths:
or_queries = [models.Q(path=str(path)) for path in parent_paths]
return (self.filter(reduce(operator.or_, or_queries))
.filter(release=document.release)
.exclude(pk=document.pk)
.order_by('path'))
return self.none()
else:
return self.none()


class Document(models.Model):
Expand Down

0 comments on commit d17ac3a

Please sign in to comment.