Exemplo n.º 1
0
def return_data():
    start_date = request.args.get('start', '')
    end_date = request.args.get('end', '')
    current_time = datetime.now()
    shift_json = []
    for s in Shift.select().where((Shift.shift_time_end < current_time)):
        if s.name != "":
            shift_json.append(
                dict(title=s.name + '-' + s.role,
                     start=str(s.shift_time_start),
                     end=str(s.shift_time_end),
                     backgroundColor='#85929E'))
    for s in Shift.select().where((Shift.name == "")
                                  & (Shift.shift_time_end > current_time)):
        shift_json.append(
            dict(title=s.role,
                 start=str(s.shift_time_start),
                 end=str(s.shift_time_end),
                 backgroundColor='#66ff66'))
    for s in Shift.select().where((Shift.name != "")
                                  & (Shift.shift_time_end > current_time)):
        shift_json.append(
            dict(title=s.name + ' - ' + s.role,
                 start=str(s.shift_time_start),
                 end=str(s.shift_time_end),
                 backgroundColor='#3399ff'))
    # print(shsift_json)
    return json.dumps(shift_json)
Exemplo n.º 2
0
def checkAvailability(id, name, role):
    """
    This method checks the availability of the shifts and makes sure that there are no
    scheduling overlaps in terms of duration.

    Args:
        id: the id of the shift that will be in analysis
        name: name of the user that is attempting to claim the shift
        role: role of the user that is claiming the shift

    Returns:
        True: if there are no scheduling conflicts
        False: if the worker in question already has a schedule arranged
    """
    tryShift = Shift.get_shift(id)
    if tryShift.role != role:
        return False
    for workShift in Shift.select().where(Shift.name == name):
        if tryShift.shift_time_start == workShift.shift_time_start or tryShift.shift_time_end == workShift.shift_time_end:
            # print("Controller3: False")
            return False
        elif workShift.shift_time_start < tryShift.shift_time_start and workShift.shift_time_end > tryShift.shift_time_end:
            # print("Controller2: False")
            return False
        elif workShift.shift_time_start > tryShift.shift_time_start and workShift.shift_time_start < tryShift.shift_time_end:
            # print("Controller1: False")
            return False
    # print("Controller: True")
    return True
Exemplo n.º 3
0
def remove():
    '''
    This handles when the user needs to remove a shift
    '''
    id = request.args.get('id')
    role = flask_login.current_user.role
    if shift_controller.checkRemoveConditions(id, role):
        Shift.remove_shift(id)
        flash("Successfully removed the shift")
    else:
        flash("Unable to remove shift")
    return redirect(url_for('shift_manager.calendar'))
Exemplo n.º 4
0
def post():
    '''
    This handles when the user needs to post a shift
    '''
    id = request.args.get('id')
    name = flask_login.current_user.name
    role = flask_login.current_user.role
    if shift_controller.checkPostConditions(id, name, role):
        Shift.post_shift(id)
        flash("Notification: Successfully posted the shift")
        return redirect(url_for('shift_manager.calendar'))
    else:
        flash("Insufficient Privileges: Unable to post the shift")
        return redirect(url_for('shift_manager.calendar'))
Exemplo n.º 5
0
def claim():
    '''
    This handles when the user needs to claim a shift
    '''
    id = request.args.get('id')
    name = flask_login.current_user.name
    role = flask_login.current_user.role
    if shift_controller.checkAvailability(id, name, role):
        Shift.claim_shift(id, name)
        flash("Notification: Successfully claimed the shift")
        return redirect(url_for('shift_manager.calendar'))
    else:
        flash("Insufficient Privileges: Unable to claim the shift")
        return redirect(url_for('shift_manager.calendar'))
