예제 #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
예제 #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
예제 #3
0
 def render(self, context):
     context[self.var_name] = ArticleSearchForm()
     return ''
예제 #4
0
 def get_context_data(self, **kwargs):
     context = super(ArticleListView, self).get_context_data(**kwargs)
     context['article_search_form'] = ArticleSearchForm()
     return context
예제 #5
0
 def get(self, request, *args, **kwargs):
     self.form = ArticleSearchForm(request.GET or None)
     return super(ArticleSearchView, self).get(self, request, *args,
                                               **kwargs)
예제 #6
0
 def get(self, request, *args, **kwargs):
     self.form = ArticleSearchForm(request.GET or None)
     return super(ArticleSearchView, self).get(self, request, *args, **kwargs)