Ejemplo n.º 1
0
class ArticleSearchView(ListView):
    def get(self, request, *args, **kwargs):
        self.form = ArticleSearchForm(request.GET or None)
        return super(ArticleSearchView, self).get(self, request, *args,
                                                  **kwargs)

    def get_queryset(self):
        articles = []
        if self.form.is_valid():
            keywords = self.form.cleaned_data['q']
            articles = Article.objects.get_active()
            articles = articles.filter(
                Q(title__icontains=keywords) | Q(text__icontains=keywords)
                | Q(excerpt__icontains=keywords)
                | Q(tags__name__in=[keywords])).distinct()
        return articles

    def get_context_data(self, **kwargs):
        context = super(ArticleSearchView, self).get_context_data(**kwargs)
        context['query'] = self.form.cleaned_data['q']
        context['article_search_form'] = self.form
        return context
Ejemplo n.º 2
0
class ArticleSearchView(ListView):

    def get(self, request, *args, **kwargs):
        self.form = ArticleSearchForm(request.GET or None)
        return super(ArticleSearchView, self).get(self, request, *args, **kwargs)

    def get_queryset(self):
        articles = []
        if self.form.is_valid():
            keywords = self.form.cleaned_data['q']
            articles = Article.objects.get_active()
            articles = articles.filter(
                Q(title__icontains=keywords) |
                Q(text__icontains=keywords) |
                Q(excerpt__icontains=keywords) |
                Q(tags__name__in=[keywords])).distinct()
        return articles

    def get_context_data(self, **kwargs):
        context = super(ArticleSearchView, self).get_context_data(**kwargs)
        context['query'] = self.form.cleaned_data['q']
        context['article_search_form'] = self.form
        return context
Ejemplo n.º 3
0
 def render(self, context):
     context[self.var_name] = ArticleSearchForm()
     return ''
Ejemplo n.º 4
0
 def get_context_data(self, **kwargs):
     context = super(ArticleListView, self).get_context_data(**kwargs)
     context['article_search_form'] = ArticleSearchForm()
     return context
Ejemplo n.º 5
0
 def get(self, request, *args, **kwargs):
     self.form = ArticleSearchForm(request.GET or None)
     return super(ArticleSearchView, self).get(self, request, *args,
                                               **kwargs)
Ejemplo n.º 6
0
 def get(self, request, *args, **kwargs):
     self.form = ArticleSearchForm(request.GET or None)
     return super(ArticleSearchView, self).get(self, request, *args, **kwargs)