def model_form(request, model_id): model = get_object_or_404(Model, application__project__owner=request.user, pk=model_id) context = {} if request.method == 'POST': model_form = ModelForm(request.POST, instance=model, prefix="model_%d_" % model.id) if model_form.is_valid(): model = model_form.save() context['saved'] = True model_form = ModelForm(instance=model, prefix="model_%d_" % model.id) context.update({'model_form': model_form, 'model': model}) return render_response(request, 'model_form.html', context) raise Http404
def model_page(request): if request.method == "GET": full_model = True try: if request.GET['country'] != 'NAC': full_model = False except: pass if full_model: #Run Model form = ModelForm(request.GET) if form.is_valid(): strategy = '' cd = form.cleaned_data id, tmp_p = tempfile.mkstemp(suffix='.json',prefix='xpert', dir=settings.MEDIA_ROOT) if cd['type_select'] == '0': #if Single Stategy is clicked strategy = cd['int_select']; #run the selected strategy else: #'All' is clicked; run all strats. strategy = '9'; params = {} params['int_select'] = int(strategy) params['target_inc'] = cd['t_inc'] params['target_mdr'] = cd['t_mdr'] params['target_hiv'] = cd['t_hiv'] params['drug1_cost'] = cd['t_drug1_cost'] params['drug2_cost'] = cd['t_drug2_cost'] params['drug3_cost'] = cd['t_drug3_cost'] params['outpt_cost'] = cd['t_outpt_cost'] params['sm_cost'] = cd['t_sm_cost'] params['gxp_cost'] = cd['t_gxp_cost'] params['sdgxp_cost'] = cd['t_sdgxp_cost'] params['homebrew'] = False with open(tmp_p,'w') as fp: json.dump(params, fp) params['filename'] = tmp_p s = "echo %s/async/xpert_bg_inter.py " % (path_to_xpert_su) s += "%s | at now" % (tmp_p) os.system(s) return render(request, "model.html", {'web_path':"{}{}".format(settings.MEDIA_URL,tmp_p.split("/")[-1]), 'int_select':params['int_select']}) else: return render(request, "preset.html", {}) return render(request,"bad.html", { 'type':'model' })
def addmodel(): if not session.get("logged_in"): return redirect(url_for("login")) add_model = ModelForm() submit = SubmitForm() if submit.validate_on_submit(): add = Model(model_name=add_model.model_name.data) db.session.add(add) db.session.commit() return redirect(url_for("model")) return render_template("addmodel.html", add_model=add_model, submit=submit)
def editmodel(model_id): if not session.get("logged_in"): return redirect(url_for("login")) model_one = Model.query.filter_by(model_id=model_id).first() edit_model = ModelForm() submit = SubmitForm() if submit.validate_on_submit(): model_one.model_name = edit_model.model_name.data db.session.commit() return redirect(url_for("model")) edit_model.model_name.data = model_one.model_name return render_template("editmodel.html", edit_model=edit_model, submit=submit)
def model_page(request): if request.method == "GET": form = ModelForm(request.GET) if form.is_valid(): strategy = '' cd = form.cleaned_data id, tmp_p = tempfile.mkstemp(suffix='.json', prefix='flexdx', dir=settings.MEDIA_ROOT) if cd['type_select'] == '0': #if Single Stategy is clicked strategy = cd['int_select'] #run the selected strategy else: #'All' is clicked; run all strats. strategy = '9' s = "echo " #insert the path to the flexbg.py file s += "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %s %s | at now" sys_str = s % ( cd['t_inc'], cd['t_hiv'], cd['t_mdr'], cd['t_drug1_cost'], cd['t_sm_cost'], cd['t_gxp_cost'], cd['t_cx_cost'], cd['t_mods_cost'], cd['t_dst_cost'] - cd['t_cx_cost'], cd['t_sd_cost'] - cd['t_sm_cost'], cd['t_sdgxp_cost'] - cd['t_gxp_cost'], cd['t_drug2_cost'], cd['t_drug3_cost'], cd['t_outpt_cost'], strategy, tmp_p) os.system(sys_str) d = {} if strategy == '9': d['run_all'] = True d['web_path'] = "{}{}".format(settings.MEDIA_URL, tmp_p.split("/")[-1]) d['tb_inc'] = '{:,.0f}'.format(cd['t_inc']) d['hiv_inc'] = '%.2f' % cd['t_hiv'] d['mdr_inc'] = '%.1f' % cd['t_mdr'] d['drg_cst'] = '{:,.2f}'.format(cd['t_drug1_cost']) #new costs JP (2013/08/05) d['drg2_cst'] = '{:,.2f}'.format(cd['t_drug2_cost']) d['drg3_cst'] = '{:,.2f}'.format(cd['t_drug3_cost']) d['opt_cst'] = '{:,.2f}'.format(cd['t_outpt_cost']) d['sm_cst'] = '{:,.2f}'.format(cd['t_sm_cost']) d['sd_cst'] = '{:,.2f}'.format(cd['t_sd_cost']) d['gxp_cst'] = '{:,.2f}'.format(cd['t_gxp_cost']) d['sdgxp_cst'] = '{:,.2f}'.format(cd['t_sdgxp_cost']) d['cx_cst'] = '{:,.2f}'.format(cd['t_cx_cost']) d['dst_cst'] = '{:,.2f}'.format(cd['t_dst_cost']) d['mods_cst'] = '{:,.2f}'.format(cd['t_mods_cost']) return render(request, "model.html", d) return render(request, "bad.html", {'type': 'model'})
def index(): # automatically loads models from MODEL_DIRECTORY model_form = ModelForm() images = get_images(IMAGE_DIRECTORY + "imagenet/") images_data = [] # json object for the images: uses the filename as key and contains the class code and base 64 encoding for image in images: images_data.append({ "file_name": image[0].rsplit(".", 1)[0], "class_code": image[1], "class_name": image[2], "b64data": image[3] }) model_form.model.choices = tuple_list_from_dict( get_models(MODEL_DIRECTORY)) return render_template('index.html', model_form=model_form, images_data=images_data)
def models_create(): form = ModelForm() if form.validate_on_submit(): return 'Yay!' else: return render_template('models/new.html', form=form)
def models_new(): form = ModelForm() return render_template('models/new.html', form=form)
def home_page(request): form = ModelForm() return render(request,"index.html", {'form':form})