Example #1
0
class IndexView(ListView):
    context_object_name = "feedbacks"
    template_name = 'feedback/index.html'
    paginate_by = 25
    model = Feedback
    form_class = FeedbackSearchForm
    create_form_class = FeedbackForm

    def get(self, request, *args, **kwargs):
        if 'title' in request.GET:
            self.form = FeedbackSearchForm(self.request.GET)
            self.create_form = FeedbackForm(user=self.request.user)
            if not self.form.is_valid():
                self.object_list = self.get_queryset()
                ctx = self.get_context_data(object_list=self.object_list)
                return self.render_to_response(ctx)
        else:
            self.form = FeedbackSearchForm()
            self.create_form = FeedbackForm(user=self.request.user)
        return super(IndexView, self).get(request, *args, **kwargs)

    def get_queryset(self):
        qs = self.model._default_manager.filter(status=True)
        if self.form.is_bound and self.form.is_valid():
            qs = qs.filter(**self.form.get_filters())
        return qs

    def get_context_data(self, *args, **kwargs):
        ctx = super(IndexView, self).get_context_data(*args, **kwargs)
        ctx['form'] = self.form
        ctx['create_form'] = self.create_form
        return ctx
Example #2
0
 def get(self, request, *args, **kwargs):
     if 'title' in request.GET:
         self.form = FeedbackSearchForm(self.request.GET)
         self.create_form = FeedbackForm(user=self.request.user)
         if not self.form.is_valid():
             self.object_list = self.get_queryset()
             ctx = self.get_context_data(object_list=self.object_list)
             return self.render_to_response(ctx)
     else:
         self.form = FeedbackSearchForm()
         self.create_form = FeedbackForm(user=self.request.user)
     return super(IndexView, self).get(request, *args, **kwargs)