コード例 #1
0
ファイル: main.py プロジェクト: mrthomasjackson/DPW
 def get(self):
     # create instance of the view
     p = Page()
     # create instance of the converter class
     u = MetricUnitConverter()
     # create instance of the data library class
     data = DataHolder()
     # if/ else statement to determine which view to throw
     if self.request.GET:
         # form inputs are stores in the data library
         data.name = self.request.GET['name']
         data.feet = self.request.GET['feet']
         data.inches = self.request.GET['inches']
         data.pounds = self.request.GET['weight']
         # calculations are returned to the data library
         data.meters = u.height_converter(data.feet, data.inches)
         data.kilograms = u.weight_converter(data.pounds)
         # english BMI requires height to be in inches only
         data.total_inches = u.inches_only(data.feet, data.inches)
         p.english_bmi = u.english_bmi_calculator(data.pounds, data.total_inches)
         p.metric_bmi = u.metric_bmi_calculator(data.kilograms, data.meters)
         # name is stored in the data library as well
         p.name = data.name
         # Custom message is injected into the h1 tag
         p.message = "Thanks for filling out our form!"
         # generate the results view
         self.response.write(p.write_answer())
     # else statement to hold the form view (1st view)
     else:
         # generate the form view (1st view)
         self.response.write(p.write_form())
コード例 #2
0
ファイル: main.py プロジェクト: ericgrogers/DPW
    def get(self):
        #create a shortcut to the Page() class
        p = Page()

        #if the GET method is invoked, grab the form values and set them to the proper keys
        if self.request.GET:

            #create a shortcut for self.request
            sr = self.request

            #set the page title.
            p.title = "Eric Rogers | Thank You!"

            #set the Page().name attribute to the input value submitted.
            p.name = sr.GET['name']

            #set the Page().telephone attribute to the input value submitted.
            p.telephone = sr.GET['telephone']

            #set the Page().email attribute to the input value submitted.
            p.email = sr.GET['email']

            #set the Page().interest attribute to the input value submitted.
            p.interest = sr.GET['interest']

            #set the Page().return_customer attribute to reflect the user's choice when checked.
            p.return_customer = 'Yes, please give me a 10% discount.'

            #try to grab the Page().return_customer checkbox value
            try:
                sr.GET['return_customer']

            #if there is no value, the server throws a KeyError meaning the box is not checked.
            except KeyError:

                #set the Page().return_customer attribute to reflect the user's choice when not checked.
                p.return_customer = 'No, I am a new customer.'

            #output Page().view2 to the page.
            self.response.write(p.view2())

        #otherwise, output Page().view1 to the page.
        else:
            self.response.write(p.view1())