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', )
def render_result(result, search_string=None, get=None): filtering_active = bool(search_string or get) # convert states to those in DB state_filter = TestResult.TEST_STATES.list_keys(get_states_to_filter(get)) if not state_filter: state_filter = TestResult.TEST_STATES.list_keys( AppSettings.get_initial_state_filter()) # perform global queries in tests and groups; we'll use our caching for these groups = TestGroupResult.objects.for_result(result) root_groups = groups.root() tests = TestResult.objects.for_result(result).by_states(state_filter) if search_string: groups = groups.search_in_title(search_string) tests = tests.search_in_title(search_string) groups = groups.select_related('parent', 'group', 'group__parent') tests = tests.select_related().prefetch_related('testlog_set', 'risk_set') rf = RecursiveFilter(groups, tests) def is_requested(group, force=False): """ lets put together the tree structure and check if there is anything to display in this group """ count = len(rf.subelements_filter(group)) if count > 0 or force: group.displayed_count = count return True return False def filter_children(children, level): """ recursively go through provided groups """ ch_dict = SortedDict() for child in children: child.left_margin = level + 1 child.child_left_margin = level + 2 is_child_requested = is_requested( child, level == -1 and not filtering_active) if is_child_requested: groups_gchildren = get_groups_children(child, groups) if len(groups_gchildren) > 0: ch_dict[child] = filter_children(groups_gchildren, level + 1) else: ch_dict[child] = None return ch_dict if not filtering_active: root_groups = filter(lambda x: x.parent is None, groups) groups_dict = filter_children(root_groups, -1) result_list = RecursiveRenderer(groups_dict).render() return result_list
def render_result(result, search_string=None, get=None): filtering_active = bool(search_string or get) # convert states to those in DB state_filter = TestResult.TEST_STATES.list_keys(get_states_to_filter(get)) if not state_filter: state_filter = TestResult.TEST_STATES.list_keys(AppSettings.get_initial_state_filter()) # perform global queries in tests and groups; we'll use our caching for these groups = TestGroupResult.objects.for_result(result) root_groups = groups.root() tests = TestResult.objects.for_result(result).by_states(state_filter) if search_string: groups = groups.search_in_title(search_string) tests = tests.search_in_title(search_string) groups = groups.select_related("parent", "group", "group__parent") tests = tests.select_related().prefetch_related("testlog_set", "risk_set") rf = RecursiveFilter(groups, tests) def is_requested(group, force=False): """ lets put together the tree structure and check if there is anything to display in this group """ count = len(rf.subelements_filter(group)) if count > 0 or force: group.displayed_count = count return True return False def filter_children(children, level): """ recursively go through provided groups """ ch_dict = SortedDict() for child in children: child.left_margin = level + 1 child.child_left_margin = level + 2 is_child_requested = is_requested(child, level == -1 and not filtering_active) if is_child_requested: groups_gchildren = get_groups_children(child, groups) if len(groups_gchildren) > 0: ch_dict[child] = filter_children(groups_gchildren, level + 1) else: ch_dict[child] = None return ch_dict if not filtering_active: root_groups = filter(lambda x: x.parent is None, groups) groups_dict = filter_children(root_groups, -1) result_list = RecursiveRenderer(groups_dict).render() return result_list
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 auth_enabled(request): return {'auth_enabled': AppSettings.get_autologin_user_id() is None}
def post(self, request, *args, **kwargs): AppSettings.unset_autologin_user_id() return super(FirstRunView, self).post(request, *args, **kwargs)
def get(self, request, *args, **kwargs): AppSettings.set_autologin_user_id(request.user.id) return self.get_redirect()
def get(self, request, *args, **kwargs): user = get_user_model()(username='******') user.save() AppSettings.set_autologin_user_id(user.id) return self.get_redirect()