コード例 #1
0
    def form_valid(self, form):
        name = form.cleaned_data['name']
        xml = form.cleaned_data['xml']
        model_version = form.cleaned_data['model_version']
        desc = form.cleaned_data['desc'] if form.cleaned_data['desc'] != '' else None

        scenario = Scenario(xml=xml, user=self.request.user, description=desc)
        if name:
            scenario.name = name
        scenario.save()
        simulation = submit(self.request.user.username, xml, model_version)
        scenario.simulation = simulation
        scenario.save()

        return super(StandaloneSubmitView, self).form_valid(form)
コード例 #2
0
ファイル: ScenarioView.py プロジェクト: vecnet/vnetsource
def submit_scenarios(request):
    scenarios_data = {"ok": False, "scenarios": []}

    if not request.user.is_authenticated() or not "scenario_ids" in request.POST:
        return HttpResponse(json.dumps(scenarios_data), content_type="application/json")

    scenario_ids = json.loads(request.POST["scenario_ids"])

    if scenario_ids is None or len(scenario_ids) <= 0:
        return HttpResponse(json.dumps(scenarios_data), content_type="application/json")

    for scenario_id in scenario_ids:
        scenarios_data["scenarios"].append({"id": scenario_id, "ok": False})

        scenario = Scenario.objects.get(user=request.user, id=int(scenario_id))

        if not scenario or scenario.simulation is not None:
            continue

        json_str = rest_validate(scenario.xml)
        validation_result = json.loads(json_str)

        valid = True if (validation_result['result'] == 0) else False

        if not valid:
            continue

        simulation = submit(request.user.username, scenario.xml)

        if simulation:
            scenario.simulation = simulation
            scenario.save()
            scenarios_data["scenarios"][-1]["ok"] = True

    scenarios_data["ok"] = True

    return HttpResponse(json.dumps(scenarios_data), content_type="application/json")