예제 #1
0
파일: __init__.py 프로젝트: xuorig/INF5190
    def poll(poll_id):
        poll = Poll.get_poll_by_id(poll_id)
        if not poll:
            return abort(404)

        choices = Choice.get_choices_for_poll(poll)
        return views.view_poll(poll, choices)
예제 #2
0
    def choice_create(poll_id):
        poll = Poll.get_poll_by_id(poll_id)
        if not poll:
            return abort(404)

        choice = PollServices.create_new_choice_for_poll_from_post_data(
            poll, request.form)
        return redirect(url_for('poll', poll_id=poll.id))
예제 #3
0
    def poll(poll_id):
        poll = Poll.get_poll_by_id(poll_id)
        if not poll:
            return abort(404)

        choices = Choice.get_choices_for_poll(poll)
        #csrf_token = generate_csrf()
        return views.view_poll(poll, choices, csrf_token=None)
예제 #4
0
    def test_get_poll_by_id(self, app):
        with app.app_context():
            now = datetime.now()
            p = Poll(id=None, name="Nom", date=now)
            p.save()

            new_poll = Poll.get_poll_by_id(1)
            assert new_poll.id == 1
            assert new_poll.name == "Nom"
            assert new_poll.date == str(now)
예제 #5
0
    def poll_vote(poll_id):
        poll = Poll.get_poll_by_id(poll_id)
        if not poll:
            return abort(404)

        choice_id = request.form['choice_id']
        choice = Choice.get_by_id_for_poll(poll, choice_id)
        if not choice:
            return abort(404)

        choice.cast_vote()

        return redirect(url_for('poll', poll_id=poll.id))