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())
Beispiel #3
0
def restoreStatus():
    group = BackendManager.getGroupStatus()
    if group is not None:
        setGroup(group)
Beispiel #4
0
def login():
    # Logout
    session.pop('username', None)

    if request.method == 'POST':
        # Validate input
        if (request.form['userName'] == ''):
            return redirect(url_for('errorPage', errorMsg="userNotSelected"))
        if (request.form['groupName'] == ''):
            return redirect(url_for('errorPage', errorMsg="groupNotSelected"))

        # Create group if leader
        if request.form['loginType'] == 'Create':
            if (request.form['groupSize'] == ''):
                return redirect(url_for('errorPage', errorMsg="sizeNotSelected"))

            # Trim and get group size
            try:
                groupSize = str(int(request.form['groupSize']))
            except:
                return redirect(url_for('errorPage', errorMsg="groupSizeNotValid"))

            # Create object to store group information
            group = PhotoGroup(request.form['groupName'], groupSize, 0)
            setGroup(group)

            # Create folder for grup images
            groupPath = group.getGroupFSPath()
            if not os.path.exists(groupPath): 
                os.makedirs(groupPath)
            cleanAllFiles(groupPath)

            # Notify backend
            BackendManager.createGroup()

        # Before joining, check group exists
        groupName = request.form['groupName']
        group = getGroup(groupName)
        if (group is None):
            return redirect(url_for('errorPage', errorMsg="nonExistentGroup"))

        # Now check if there are spaces available
        if(not group.isInGroup(request.form['userName'])) and (not group.isSpaceAvailable()):
            return redirect(url_for('errorPage', errorMsg="maxUsersReached"))

        # Setup session, joining group
        userName = request.form['userName']
        session['username'] = userName            
        
        # Depending on status from current Group, redirect to page that the user was before
        if group.isUserSubmitted(userName):
            return redirect(url_for('waitForMontage', groupName=groupName))
        elif group.isUserApproved(userName):
            return redirect(url_for('waitForApproval', groupName=groupName))
        elif group.isUserDone(userName):
            return redirect(url_for('commitMontage', groupName=groupName))
        else:
            # Join group and go to upload page
            group.setStatusReady(userName)
            return redirect(url_for('upload', groupName=groupName))
    else:
        return render_template('login.html')