def get_queryset(self): """Return a list of all the content we're looking at, filtered by search criteria.""" if self.request.user.has_perm("core.read_content"): content = models.Content.objects.all() else: content = models.Content.objects.filter( Q(authors=self.request.user) | Q(uploader=self.request.user) ).all() form = forms.ContentSearchForm(self.request.GET) if form.is_valid(): # Filter the content by certain criteria query = Q() if form.data.get("title"): query &= Q(title__contains=form.data["title"]) if form.data.get("id"): query &= Q(pk=int(form.data["id"])) if form.data.get("after"): query &= Q(created__gt=form.data["after"]) if form.data.get("before"): query &= Q(created__lt=form.data["before"]) if form.data.get("authors"): query &= Q(authors=form.data["authors"]) if form.data.get("tags"): query &= Q(tags=form.data["tags"]) content = content.filter(query) return content.order_by("-modified")
def get_queryset(self): """Return a list of all the content we're looking at, filtered by search criteria.""" if self.request.user.has_perm('core.read_content'): content = models.Content.objects.all() else: content = models.Content.objects.filter(authors=self.request.user).all() form = forms.ContentSearchForm(self.request.GET) if form.is_valid(): # Filter the content by certain criteria query = Q() if 'title' in form.data and form.data['title']: query &= Q(title__contains=form.data['title']) if 'id' in form.data and form.data['id']: query &= Q(pk=int(form.data['id'])) if 'after' in form.data and form.data['after']: query &= Q(created__gt=form.data['after']) if 'before' in form.data and form.data['before']: query &= Q(created__lt=form.data['before']) if 'authors' in form.data and form.data['authors']: query &= Q(authors=form.data['authors']) content = content.filter(query) return content.order_by('-modified')
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["form"] = forms.ContentSearchForm(self.request.GET) return context