def add_sequencelisting(request): if request.method == 'POST': form = SequenceListingForm(request.POST) title_form = TitleForm(request.POST) if form.is_valid() and title_form.is_valid(): filingDateFromForm = request.POST.get('filingDate') # set to None bc the model does not handle properly empty string from form fd = filingDateFromForm if filingDateFromForm else None sl_instance = SequenceListing.objects.create( fileName=request.POST.get('fileName'), dtdVersion='1', softwareName='prototype', softwareVersion='0.1', productionDate=timezone.now( ), #should be overwritten upon xml export applicantFileReference=request.POST.get( 'applicantFileReference'), IPOfficeCode=request.POST.get('IPOfficeCode'), applicationNumberText=request.POST.get( 'applicationNumberText'), # filingDate = request.POST.get('filingDate'), filingDate=fd, earliestPriorityIPOfficeCode=request.POST.get( 'earliestPriorityIPOfficeCode'), earliestPriorityApplicationNumberText=request.POST.get( 'earliestPriorityApplicationNumberText'), earliestPriorityFilingDate=request.POST.get( 'earliestPriorityFilingDate'), applicantName=request.POST.get('applicantName'), applicantNameLanguageCode=request.POST.get( 'applicantNameLanguageCode'), applicantNameLatin=request.POST.get('applicantNameLatin'), inventorName=request.POST.get('inventorName'), inventorNameLanguageCode=request.POST.get( 'inventorNameLanguageCode'), inventorNameLatin=request.POST.get('inventorNameLatin'), ) sl_instance.save() tcd = title_form.cleaned_data title_instance = Title( sequenceListing=sl_instance, inventionTitle=tcd['inventionTitle'], inventionTitleLanguageCode=tcd['inventionTitleLanguageCode']) title_instance.save() return HttpResponseRedirect( reverse('sequencelistings:edit_seql', args=(sl_instance.pk, ))) else: form = SequenceListingForm() title_form = TitleForm() return render(request, 'sequencelistings/add_sequencelisting.html', { 'form': form, 'title_form': title_form })
def custom_form_view(request): if request.method == 'POST': form = TitleForm(request.POST) if form.is_valid(): # form.save() return redirect('/forms') else: form = TitleForm() time.sleep(2) return render(request, 'forms/form.html', {'form': form.as_p(), 'action': '/forms/custom'})
def add_title(): """ Add a title to the database """ check_admin() add_title = True form = TitleForm() if form.validate_on_submit(): title = Title(name=form.name.data) try: # add title to the database db.session.add(title) db.session.commit() flash('You have successfully added a new title.') except: # in case title name already exists flash('Error: title name already exists.') # redirect to titles page return redirect(url_for('admin.list_titles')) # load title template return render_template('admin/titles/title.html', action="Add", add_title=add_title, form=form, title="Add Title")
def edit_title(id): """ Edit a title """ check_admin() add_title = False title = Title.query.get_or_404(id) form = TitleForm(obj=title) if form.validate_on_submit(): title.name = form.name.data db.session.commit() flash('You have successfully edited the title.') # redirect to the titles page return redirect(url_for('admin.list_titles')) form.name.data = title.name return render_template('admin/titles/title.html', action="Edit", add_title=add_title, form=form, title_edit=title, title="Edit Title")
def add_title(request, pk): if request.method == 'POST': form = TitleForm(request.POST) if form.is_valid(): sl = SequenceListing.objects.get(pk=pk) cd = form.cleaned_data title_instance = Title( sequenceListing=sl, inventionTitle=cd['inventionTitle'].encode('utf-8'), inventionTitleLanguageCode=cd['inventionTitleLanguageCode']) title_instance.save() return HttpResponseRedirect( reverse('sequencelistings:edit_seql', args=(pk, ))) else: form = TitleForm() return render(request, 'sequencelistings/add_title.html', { 'form': form, 'pk': pk })
def model_parameters(request): errormsg = "" if request.method == 'POST': titleform = TitleForm(request.POST) outvarform = OutputVarForm(request.POST) resform = ResultsForm(request.POST) tstepform = TimeStep(request.POST) outstepform = OutStep(request.POST) durform = Duration(request.POST) initcondform = InitConds(request.POST) initcondvalform = InitValue(request.POST) tidalflatsform = TidalFlats(request.POST) opttidalflatsform = OptTidalFlats(request.POST) optliqbndryform = OptLiquidBndry(request.POST) tidaldbform = TidalDatabase(request.POST) autotuneform = AutoTune(request.POST) autotuneoptsform = AutoTuneOpts(request.POST, request.FILES) bottomfric = BottomFric(request.POST) mobilealert = MobileAlert(request.POST) if tstepform.is_valid() and outvarform.is_valid( ) and outstepform.is_valid() and durform.is_valid( ) and initcondform.is_valid() and optliqbndryform.is_valid(): postitems = {} #autotuneoptsform.save() mytitle = request.POST['title'] outvars = request.POST.getlist('outputvar') for key, value in request.POST.items(): print(key, value) postitems[key] = value postitems['meshfile'] = request.session.get('meshfile', None) postitems['bcfile'] = request.session.get('bcfile', None) postitems['outputvar'] = outvars mycasfile = CASFILE(postitems) mycasfile.writeCasfile() if 'autocalib' in postitems: if postitems['autocalib'] == "1": if autotuneoptsform.is_valid(): autotuneoptsform.save() content = request.FILES['obsfldr'] cwd = os.getcwd() dirname = cwd + "\\documents\\" zippath = dirname + str(content) zipobj = zipfile.ZipFile(zippath) zipobj.extractall(dirname) zipobj.close() os.remove(zippath) else: errormsg = "Please fill in all the fields." else: titleform = TitleForm() outvarform = OutputVarForm() resform = ResultsForm() tstepform = TimeStep() outstepform = OutStep() durform = Duration() initcondform = InitConds() initcondvalform = InitValue() tidalflatsform = TidalFlats({'tidalflats': 'YES'}) opttidalflatsform = OptTidalFlats({ 'opttidalflats': '1', 'optnegdepths': '1' }) optliqbndryform = OptLiquidBndry() tidaldbform = TidalDatabase() autotuneform = AutoTune() autotuneoptsform = AutoTuneOpts() bottomfric = BottomFric() mobilealert = MobileAlert() geodata = request.session.get('my_data', None) meshcentre = request.session.get('centre', None) bndrysgeojson = request.session.get('bndrysgeojson') northbndry = json.dumps(bndrysgeojson['northbndry']) southbndry = json.dumps(bndrysgeojson['southbndry']) return render(request, 'runtide/modelforms.html', locals())