diff options
author | Dan McGee <dan@archlinux.org> | 2012-09-30 08:40:25 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-09-30 08:40:29 +0200 |
commit | 44dc458a2b8ca500acda72b437a720dd4f57bedf (patch) | |
tree | 9c11914cac376632b3b304c3115309ad632d5d91 | |
parent | 4b36fdd65404efa19f0c7ab4f62d97c5ce86a4fc (diff) | |
download | archweb-44dc458a2b8ca500acda72b437a720dd4f57bedf.tar.gz archweb-44dc458a2b8ca500acda72b437a720dd4f57bedf.tar.xz |
Hide staging packages in search results
This is for users that aren't logged in; developers will still see them.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | packages/views/search.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/packages/views/search.py b/packages/views/search.py index 1fbe569..99bf703 100644 --- a/packages/views/search.py +++ b/packages/views/search.py @@ -55,8 +55,11 @@ class PackageSearchForm(forms.Form): initial=50) def __init__(self, *args, **kwargs): + show_staging = kwargs.pop('show_staging', False) super(PackageSearchForm, self).__init__(*args, **kwargs) - repos = Repo.objects.filter(staging=False) + repos = Repo.objects.all() + if not show_staging: + repos = repos.filter(staging=False) self.fields['repo'].choices = make_choice( [repo.name for repo in repos]) self.fields['arch'].choices = make_choice( @@ -129,11 +132,14 @@ class SearchListView(ListView): allowed_sort = list(sort_fields) + ["-" + s for s in sort_fields] def get(self, request, *args, **kwargs): - self.form = PackageSearchForm(data=request.GET) + self.form = PackageSearchForm(data=request.GET, + show_staging=self.request.user.is_authenticated()) return super(SearchListView, self).get(request, *args, **kwargs) def get_queryset(self): packages = Package.objects.normal() + if not self.request.user.is_authenticated(): + packages = packages.filter(repo__staging=False) if self.form.is_valid(): packages = parse_form(self.form, packages) sort = self.form.cleaned_data['sort'] @@ -174,9 +180,12 @@ def search_json(request): } if request.GET: - form = PackageSearchForm(data=request.GET) + form = PackageSearchForm(data=request.GET, + show_staging=request.user.is_authenticated()) if form.is_valid(): packages = Package.objects.normal() + if not request.user.is_authenticated(): + packages = packages.filter(repo__staging=False) packages = parse_form(form, packages)[:limit] container['results'] = packages container['valid'] = True |