Beispiel #1
0
def approval(groupName=None):
    # Group check
    group = getGroup(groupName)
    if (group is None):
        return redirect(url_for('errorPage', errorMsg="nonExistentGroup"))

    # User check
    if(not session['username'] or not group.isInGroup(session['username'])):
        return redirect(url_for('errorPage', errorMsg="userIsNotInGroup"))

    if group.isTimeUp():
        group.stopTimer()
        group.setAllReady()
        BackendManager.storeGroupStatus(groupName, group.getUsersStatus()) 
        return redirect(url_for('upload', groupName=groupName))            

    if request.method == 'GET':
        if group.checkAllReady():
            # Someone aborted; we all go back to uploading...
            return redirect(url_for('upload', groupName=groupName))    
        elif group.anyUserReady():
            # Check if someone went back to change their pictures. If so, lets go wait for the new montage
            group.setStatusSubmitted(session['username'])
            return redirect(url_for('waitForMontage', groupName=groupName))
        else:
            # Show montage for user to approve
            montagePath = group.generateMontagePath()
            return render_template('coordinate.html', name=groupName, montagePath=montagePath)
    elif request.method == 'POST':
        # Handle user approval
        if request.form['submitBtn'] == 'Approve':
            group.setStatusApproved(session['username']) 

            # Save state to backend
            BackendManager.storeGroupStatus(groupName, group.getUsersStatus())

            # Go to waiting page if required (or it will make us jump straight to commited state)
            return redirect(url_for('waitForApproval', groupName=groupName))
        elif request.form['submitBtn'] == 'Reject':
            # Move everybody back to the "ready to upload" phase
            group.setAllReady()

            # Save state to backend
            BackendManager.storeGroupStatus(groupName, group.getUsersStatus()) 
            return redirect(url_for('upload', groupName=groupName))         
        else:   # Upload new Image
            # We send everybody to "waiting for other pictures" except for the current one, which goes to "ready to upload"
            group.setAllSubmitted()
            group.setStatusReady(session['username'])

            # Save state to backend
            BackendManager.storeGroupStatus(groupName, group.getUsersStatus())

            return redirect(url_for('upload', groupName=groupName))            
Beispiel #2
0
def waitForApproval(groupName=None):
    # Group check
    group = getGroup(groupName)
    if (group is None):
        return redirect(url_for('errorPage', errorMsg="nonExistentGroup"))

    # User check
    if(not session['username'] or not group.isInGroup(session['username'])):
        return redirect(url_for('errorPage', errorMsg="userIsNotInGroup"))

    if group.isTimeUp():
        group.stopTimer()
        group.setAllReady()
        BackendManager.storeGroupStatus(groupName, group.getUsersStatus()) 
        return redirect(url_for('upload', groupName=groupName))            

    if group.checkAllApprovedOrDone():
        # All have approved! Set this user as done (all have approved and he will know about it now)
        group.setStatusDone(session['username'])

        if group.checkAllDone():
            # If we are the last one asking for the montage status, remove session
            BackendManager.removeGroup()

        # Show the montage to the user
        return redirect(url_for('commitMontage', groupName=groupName))
    elif group.checkAllReady():
        # Someone aborted; we all go back to uploading...
        return redirect(url_for('upload', groupName=groupName))    
    elif group.anyUserReady():
        # Someone aborted to change their image; let's go back to the "waiting for montage" page
        group.setStatusSubmitted(session['username'])
        return redirect(url_for('waitForMontage', groupName=groupName))
    else:
        # Nothing new that is useful; still waiting for approvals or one abort
        return render_template('waitForApproval.html', name=groupName, memberStatus=group.getUsersStatus())