Esempio n. 1
0
def completed():
    polls=getClosedPolls(isAdmin=False)
    users = getAllUsers()
    if current_user.is_authenticated:
        if current_user.isAdmin:
            polls=getClosedPolls(isAdmin=True)
            users = getAllUsers()
            return render_template("completed.html", title='Completed Polls', polls=polls, users=users)
    return render_template("completed.html", title='Completed Polls', polls=polls, users=users)
Esempio n. 2
0
def current():
    polls=getCurrentPolls()
    users=getAllUsers()
    
    if current_user.is_authenticated:
        if current_user.isAdmin:
            polls=getCurrentPolls(isAdmin=True)
            users=getAllUsers()
            return render_template("current.html", title='Current Polls', polls=polls, users=users)
    return render_template("current.html", title='Current Polls', polls=polls, users=users)
Esempio n. 3
0
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)
Esempio n. 4
0
def users():
    
    if current_user.isAdmin:
        users=getAllUsers()
        return render_template("users.html", title='Users', users=users)
    else:
        flash(Markup('<script>Notify("Only an admin user can view this page.", null, null, "danger")</script>'))
        return redirect(url_for('main.index'))
Esempio n. 5
0
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)
Esempio n. 6
0
def index():
    all_polls = getAllPolls()
    current_polls = len(getCurrentPolls())
    completed_polls = len(getClosedPolls())
    user_count = len(getAllUsers())
    my_polls = []
    if hasattr(current_user, 'userId'):
        for poll in all_polls:
            if poll.createdByUserId == current_user.userId:
                my_polls.append(poll)
    return render_template('index.html', title='Home', my_polls=len(my_polls), current_polls=current_polls, completed_polls=completed_polls, all_users=user_count)
Esempio n. 7
0
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)
Esempio n. 8
0
def archive_users():
    if current_user.is_authenticated:
        if current_user.isAdmin:
            users=getAllUsers()
            form=deleteUserForm()
            if form.is_submitted():
                user=getUserById(form.userId.data)
                if user==None:
                    flash(Markup('<script>Notify("Cannot find user.", null, null, "danger")</script>'))
                else:
                    if archiveUser(user):
                        flash(Markup('<script>Notify("The user has been archived successfully!", null, null, "success")</script>'))
                    else:
                        flash(Markup('<script>Notify("Could not archive the user.", 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/userArchive.html", title='Users', users=users, form=form)
Esempio n. 9
0
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)