Permalink
Browse files

Sort search results, images, and attachments.

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 f6566385455cc0e29e79a26799b0d49a693c9d78
Showing with 4 additions and 4 deletions.
  1. +1 −1 src/wiki/plugins/attachments/views.py
  2. +1 −1 src/wiki/plugins/images/views.py
  3. +2 −2 src/wiki/views/article.py
@@ -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?
@@ -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))
@@ -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)

0 comments on commit f656638

Please sign in to comment.