Exemple #1
0
def state_filter_form(result, get=None):
    states = get_states_to_filter(get)
    if states:
        form = StateFilterForm(get, result=result)
    else:
        init_states = AppSettings.get_initial_state_filter()
        inital_conf = {}
        for i in init_states:
            key = i + str(result.id)
            inital_conf[key] = True
        form = StateFilterForm(result=result, initial=inital_conf)
    return form
def state_filter_form(result, get=None):
    states = get_states_to_filter(get)
    if states:
        form = StateFilterForm(get, result=result)
    else:
        init_states = AppSettings.get_initial_state_filter()
        inital_conf = {}
        for i in init_states:
            key = i + str(result.id)
            inital_conf[key] = True
        form = StateFilterForm(result=result, initial=inital_conf)
    return form
    def get(self, request, result_id, *args, **kwargs):
        try:
            result = Result.objects.get(id=result_id)
        except ObjectDoesNotExist:
            return HttpResponse(
                json.dumps({
                    'status': 'ERROR',
                    'content': "Not found."
                }),
                content_type='application/json',
            )

        response = {}

        # form with states
        states = get_states_to_filter(request.GET)
        if states:
            form = StateFilterForm(request.GET, result=result)
            try:
                self.request.GET['filter'] == 'all'
            except KeyError:
                pass
            else:
                AppSettings.set_initial_state_filter(states)
        else:
            init_states = AppSettings.get_initial_state_filter()
            inital_conf = {}
            for i in init_states:
                key = i + str(result.id)
                inital_conf[key] = True
            form = StateFilterForm(result=result, initial=inital_conf)

        try:
            search_string = request.GET['search']
        except KeyError:
            search_string = ''

        context = RequestContext(
            request, {
                'flat_tree': render_result(result, search_string, request.GET),
                'result': result,
                'state_filter_form': form,
            })
        template_name = "report/result.html"
        template = loader.get_template(template_name)
        response['content'] = template.render(context)
        response['status'] = 'OK'
        return HttpResponse(
            json.dumps(response),
            content_type='application/json',
        )
    def get(self, request, result_id, *args, **kwargs):
        try:
            result = Result.objects.get(id=result_id)
        except ObjectDoesNotExist:
            return HttpResponse(
                json.dumps({'status': 'ERROR', 'content': "Not found."}),
                content_type='application/json',
            )

        response = {}

        # form with states
        states = get_states_to_filter(request.GET)
        if states:
            form = StateFilterForm(request.GET, result=result)
            try:
                self.request.GET['filter'] == 'all'
            except KeyError:
                pass
            else:
                AppSettings.set_initial_state_filter(states)
        else:
            init_states = AppSettings.get_initial_state_filter()
            inital_conf = {}
            for i in init_states:
                key = i + str(result.id)
                inital_conf[key] = True
            form = StateFilterForm(result=result, initial=inital_conf)

        try:
            search_string = request.GET['search']
        except KeyError:
            search_string = ''

        context = RequestContext(request, {
            'flat_tree': render_result(result, search_string, request.GET),
            'result': result,
            'state_filter_form': form,
        })
        template_name = "report/result.html"
        template = loader.get_template(template_name)
        response['content'] = template.render(context)
        response['status'] = 'OK'
        return HttpResponse(
            json.dumps(response),
            content_type='application/json',
        )