예제 #1
0
파일: routes.py 프로젝트: Dragonite/fishing
def current_view(pollId):
    users = getAllUsers()
    poll=getPollById(pollId)
    if poll:
        responseParameter=[]
        for item in poll.Candidate:
            responseParameter.append((item.candidateId, item.candidateDescription))
        form=makeResponseForm(responseParameter)
        renderedtitle=poll.title
    else:
        flash(Markup('<script>Notify("Poll does not exist.", null, null, "danger")</script>'))
        return redirect(url_for('main.current'))
    if form.is_submitted():
        preferences=form.preferences
        pref={}
        for item in preferences:
            print(item.data)
        index=1;
        for item in preferences:
            pref[item.data]=pref.get(item.data, index)
            index +=1    
        if Poll.Response.query.filter_by(pollId=pollId).filter_by(userId=current_user.userId).first()!=None:
            flash(Markup('<script>Notify("You have already voted for this poll.", null, null, "danger")</script>'))
            return redirect(url_for('main.current'))
        else:
            if poll.addResponse(current_user.userId, pref):
                flash(Markup('<script>Notify("You have successfully voted for this poll.", null, null, "success")</script>'))
                return redirect(url_for('main.current'))
            else:
                flash(Markup('<script>Notify("Oops, Something went wrong!", null, null, "danger")</script>'))
    return render_template("poll-views/currentPollView.html", title=renderedtitle, poll=poll, form=form, users=users)
예제 #2
0
파일: routes.py 프로젝트: Dragonite/fishing
def completed_view(pollId):
    poll=getPollById(pollId)
    users = getAllUsers()
    if poll:
        renderedtitle=poll.title
    else:
        renderedtitle="Oops, something is wrong"
    return render_template("poll-views/completedPollView.html", title=renderedtitle, poll=poll, users=users)
예제 #3
0
파일: routes.py 프로젝트: Dragonite/fishing
def profile():
    all_polls = getAllPolls()
    polls = []
    form=closePollForm()
    for poll in all_polls:
        if poll.createdByUserId == current_user.userId:
            polls.append(poll)
    if form.validate_on_submit():
        myPoll = getPollById(form.pollId.data)
        myPoll.close()
        if modifyPoll(myPoll):
            flash(Markup('<script>Notify("Poll has been closed successfully!", null, null, "success")</script>'))

    return render_template("profile.html", title='My Profile', polls=polls, form=form)
예제 #4
0
파일: routes.py 프로젝트: Dragonite/fishing
def poll_archive(pollId):
    if current_user.is_authenticated:
        if current_user.isAdmin:
            users=getAllUsers()
            poll=getPollById(pollId)
            form= deleteResponseForm()
            if poll==None:
                flash(Markup('<script>Notify("Cannot find poll.", null, null, "danger")</script>'))
            if form.is_submitted():
                if User.query.filter_by(userId=form.userId.data).first():
                    if archiveResponse(poll,int(form.userId.data)):
                        flash(Markup('<script>Notify("The response has been archived successfully!", null, null, "success")</script>'))
                    else:
                        flash(Markup('<script>Notify("Could not archive the response.", null, null, "danger")</script>'))
    return render_template("archive-components/responseArchive.html", title="Archive Responses: "+"Poll "+str(pollId), poll=poll, users=users, form=form)
예제 #5
0
파일: routes.py 프로젝트: Dragonite/fishing
def archive_poll():
    if current_user.is_authenticated:
        if current_user.isAdmin:
            users=getAllUsers()
            polls=getAllPolls()
            form=deletePollForm()
            if form.is_submitted():
                poll=getPollById(form.pollId.data)
                if poll==None:
                    flash(Markup('<script>Notify("Cannot find poll.", null, null, "danger")</script>'))
                else:
                    poll.close()
                    # modifyPoll(poll)
                    if archivePoll(poll):
                        flash(Markup('<script>Notify("The poll has been archived successfully!", null, null, "success")</script>'))
                    else:
                        flash(Markup('<script>Notify("Could not archive the poll.", null, null, "danger")</script>'))
        else:
            flash(Markup('<script>Notify("Only an admin user can view this page.", null, null, "danger")</script>'))
            return redirect(url_for('main.index'))
    return render_template("archive-components/pollArchive.html", title="Archive Poll", polls=polls, users=users, form=form)
예제 #6
0
파일: routes.py 프로젝트: Dragonite/fishing
def get_poll(pollId):
    poll=getPollById(pollId)
    if poll:
        return jsonify(poll.to_dict())
    else: 
        bad_request('pollId does not exists')
예제 #7
0
파일: routes.py 프로젝트: Dragonite/fishing
def specific_poll_view(pollId):
    poll=getPollById(pollId)
    if(poll.completedAt):
        return redirect(url_for('main.completed')+'/'+str(pollId))
    return redirect(url_for('main.current')+'/'+str(pollId))