def chart_form(request, bread_crumb_trail, instance=None, query_id=None): if request.method == 'POST': form = ChartForm(request.user, request.POST, instance=instance) if form.is_valid(): chart = form.save() if query_id: query = Query.objects.get(pk=query_id) chart_query = ChartQuery(chart=chart, query=query) chart_query.save() return HttpResponseRedirect(chart.get_absolute_url() + "/+detail") else: form = ChartForm(request.user, instance=instance) form.fields['owner'].initial = request.user template = loader.get_template('lava_results_app/chart_form.html') return HttpResponse( template.render( { 'bread_crumb_trail': bread_crumb_trail, 'form': form, }, request=request))
def chart_custom(request): content_type = Query.get_content_type(request.GET.get("entity")) chart_type = request.GET.get("type") chart_type_choices = ChartQuery._meta.get_field("chart_type").choices if not chart_type: chart_type = ChartQuery._meta.get_field("chart_type").default else: found = False for choice in chart_type_choices: if chart_type in choice: found = True if not found: raise InvalidChartTypeError( "Wrong chart type param. Please refer to chart docs." ) if content_type.model_class() not in QueryCondition.RELATION_MAP: raise InvalidContentTypeError( "Wrong table name in entity param. Please refer to chart docs." ) if content_type.model_class() == TestCase and chart_type == "pass/fail": raise TestCasePassFailChartError( "Chart of TestCase entity cannot be of pass/fail chart type." ) conditions = Query.parse_conditions(content_type, request.GET.get("conditions")) chart = Chart(name="Custom") chart_query = ChartQuery(id=0) chart_query.chart = chart chart_query.chart_type = chart_type chart_data = {} chart_data[0] = chart_query.get_data(request.user, content_type, conditions) template = loader.get_template("lava_results_app/chart_display.html") return HttpResponse( template.render( { "chart": chart, "chart_data": simplejson.dumps(chart_data), "bread_crumb_trail": BreadCrumbTrail.leading_to(chart_custom), "can_admin": False, }, request=request, ) )
def chart_custom(request): content_type = Query.get_content_type(request.GET.get("entity")) chart_type = request.GET.get("type") chart_type_choices = ChartQuery._meta.get_field_by_name( 'chart_type')[0].choices if not chart_type: chart_type = ChartQuery._meta.get_field_by_name( 'chart_type')[0].default else: found = False for choice in chart_type_choices: if chart_type in choice: found = True if not found: raise InvalidChartTypeError( "Wrong chart type param. Please refer to chart docs.") if content_type.model_class() not in QueryCondition.RELATION_MAP: raise InvalidContentTypeError( "Wrong table name in entity param. Please refer to chart docs.") if content_type.model_class() == TestCase and chart_type == "pass/fail": raise TestCasePassFailChartError( "Chart of TestCase entity cannot be of pass/fail chart type.") conditions = Query.parse_conditions( content_type, request.GET.get("conditions")) chart = Chart(name="Custom") chart_query = ChartQuery(id=0) chart_query.chart = chart chart_query.chart_type = chart_type chart_data = {} chart_data[0] = chart_query.get_data(request.user, content_type, conditions) template = loader.get_template('lava_results_app/chart_display.html') return HttpResponse(template.render( { 'chart': chart, 'chart_data': simplejson.dumps(chart_data), 'bread_crumb_trail': BreadCrumbTrail.leading_to( chart_custom), 'can_admin': False, }, request=request) )
def chart_form(request, bread_crumb_trail, instance=None, query_id=None): if request.method == 'POST': form = ChartForm(request.user, request.POST, instance=instance) if form.is_valid(): chart = form.save() if query_id: query = Query.objects.get(pk=query_id) chart_query = ChartQuery(chart=chart, query=query) chart_query.save() return HttpResponseRedirect(chart.get_absolute_url() + "/+detail") else: form = ChartForm(request.user, instance=instance) form.fields['owner'].initial = request.user template = loader.get_template('lava_results_app/chart_form.html') return HttpResponse(template.render( { 'bread_crumb_trail': bread_crumb_trail, 'form': form, }, request=request))