コード例 #1
0
ファイル: main.py プロジェクト: psawaya/ERA
    def post(self,reviewID,nthScreen):        
        review = Review.get_by_id(int(reviewID))
        
        # First, unset all option flags for the prompt, and then
        # reset them as needed as we look at the options.

        # Only call review.put() at the end, so we only write
        # the flags to the DB once.
        
        # Look for the prompts in the POST args, their arg name is just the prompt.key().id()
        for promptID in self.request.arguments.get('prompts[]'):
            prompt = Prompt.get_by_id(int(promptID))
            review.unsetFlagsByPrompt(prompt)
            
            # If a promptID isn't present in POST args, its options must be.
            
            if promptID in self.request.arguments:
                # Look for an entity in the DB with the keyName promptID_reviewID.
                # Or, create one if it doesn't already exist

                response = PromptResponse.get_or_insert("%s_%s" % (promptID,reviewID))
                response.review = review
                response.assignValue(self.request.arguments[promptID][0],prompt)

        for optionID in self.request.arguments.get('options[]') or []:
            # Each option value is a form element named 'option+<option ID>'
            optionValue = self.request.arguments.get("option" + optionID) == ['on']
            
            option = Option.get_by_id(int(optionID))
            response = PromptResponse.get_or_insert("%s_%s" % (option.key().id(),reviewID))
            response.review = review
            response.assignValue(optionValue,None,option)
            
            for flag in option.flagsSet:
                review.setFlagForPromptOption(option,flag)

        review.put()

        return self.renderOrRedirectNextScreen(review,long(nthScreen)+1)