Exemplo n.º 6
0
def checkPostConditions(id, name, role):
    """
    This method checks the ability for the user to post their shift and makes sure that
    the user is not posting another user's shift. The only exceptions are for admins
    and managers.

    Args:
        id: the id of the shift that will be in analysis
        name: name of the user that is attempting to claim the shift
        role: role of the user that is claiming the shift

    Returns:
        True: if the user or the role has the proper influence
        False: if the user or role does not meet the criteria
    """
    tryShift = Shift.get_shift(id)
    current_time = datetime.now()
    if tryShift.shift_time_start < current_time:
        return False
    if role == 'admin' or role == 'manager':
        return True
    elif tryShift.role == role and tryShift.name == name:
        return True
    else:
        return False
Exemplo n.º 7
0
def calendar():
    '''
    Renders the index page of the shift management page
    '''
    current_time = datetime.now()
    employee_name = flask_login.current_user.name
    employee_role = flask_login.current_user.role
    form = ShiftForm()
    form.role.choices = {(r.role, r.role) for r in User.select()}
    form.role.default = ''
    if form.validate_on_submit() and form.submit.data:
        Shift.create_shift("", form.start.data, form.end.data, form.role.data)
    free_shifts = []
    for freeShift in Shift.select().where(
        (Shift.name == "") & (Shift.shift_time_end > current_time)):
        free_shifts.append(
            dict(shift_time_start=freeShift.shift_time_start,
                 shift_time_end=freeShift.shift_time_end,
                 role=freeShift.role,
                 id=freeShift.id))
    freeTable = FreeTable(free_shifts)
    claim_shifts = []
    form2 = CheckForm()
    form2.user.choices = {(u.name, u.name + ' - ' + u.role)
                          for u in User.select()}.union({('', 'All Users')})
    form2.user.default = ''
    if form2.validate_on_submit() and form2.submit.data:
        if form2.user.data == '':
            for claimShift in Shift.select().where(
                (Shift.name != "") & (Shift.shift_time_end > current_time)):
                claim_shifts.append(
                    dict(name=claimShift.name,
                         shift_time_start=claimShift.shift_time_start,
                         shift_time_end=claimShift.shift_time_end,
                         role=claimShift.role,
                         id=claimShift.id))
            selection = 'All Users'
            claimTable = ClaimTable(claim_shifts)
            flash("Notification: Shifts for selected user is displayed")
            return render_template('/shift_manager/index.html',
                                   logged_in=True,
                                   name=employee_name,
                                   role=employee_role,
                                   freeTable=freeTable,
                                   claimTable=claimTable,
                                   form=form,
                                   userShift=form2,
                                   selection=selection)
        else:
            for userShift in Shift.select().where(
                (Shift.name == form2.user.data)
                    & (Shift.shift_time_end > current_time)):
                claim_shifts.append(
                    dict(shift_time_start=userShift.shift_time_start,
                         shift_time_end=userShift.shift_time_end,
                         role=userShift.role,
                         id=userShift.id))
            selection = form2.user.data
            claimTable = UniqueTable(claim_shifts)
            flash("Notification: Shifts for selected user is displayed")
        return render_template('/shift_manager/index.html',
                               logged_in=True,
                               name=employee_name,
                               role=employee_role,
                               freeTable=freeTable,
                               claimTable=claimTable,
                               form=form,
                               userShift=form2,
                               selection=selection)
    else:
        for claimShift in Shift.select().where(
            (Shift.name != "") & (Shift.shift_time_end > current_time)):
            claim_shifts.append(
                dict(name=claimShift.name,
                     shift_time_start=claimShift.shift_time_start,
                     shift_time_end=claimShift.shift_time_end,
                     role=claimShift.role,
                     id=claimShift.id))
        selection = 'All Users'
        claimTable = ClaimTable(claim_shifts)
    return render_template('/shift_manager/index.html',
                           logged_in=True,
                           name=employee_name,
                           role=employee_role,
                           freeTable=freeTable,
                           claimTable=claimTable,
                           form=form,
                           userShift=form2,
                           selection=selection)