Exemple #1
0
def create_new_poll():
  errors=["An error occurred while creating a poll."]
  form = PollForm()
  form['csrf_token'].data = request.cookies['csrf_token']

  if form.validate_on_submit():
    new_poll = Poll(title=form.data['title'], question_text=form.data["question_text"], user_id=current_user.get_id())
    db.session.add(new_poll)
    db.session.commit()
    return { new_poll.get_id(): new_poll.to_dict() }

  return { "errors": errors }
Exemple #2
0
def createPoll(Poll):
    if Poll == None:
        print('Poll object is empty')
        return False
    else:
        if Poll.validate():
            try:
                db.session.add(Poll)
                db.session.commit()
                for index in range(Poll.howManyCandidates()):
                    Poll.Candidate[index].pollId = Poll.get_id()
                    try:
                        db.session.add(Poll.Candidate[index])
                        db.session.commit()
                    except:
                        return 'create candidate exception raised: ' + str(
                            sys.exc_info()[0])
                return True
            except:
                return 'createPoll exception raised: ' + str(sys.exc_info()[0])
        else:
            print('Mandatory data for a poll missing')
            return False