Ejemplo n.º 1
0
def validate_start_before_end(start_date, start_time, end_date, end_time):
    start_datetime = return_datetime(start_date, start_time)
    end_datetme = return_datetime(end_date, end_time)

    if end_datetme < start_datetime:
        return False
    else:
        return True
Ejemplo n.º 2
0
def insert_availability_request(
            org_id,
            tz, 
            avail_request_name, 
            start_date, 
            start_time, 
            end_date, 
            end_time
        ):
    '''insert an availability request into the database'''
    db = get_db()
    cur = db.cursor()
    # get datetime objects for start and end
    start_request = return_datetime(start_date, start_time, tz)
    end_request = return_datetime(end_date, end_time, tz)

    # insert new avaiability request into the database
    cur.execute(
        ''' INSERT INTO availability_request 
        (avail_request_name, start_request, end_request, 
        timezone, org_id, completed) VALUES (%s, %s, %s, %s, %s, %s)
        RETURNING avail_request_id''',
        (avail_request_name, start_request, end_request, tz, org_id, False)
    )

    # in order to add to member_request we need to avail_request_id of the 
    # availability request we just created
    member_id = session.get('member_id')

    avail_request_id = cur.fetchone()

    #insert everyone in the organization into member_request
    cur.execute(
        'SELECT member_id FROM roster WHERE roster.org_id = %s',
        (org_id,)
    )

    members_in_org = cur.fetchall()

    for member in members_in_org:
        org_member_id = member[0] #member_id of a member in the org

        # insert this member and the avail_request id of the newly created 
        # availability request into member_id
        cur.execute(
            '''
            INSERT INTO member_request (member_id, avail_request_id, answered) 
            VALUES (%s, %s, %s)
            ''',
            (org_member_id, avail_request_id[0], False)
        )
    db.commit()

    #update session data
    session['avail_requests'] = get_avail_requests_data(session['member_id'])
    session['org_avail_requests'] = get_org_avail_requests(session['active_org']['org_id'])
    session.modified = True
Ejemplo n.º 3
0
def insert_availability_slot(avail_request_id, start_date, start_time, end_date, end_time, timezone):
    '''insert an availability slot into the database'''
    db = get_db()
    cur = db.cursor()
    # get datetime objects for start and end
    start_slot = return_datetime(start_date, start_time, timezone)
    end_slot = return_datetime(end_date, end_time, timezone)

    # insert new availability slot into the database
    cur.execute(
        '''
        INSERT INTO availability_slot(
        start_slot, end_slot, avail_request_id, member_id
        ) 
        VALUES (%s, %s, %s, %s)
        RETURNING avail_slot_id
        ''',
        (start_slot, end_slot, avail_request_id, session['member_id'],)
    )

    # get avail_slot_id of the last insert
    avail_slot_id = cur.fetchone()[0]

    # set the answered field in member_request to TRUE
    cur.execute(
        ''' UPDATE member_request SET answered = TRUE WHERE member_id = %s AND avail_request_id = %s ''',
        (session['member_id'], avail_request_id,)
    )
    db.commit()

    # update session data 
    start_datetime = return_datetime(start_date, start_time).strftime("%-m/%-d/%Y %-I:%M%p")
    end_datetime = return_datetime(end_date, end_time).strftime("%-m/%-d/%Y %-I:%M%p")

    for response in session['member_responses']: 
        if response['member_id'] == session['member_id']:
            response['answered'] = 1
            response['avail_slots'].append(
                {
                    'start_time': start_datetime,
                    'end_time': end_datetime,
                    'avail_slot_id': avail_slot_id
                }
            )
    session.modified = True    
Ejemplo n.º 4
0
def insert_booked_date(avail_request_id, start_date, start_time, end_date, end_time, timezone):
    '''insert a booked_date into the database'''
    db = get_db()
    cur = db.cursor()

    # get datetime objects for the start and end
    start_book = return_datetime(start_date, start_time, timezone)
    end_book = return_datetime(end_date, end_time, timezone)    

    # get timezone, org_id, and avail_request_name from avail_request
    # these fields are all carried over into the booked date
    cur.execute(
        '''
        SELECT 
        availability_request.timezone, 
        availability_request.org_id, 
        availability_request.avail_request_name
        FROM availability_request
        WHERE availability_request.avail_request_id = %s
        ''',
        (avail_request_id,)
    )

    avail_request_info = cur.fetchone()

    tz = avail_request_info[0]
    org_id = avail_request_info[1]
    name = avail_request_info[2]

    # insert the booked date into the database
    cur.execute(
        '''INSERT INTO booked_date(
            booked_date_name, start_time, end_time, timezone, org_id, avail_request_id
        ) VALUES (%s, %s, %s, %s, %s, %s)''',
        (name, start_book, end_book, tz, org_id, avail_request_id,)
    )
    db.commit()

    # update session data
    session['booked_dates'] = get_member_booked_dates(session['member_id'])
    session['org_booked_dates'] = get_org_booked_dates(session['active_org']['org_id'])
    session.modified = True
Ejemplo n.º 5
0
def validate_time_slot(
        avail_request_start,  #formatted datetime string
        avail_request_end,  #formatted datetime string
        start_slot_date,
        start_slot_time,
        end_slot_date,
        end_slot_time):
    #get datetimes for the start and end of the availability_slot
    start_slot_datetime = return_datetime(start_slot_date, start_slot_time)
    end_slot_datetime = return_datetime(end_slot_date, end_slot_time)

    #get datetimes for the start and end of the the availability request
    avail_request_start_datetime = datetime.strptime(avail_request_start,
                                                     "%m/%d/%Y %I:%M%p")
    avail_request_end_datetime = datetime.strptime(avail_request_end,
                                                   "%m/%d/%Y %I:%M%p")

    if start_slot_datetime < avail_request_start_datetime:
        return "availability slot cannot start before the availability request"
    elif end_slot_datetime > avail_request_end_datetime:
        return "avaiability slot cannot end after the availability request"
    else:
        return None