def write_to_db(person_name_input, favorite_color_input, favorite_animal_input): # Writes data to database. Returns message passed from database. try: with db.transaction(): ''' Attempt to add the vote. If person_name is taken, the database will raise an IntegrityError ''' Person.create(person_name=person_name_input, favorite_color=favorite_color_input, favorite_animal=favorite_animal_input) return "Thank you for voting!" except db_exceptions['IntegrityError']: return "You have already voted!" except Exception as e: app.logger.error('Exception in write_to_db: {}'.format(str(e))) return "Please try again later."