Exemplo n.º 1
0
def export_to_file(request, qmodel=None):
    if (request.method == "GET") and (not qmodel):
        return shortcuts.redirect("prosoul:editor")

    if request.method == "POST":
        qmodel_id = request.POST["id"]
        qmodel = QualityModel.objects.get(id=qmodel_id)

    file_name = "qmodel_%s.json" % qmodel
    task_init = time()
    try:
        models_json = fetch_models(qmodel)
    except (QualityModel.DoesNotExist, Exception) as ex:
        print(ex)
        error_msg = "Goals from qmodel \"%s\" couldn't be exported." % qmodel
        if request.method == "POST":
            # If request comes from web UI and fails, return error page
            return return_error(error_msg)
        else:
            # If request comes as a GET request, return HTTP 404: Not Found
            return HttpResponse(status=404)

    print("Total loading time ... %.2f sec", time() - task_init)
    if models_json:
        models = json.dumps(models_json, indent=True, sort_keys=True)
        response = HttpResponse(models, content_type="application/json")
        response['Content-Disposition'] = 'attachment; filename=' + file_name
        return response
    else:
        error_msg = "There are no goals to export"
        return return_error(error_msg)
Exemplo n.º 2
0
    def get(self, request):
        """ Basic Models Viewer just dumping the JSON of all models """
        models = fetch_models()
        if not models['qualityModels']:
            return shortcuts.redirect('prosoul:editor')
        model_selected = models['qualityModels'][0]['name']
        if request.method == 'GET' and 'qmodel_selected' in request.GET:
            model_selected = request.GET['qmodel_selected']
        viewer_data = gl2viewer(models, model_name=model_selected)
        context = {
            'active_page': "viewer",
            'qmodel_selected': model_selected,
            'qmodels': models['qualityModels'],
            'qm_data': viewer_data[0],
            'qm_data_str': json.dumps(viewer_data[0]).replace('\"', '\\"'),
            'attributes_data': viewer_data[1],
            'attributes_data_str':
            json.dumps(viewer_data[1]).replace('\"', '\\"'),
            'metrics_data': viewer_data[2],
            'metrics_data_str':
            json.dumps(viewer_data[2]).replace('\"', '\\"')
        }

        template = loader.get_template('prosoul/viewer.html')

        render_index = template.render(context, request)

        return HttpResponse(render_index)
Exemplo n.º 3
0
def compare_models(models_json, format_=None):
    # The Prosoul database must only contains the models imported
    exported_models_json = fetch_models()
    if format_ == 'ossmeter':
        exported_models_json = gl2ossmeter(exported_models_json)
    elif format_ == 'alambic':
        exported_models_json = gl2alambic(exported_models_json)
    test = TestCase()
    test.maxDiff = None
    test.assertDictEqual(models_json, exported_models_json)
    logging.info("Check completed")