def getPromptsToShow(self,screen): p = Prompt.all() p.filter("screen =",screen) p = p.fetch(1000) prompts = [prompt for prompt in p if prompt.shouldShowPrompt(self.getSetFlagNames())] return prompts
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)
from era_db import Screen, Prompt, Option, eraDB # You *must* call prepareReconfig() before defining the workflow eraDB.prepareReconfig() s1 = Screen.new() p1 = Prompt.new() p1.setText("Please enter the name of the paper being reviewed.") p1.setType("input") s1.addPrompt(p1) p2 = Prompt.new() p2.setText("Please enter the author's name.") p2.setType("input") s1.addPrompt(p2) p3 = Prompt.new() p3.setText("Please enter your name.") p3.setType("input") s1.addPrompt(p3) p4 = Prompt.new() p4.setText("Claims") p4.setType("textarea") s1.addPrompt(p4) p5 = Prompt.new() p5.setText("Summary") p5.setType("textarea") s1.addPrompt(p5)