def advance_search(request, tmpl='search/advanced_search.html'): """View of /advance-search/""" errors = None data = request.GET target = data.get('target') plan_form = PlanForm(data) case_form = CaseForm(data) run_form = RunForm(data) # Update MultipleModelChoiceField on each form dynamically plan_form.populate(data) case_form.populate(data) run_form.populate(data) all_forms = (plan_form, case_form, run_form) errors = [f.errors for f in all_forms if not f.is_valid()] if errors or not data: PRODUCT_CHOICE = [(p.pk, p.name) for p in cached_entities('product')] PLAN_TYPE_CHOICES = cached_entities('testplantype') errors = fmt_errors(errors) return render_to_response(tmpl, locals(), context_instance=RequestContext(request)) start = time.time() results = query(request, plan_form.cleaned_data, run_form.cleaned_data, case_form.cleaned_data, target) results = order_targets(target, results, data) end = time.time() timecost = round(end - start, 3) queries = fmt_queries(*[f.cleaned_data for f in all_forms]) queries['Target'] = target return render_results(request, results, timecost, queries)
def view_test_run_report(request): templates = { 'per_build_report': 'report/caserun_report_per_build.html', 'per_tester_report': 'report/caserun_report_per_tester.html', 'per_priority_report': 'report/caserun_report_per_priority.html', 'per_plan_tag_report': 'report/testrun_report_per_plan_tag.html', 'per_plan_build_report': 'report/testrun_report_per_plan_build.html', 'runs_with_rates_per_plan_tag': 'report/testrun_report_by_plan_tag_with_rates.html', 'runs_with_rates_per_plan_build': 'report/testrun_report_by_plan_build_with_rates.html', } errors = None queries = request.GET data = {} report_type = queries.get('report_type') PRODUCT_CHOICE = [ (p.pk, p.name) for p in cached_entities('product') ] if queries: run_form = RunForm(queries) run_form.populate(queries) if run_form.is_valid(): queries = run_form.cleaned_data data = test_run_report(queries, report_type) else: errors = run_form.errors tmpl = templates.get(report_type, 'report/common/search_run.html') queries = fmt_queries(queries) request_path = remove_from_request_path(request, 'report_type') if request_path: path_without_build = remove_from_request_path(request_path, 'r_build') data.update(locals()) return direct_to_template(request, tmpl, data)
def advance_search(request, tmpl='search/advanced_search.html'): ''' View of /advance-search/ ''' errors = None data = request.GET target = data.get('target') plan_form = PlanForm(data) case_form = CaseForm(data) run_form = RunForm(data) # Update MultipleModelChoiceField on each form dynamically plan_form.populate(data) case_form.populate(data) run_form.populate(data) all_forms = (plan_form, case_form, run_form) errors = [f.errors for f in all_forms if not f.is_valid()] if errors or not data: PRODUCT_CHOICE = [ (p.pk, p.name) for p in cached_entities('product') ] PLAN_TYPE_CHOICES = cached_entities('testplantype') errors = fmt_errors(errors) return render_to_response(tmpl, locals(), context_instance=RequestContext(request)) start = time.time() results = query(request, plan_form.cleaned_data, run_form.cleaned_data, case_form.cleaned_data, target) results = order_targets(target, results, data) end = time.time() timecost = round(end - start, 3) queries = fmt_queries(*[f.cleaned_data for f in all_forms]) queries['Target'] = target return render_results(request, results, timecost, queries)
def advance_search(request): data = request.GET target = data.get('target') plan_form = PlanForm(data) case_form = CaseForm(data) run_form = RunForm(data) # Update MultipleModelChoiceField on each form dynamically plan_form.populate(data) case_form.populate(data) run_form.populate(data) all_forms = (plan_form, case_form, run_form) rendered_errors = _render_errors(request, data, all_forms) if rendered_errors: return rendered_errors start = time.time() results = _query(plan_form.cleaned_data, run_form.cleaned_data, case_form.cleaned_data, target) results = order_targets(target, results, data) end = time.time() timecost = round(end - start, 3) queries = [] for form in all_forms: queries.append(form.cleaned_data) queries = fmt_queries(*queries) queries['Target'] = target return _render_results(request, results, timecost, queries)
def advance_search(request, tmpl='search/advanced_search.html'): """View of /advance-search/""" errors = None data = request.GET target = data.get('target') plan_form = PlanForm(data) case_form = CaseForm(data) run_form = RunForm(data) # Update MultipleModelChoiceField on each form dynamically plan_form.populate(data) case_form.populate(data) run_form.populate(data) all_forms = (plan_form, case_form, run_form) errors = [f.errors for f in all_forms if not f.is_valid()] if errors or not data: products = Product.objects.order_by('pk').only('pk', 'name') plan_types = TestPlanType.objects.order_by('name').only('pk', 'name') priorities = Priority.objects.filter(is_active=True).order_by('value') errors = fmt_errors(errors) return render(request, tmpl, context=locals()) start_time = time.time() results = query(request, plan_form.cleaned_data, run_form.cleaned_data, case_form.cleaned_data, target) results = order_targets(target, results, data) queries = fmt_queries(*[f.cleaned_data for f in all_forms]) queries['Target'] = target return render_results(request, results, start_time, queries)
def view_caseruns(request): """View that search caseruns.""" queries = request.GET r_form = RunForm(queries) r_form.populate(queries) context = {} if r_form.is_valid(): runs = SmartDjangoQuery(r_form.cleaned_data, TestRun.__name__).evaluate() case_runs = get_caseruns_of_runs(runs, queries) context['test_case_runs'] = case_runs context['runs'] = runs return render(request, 'report/caseruns.html', context)
def caseruns(request, templ='report/caseruns.html'): """View that search caseruns.""" queries = request.GET r_form = RunForm(queries) r_form.populate(queries) context = {} if r_form.is_valid(): runs = SmartDjangoQuery(r_form.cleaned_data, TestRun.__name__) runs = runs.evaluate() caseruns = get_caseruns_of_runs(runs, queries) context['test_case_runs'] = caseruns context['runs'] = runs response = direct_to_template(request, templ, context) return response
def advance_search(request): """View of /advance-search/""" data = request.GET target = data.get('target') plan_form = PlanForm(data) case_form = CaseForm(data) run_form = RunForm(data) # Update MultipleModelChoiceField on each form dynamically plan_form.populate(data) case_form.populate(data) run_form.populate(data) all_forms = (plan_form, case_form, run_form) errors = [] for form in all_forms: if form.is_valid(): errors.append(form.errors) if errors or not data: product_choice = [] for product in Product.objects.all(): product_choice.append((product.pk, product.name)) plan_type_choices = PlanType.objects.all() # pylint: disable=unused-variable errors = _fmt_errors(errors) priorities = Priority.objects.filter( # pylint: disable=unused-variable is_active=True).order_by('value') return render(request, 'search/advanced_search.html', locals()) start = time.time() results = _query(plan_form.cleaned_data, run_form.cleaned_data, case_form.cleaned_data, target) results = order_targets(target, results, data) end = time.time() timecost = round(end - start, 3) queries = [] for form in all_forms: queries.append(form.cleaned_data) queries = fmt_queries(*queries) queries['Target'] = target return _render_results(request, results, timecost, queries)
def view_test_run_report(request): templates = { 'per_build_report': 'report/caserun_report_per_build.html', 'per_tester_report': 'report/caserun_report_per_tester.html', 'per_priority_report': 'report/caserun_report_per_priority.html', 'per_plan_tag_report': 'report/testrun_report_per_plan_tag.html', 'per_plan_build_report': 'report/testrun_report_per_plan_build.html', 'runs_with_rates_per_plan_tag': 'report/testrun_report_by_plan_tag_with_rates.html', 'runs_with_rates_per_plan_build': 'report/testrun_report_by_plan_build_with_rates.html', } errors = None queries = request.GET data = {} report_type = queries.get('report_type') PRODUCT_CHOICE = [(p.pk, p.name) for p in cached_entities('product')] if queries: run_form = RunForm(queries) run_form.populate(queries) if run_form.is_valid(): queries = run_form.cleaned_data data = test_run_report(queries, report_type) else: errors = run_form.errors tmpl = templates.get(report_type, 'report/common/search_run.html') queries = fmt_queries(queries) request_path = remove_from_request_path(request, 'report_type') if request_path: path_without_build = remove_from_request_path(request_path, 'r_build') data.update(locals()) return render_to_response(tmpl, data, context_instance=RequestContext(request))
def advance_search(request, tmpl='search/advanced_search.html'): """View of /advance-search/""" errors = None data = request.GET target = data.get('target') plan_form = PlanForm(data) case_form = CaseForm(data) run_form = RunForm(data) # Update MultipleModelChoiceField on each form dynamically plan_form.populate(data) case_form.populate(data) run_form.populate(data) all_forms = (plan_form, case_form, run_form) errors = [f.errors for f in all_forms if not f.is_valid()] if errors or not data: products = Product.objects.order_by('pk').only('pk', 'name') plan_types = TestPlanType.objects.order_by('name').only('pk', 'name') priorities = Priority.objects.filter(is_active=True).order_by('value') errors = fmt_errors(errors) return render(request, tmpl, context=locals()) start_time = time.time() results = search_objects(request, plan_form.cleaned_data, run_form.cleaned_data, case_form.cleaned_data, target) results = order_targets(results, data) queries = fmt_queries(*[f.cleaned_data for f in all_forms]) queries['Target'] = target search_infos = { 'plan': SearchInfo(column_names=[ '', 'plan_id', 'name', 'author__username', 'owner__username', 'product', 'product_version', 'type', 'cases_count', 'runs_count', '' ], template_file='plan/common/json_plans.txt'), 'case': SearchInfo(column_names=[ '', '', 'case_id', 'summary', 'author__username', 'default_tester__username', '', 'case_status__name', 'category__name', 'priority__value', 'create_date' ], template_file='case/common/json_cases.txt'), 'run': SearchInfo(column_names=[ '', 'run_id', 'summary', 'manager__username', 'default_tester__username', 'build__product__name', 'product_version__value', 'env_groups', 'cases_count', 'stop_date', 'completed' ], template_file='run/common/json_runs.txt') } search_info = search_infos[target] dt = DataTableResult(request.GET, results, search_info.column_names, default_order_key='-pk') response_data = dt.get_response_data() if target == 'run': from tcms.testruns.views import calculate_associated_data calculate_associated_data(response_data['querySet']) if 'sEcho' in request.GET: resp_data = (get_template(search_info.template_file).render( response_data, request)) return JsonResponse(json.loads(resp_data)) else: end_time = time.time() time_cost = round(end_time - start_time, 3) return render( request, 'search/results.html', context={ 'search_target': target, 'time_cost': time_cost, 'queries': queries, # FIXME: choose another name rather than this_page 'object_list': response_data['querySet'], 'total_count': response_data['iTotalRecords'], })