Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #712 from floemker/sorting
Sort search results, images, and attachments.
  • Loading branch information
benjaoming committed Nov 7, 2017
2 parents afefd8e + f656638 commit dc4354b
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(original_filename__contains=self.query) |
Q(current_revision__description__contains=self.query) | Q(current_revision__description__contains=self.query) |
Q(article__current_revision__title__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): def get_context_data(self, **kwargs):
# Is this a bit of a hack? Use better inheritance? # 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, article=self.article,
current_revision__deleted=False) current_revision__deleted=False)
images.select_related() images.select_related()
return images return images.order_by('-current_revision__imagerevision__created')


def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs.update(ArticleMixin.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): def get_queryset(self):
if not self.query: if not self.query:
return models.Article.objects.none() return models.Article.objects.none().order_by('-current_revision__created')
articles = models.Article.objects.filter( articles = models.Article.objects.filter(
Q(current_revision__title__icontains=self.query) | Q(current_revision__title__icontains=self.query) |
Q(current_revision__content__icontains=self.query)) Q(current_revision__content__icontains=self.query))
if not permissions.can_moderate( if not permissions.can_moderate(
models.URLPath.root().article, models.URLPath.root().article,
self.request.user): self.request.user):
articles = articles.active().can_read(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): def get_context_data(self, **kwargs):
kwargs = super(SearchView, self).get_context_data(**kwargs) kwargs = super(SearchView, self).get_context_data(**kwargs)
Expand Down

0 comments on commit dc4354b

Please sign in to comment.