Skip to content

Commit

Permalink
Sort search results, images, and attachments.
Browse files Browse the repository at this point in the history
When providing a list of results these results should be sorted to give
consistent results. Order search results and images by the time they
were changed and attachments by there name. This fixes the Django 1.11
UnorderedObjectListWarning.
  • Loading branch information
floemker committed Nov 7, 2017
1 parent afefd8e commit f656638
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/wiki/plugins/attachments/views.py
Expand Up @@ -386,7 +386,7 @@ def get_queryset(self):
Q(original_filename__contains=self.query) |
Q(current_revision__description__contains=self.query) |
Q(article__current_revision__title__contains=self.query))
return qs
return qs.order_by('original_filename')

def get_context_data(self, **kwargs):
# Is this a bit of a hack? Use better inheritance?
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/plugins/images/views.py
Expand Up @@ -41,7 +41,7 @@ def get_queryset(self):
article=self.article,
current_revision__deleted=False)
images.select_related()
return images
return images.order_by('-current_revision__imagerevision__created')

def get_context_data(self, **kwargs):
kwargs.update(ArticleMixin.get_context_data(self, **kwargs))
Expand Down
4 changes: 2 additions & 2 deletions src/wiki/views/article.py
Expand Up @@ -686,15 +686,15 @@ def dispatch(self, request, *args, **kwargs):

def get_queryset(self):
if not self.query:
return models.Article.objects.none()
return models.Article.objects.none().order_by('-current_revision__created')
articles = models.Article.objects.filter(
Q(current_revision__title__icontains=self.query) |
Q(current_revision__content__icontains=self.query))
if not permissions.can_moderate(
models.URLPath.root().article,
self.request.user):
articles = articles.active().can_read(self.request.user)
return articles
return articles.order_by('-current_revision__created')

def get_context_data(self, **kwargs):
kwargs = super(SearchView, self).get_context_data(**kwargs)
Expand Down

0 comments on commit f656638

Please sign in to comment.