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, 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 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 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'], })