def MainPhaseOne(request): #checks database entry 1, returns a 404 error if this entry does not exhist. valuesSPF = get_object_or_404(SPFValuePhaseOne, pk=1) valuesSAA = get_object_or_404(SAAValuePhaseOne, pk=1) valuesSurvey = get_object_or_404(SurveyValue, pk=1) if request.method == 'POST': form1 = SPFformPhaseOne(request.POST) form2 = SAAformPhaseOne(request.POST) form3 = Surveyform(request.POST) #goes through each section of the form and checks for a valid entry, saving the values if all validation requirments (at this point just type) are met. if form1.is_valid(): valuesSPF.SPFSizePhaseOne = form1.cleaned_data['SPFSizePhaseOne'] valuesSPF.SPFbeamPhaseOne = form1.cleaned_data['SPFbeamPhaseOne'] valuesSPF.SPFATPhaseOne = form1.cleaned_data['SPFATPhaseOne'] valuesSPF.SPFefficiencyPhaseOne = form1.cleaned_data['SPFefficiencyPhaseOne'] valuesSPF.SPFnyquistPhaseOne = form1.cleaned_data['SPFnyquistPhaseOne'] valuesSPF.SPFseperationPhaseOne = form1.cleaned_data['SPFseperationPhaseOne'] valuesSPF.SPFminfreqPhaseOne = form1.cleaned_data['SPFminfreqPhaseOne'] valuesSPF.SPFmaxfreqPhaseOne = form1.cleaned_data['SPFmaxfreqPhaseOne'] valuesSPF.save() if form2.is_valid(): valuesSAA.SAASizePhaseOne = form2.cleaned_data['SAASizePhaseOne'] valuesSAA.SAAbeamPhaseOne = form2.cleaned_data['SAAbeamPhaseOne'] valuesSAA.SAAATPhaseOne = form2.cleaned_data['SAAATPhaseOne'] valuesSAA.SAAefficiencyPhaseOne = form2.cleaned_data['SAAefficiencyPhaseOne'] valuesSAA.SAAnyquistPhaseOne = form2.cleaned_data['SAAnyquistPhaseOne'] valuesSAA.SAAseperationPhaseOne = form2.cleaned_data['SAAseperationPhaseOne'] valuesSAA.SAAminfreqPhaseOne = form2.cleaned_data['SAAminfreqPhaseOne'] valuesSAA.SAAmaxfreqPhaseOne = form2.cleaned_data['SAAmaxfreqPhaseOne'] valuesSAA.save() if form3.is_valid(): valuesSurvey.FoV = form3.cleaned_data['FoV'] valuesSurvey.TotalTime = form3.cleaned_data['TotalTime'] valuesSurvey.Hubble = form3.cleaned_data['Hubble'] valuesSurvey.OmegaM = form3.cleaned_data['OmegaM'] valuesSurvey.OmegaV = form3.cleaned_data['OmegaV'] valuesSurvey.BeamWidth = form3.cleaned_data['BeamWidth'] valuesSurvey.sigma = form3.cleaned_data['sigma'] valuesSurvey.save() context = Context({'title': 'SKA calculator Phase 1', 'form1': form1, 'form2': form2, 'form3': form3}) return plotPhaseOne(request) else: form1 = SPFformPhaseOne() form2 = SAAformPhaseOne() form3 = Surveyform() context = Context({'title': 'SKA calculator Phase 1', 'form1': form1, 'form2': form2, 'form3': form3}) return render_to_response('calc/MainPhaseOne.html', context)
def addDatabaseEntry(request): if request.method == 'POST': form1 = SPFform(request.POST) form2 = PAFform(request.POST) form3 = SAAform(request.POST) form4 = DAAform(request.POST) form5 = Surveyform(request.POST) form6 = SPFformPhaseOne(request.POST) form7 = SAAformPhaseOne(request.POST) if form1.is_valid(): # create a new item valuesSPF = SPFValue.objects.create( SPFSize = form1.cleaned_data['SPFSize'], SPFbeam = form1.cleaned_data['SPFbeam'], SPFAT = form1.cleaned_data['SPFAT'], SPFefficiency = form1.cleaned_data['SPFefficiency'], SPFnyquist = form1.cleaned_data['SPFnyquist'], SPFseperation = form1.cleaned_data['SPFseperation'], SPFminfreq = form1.cleaned_data['SPFminfreq'], SPFmaxfreq = form1.cleaned_data['SPFmaxfreq'], ) if form2.is_valid(): # create a new item valuesPAF = PAFValue.objects.create( PAFSize = form2.cleaned_data['PAFSize'], PAFbeam = form2.cleaned_data['PAFbeam'], PAFAT = form2.cleaned_data['PAFAT'], PAFefficiency = form2.cleaned_data['PAFefficiency'], PAFnyquist = form2.cleaned_data['PAFnyquist'], PAFseperation = form2.cleaned_data['PAFseperation'], PAFminfreq = form2.cleaned_data['PAFminfreq'], PAFmaxfreq = form2.cleaned_data['PAFmaxfreq'], ) if form3.is_valid(): # create a new item valuesSAA = SAAValue.objects.create( SAASize = form3.cleaned_data['SAASize'], SAAbeam = form3.cleaned_data['SAAbeam'], SAAAT = form3.cleaned_data['SAAAT'], SAAefficiency = form3.cleaned_data['SAAefficiency'], SAAnyquist = form3.cleaned_data['SAAnyquist'], SAAseperation = form3.cleaned_data['SAAseperation'], SAAminfreq = form3.cleaned_data['SAAminfreq'], SAAmaxfreq = form3.cleaned_data['SAAmaxfreq'], ) if form4.is_valid(): # create a new item valuesDAA = DAAValue.objects.create( DAASize = form4.cleaned_data['DAASize'], DAAbeam = form4.cleaned_data['DAAbeam'], DAAAT = form4.cleaned_data['DAAAT'], DAAefficiency = form4.cleaned_data['DAAefficiency'], DAAnyquist = form4.cleaned_data['DAAnyquist'], DAAseperation = form4.cleaned_data['DAAseperation'], DAAminfreq = form4.cleaned_data['DAAminfreq'], DAAmaxfreq = form4.cleaned_data['DAAmaxfreq'], ) if form5.is_valid(): # create a new item valuesSurvey = SurveyValue.objects.create( FoV = form5.cleaned_data['FoV'], TotalTime = form5.cleaned_data['TotalTime'], Hubble = form5.cleaned_data['Hubble'], OmegaM = form5.cleaned_data['OmegaM'], OmegaV = form5.cleaned_data['OmegaV'], BeamWidth = form5.cleaned_data['BeamWidth'], sigma = form5.cleaned_data['sigma'], ) if form6.is_valid(): # create a new item valuesSPFPhaseOne = SPFValuePhaseOne.objects.create( SPFSizePhaseOne = form6.cleaned_data['SPFSizePhaseOne'], SPFbeamPhaseOne = form6.cleaned_data['SPFbeamPhaseOne'], SPFATPhaseOne = form6.cleaned_data['SPFATPhaseOne'], SPFefficiencyPhaseOne = form6.cleaned_data['SPFefficiencyPhaseOne'], SPFnyquistPhaseOne = form6.cleaned_data['SPFnyquistPhaseOne'], SPFseperationPhaseOne = form6.cleaned_data['SPFseperationPhaseOne'], SPFminfreqPhaseOne = form6.cleaned_data['SPFminfreqPhaseOne'], SPFmaxfreqPhaseOne = form6.cleaned_data['SPFmaxfreqPhaseOne'], ) if form7.is_valid(): # create a new item valuesSAAPhaseOne = SAAValuePhaseOne.objects.create( SAASizePhaseOne = form7.cleaned_data['SAASizePhaseOne'], SAAbeamPhaseOne = form7.cleaned_data['SAAbeamPhaseOne'], SAAATPhaseOne = form7.cleaned_data['SAAATPhaseOne'], SAAefficiencyPhaseOne = form7.cleaned_data['SAAefficiencyPhaseOne'], SAAnyquistPhaseOne = form7.cleaned_data['SAAnyquistPhaseOne'], SAAseperationPhaseOne = form7.cleaned_data['SAAseperationPhaseOne'], SAAminfreqPhaseOne = form7.cleaned_data['SAAminfreqPhaseOne'], SAAmaxfreqPhaseOne = form7.cleaned_data['SAAmaxfreqPhaseOne'], ) context = Context({'title': 'Add New Defualt Database Entry', 'form1': form1, 'form2': form2, 'form3': form3, 'form4': form4, 'form5':form5, 'form6':form6, 'form7':form7}) return render_to_response('calc/addto.html', context) else: # This the the first page load, display a blank form form1 = SPFform() form2 = PAFform() form3 = SAAform() form4 = DAAform() form5 = Surveyform() form6 = SPFformPhaseOne() form7 = SAAformPhaseOne() context = Context({'title': 'Add New Defualt Database Entry', 'form1': form1, 'form2': form2, 'form3': form3, 'form4': form4, 'form5':form5, 'form6':form6, 'form7':form7}) return render_to_response('calc/addto.html', context)