def steps(self, conn=None): if not conn: conn = self.conn sql = "select * from %s where recipe_id = %s ORDER BY created_at" rows = conn.execute(sql % (Step.table_name(), self.id)) return [Step.load(conn, row) for row in rows]
def recipe_command(): """ Create a new recipe with steps. """ c = ado.commands.conn() created_at = datetime.now() print "Creating a new recipe." Portfolio.printall(c) portfolio_id = int(ado.commands.clean_input("Enter portfolio id: ")) # Verify portfolio choice. portfolio = Portfolio.get(c, portfolio_id) print "You chose portfolio %s - %s" % (portfolio.id, portfolio.name) name = ado.commands.clean_input("Enter short name for recipe: ") print "Name set to '%s'" % name description = ado.commands.clean_input("Description of recipe: ") print "Description set to '%s'" % description print "Describe each step in the recipe you wish to define." step = 0 steps = [] while True: step += 1 step_text = ado.commands.clean_input("Step %s: " % step) if step_text: steps.append(step_text) print "Processing step text '%s'" % step_text else: print "done! %s steps recorded." % len(steps) break print "How often should you do this recipe (e.g. 1w (1 week), 1d (1 day), 12h (12 hours), 30m (30 minutes)" raw_frequency = ado.commands.clean_input("> ") if raw_frequency: frequency = raw_frequency print "This recipe should be done every %s days" % frequency else: frequency = "None" print "No specified frequency." context = ado.commands.clean_input("Context (where you can do this): ") recipe = Recipe.create( c, context=context, created_at=created_at, description=description, frequency=frequency, name=name, portfolio_id=portfolio_id ) print "Created recipe", recipe.id for step_text in steps: step = Step.create( c, created_at=created_at, recipe_id = recipe.id, description = step_text ) print "Created step id %s" % step.id