コード例 #1
0
ファイル: routes.py プロジェクト: Dragonite/fishing
def create():
    form = CreatePollForm()
    if form.validate_on_submit():
        validationPoll=Poll.query.filter_by(title=form.title.data).first()
        if validationPoll!= None:
            flash(Markup('<script>Notify("There is already a poll created with the same title.", null, null, "danger")</script>'))
            return redirect(url_for('main.create'))

        else:
            poll=Poll(title=form.title.data, description=form.description.data,  minResponses=0, orderCandidatesBy=None, isOpenPoll=form.isOpen.data, openAt=None, closeAt=None, User=current_user)
            candidates=form.options
            nullCount=len(form.options)

            for item in candidates:
                if item.data != None and item.data != "":
                    poll.addCandidate(item.data, None)
                    nullCount-=1
            if nullCount > (len(form.options)-2):
                flash(Markup('<script>Notify("There is not enough choices to make this poll.", null, null, "danger")</script>'))
                return redirect(url_for('main.create'))
            else:
                if createPoll(poll)==True:
                    flash(Markup('<script>Notify("Poll has been created successfully!", null, null, "success")</script>'))
                    return redirect(url_for('main.current')+'/'+ str(poll.pollId))

                else:
                    flash(Markup('<script>Notify("Something is wrong!", null, null, "danger")</script>'))
                    return redirect(url_for('main.create'))
    return render_template('create.html', title='Create a Poll', form=form)
コード例 #2
0
ファイル: tests.py プロジェクト: Dragonite/fishing
    def test_createPoll(self):
        title='test_createPoll- where is your third favorite fishing spot?'
        description='test_createPoll- survey to find out the most favorite fishing spot in Perth'
        user=User()
        user.userId=1
        minResponses=5 #if not specified, the default value is -1 which will be ignored
        orderCandidateBy=None #if not specified, the default value is alphabel acending 'Acs'
        isOpenPoll=None #if not specified, the default value is False
        openAt=None #if not specified, the default value is utcnow()
        closeAt=None  # if not specified, the default value is today + 7 days
        poll=Poll(title, description, minResponses, orderCandidateBy, isOpenPoll, openAt, closeAt, user)
        poll.addCandidate('test_createPoll- Narrows Bridge Perth',None)
        poll.addCandidate('test_createPoll- White Hills Mandurah',None)
        poll.addCandidate('test_createPoll- North Mole Fremantle',None)
        poll.addCandidate('test_createPoll- Floreat Drain Floreat',None)
        poll.addCandidate('test_createPoll- Ricey Beach And Radar Reef Rottnest Island',None)
        poll.addCandidate('test_createPoll- Lancelin Jetty Lancelin',None)

        assert_that(createPoll(poll)).is_equal_to(True)