def shiftNotes(): employeeID = current_user.get_id() clientIP = request.environ['REMOTE_ADDR'] if clientIP == "137.22.5.163" or clientIP == "137.22.29.178" or clientIP == "137.22.2.38": location = "CMC" #default location else: location = "ResearchIT" #elif clientIP == "137.22.7.132" or clientIP == "137.22.7.136": # location = "ResearchIT" #else: # #not in allowed location for checkin # location = "Unauthorized" shiftID = accessDB(getCurrentShift, location, employeeID) if request.method == 'POST': note = request.form.get("note_input") #truncate note to 255 characters, just in case some joker tries to game the system. note = note[:255] accessDB(addShiftNotes, shiftID, employeeID, note) return ("nothing") elif request.method == 'GET': #retrieve the note for the shift already. notes = accessDB(getShiftNotes, shiftID, employeeID) if notes: #if notes isn't empty... return jsonify( {"notes": notes[0]} ) #it's a tuple b/c it's a result set, so we need to extract the content from the tuple. else: return jsonify({"noContent"})
def getShiftCalendarData( db, startDate, endDate ): #startDate and endDate should be passed in as ISO8601 Date Strings e.g 2013-12-01 cur = db.cursor() theNow = datetime.now().strftime("%Y-%m-%d %H:%M") cur.execute("SELECT id FROM ShiftList where date >= %s AND date <= %s", (startDate, endDate)) allShiftIDs = cur.fetchall() relevantShifts = [] for elem in allShiftIDs: thisShift = {} id = str(elem[0]) #Get the actual id out of the tuple... shiftInfoDic = accessDB(adminFunctions.getShiftInfo, id) #Result is a dictionary... thisShift["description"] = ( datetime.min + shiftInfoDic["startTime"] ).strftime("%I:%M %p") + "-" + ( datetime.min + shiftInfoDic["endTime"]).strftime("%I:%M %p") + "\n" #convert startTimes and endTimes to strings... startTime = ( datetime.combine(shiftInfoDic["date"], datetime.min.time()) + shiftInfoDic["startTime"]).strftime("%Y-%m-%dT%H:%M") endTime = ( datetime.combine(shiftInfoDic["endDate"], datetime.min.time()) + shiftInfoDic["endTime"]).strftime("%Y-%m-%dT%H:%M") thisShift["start"] = startTime thisShift["end"] = endTime thisShift["description"] = thisShift[ "description"] + "Location: " + shiftInfoDic["location"] + "\n" #next, get all the employeeInfos. employeeIDs = shiftInfoDic["employees"] title = "" for empid in employeeIDs: employeeInfo = accessDB(adminFunctions.getEmployeeInfo, empid) employeeFirstName = employeeInfo[0] employeeName = employeeInfo[0] + " " + employeeInfo[1] title = title + employeeFirstName + "\n" thisShift[ "description"] = thisShift["description"] + employeeName + "\n" thisShift["title"] = title #finally, get location and determine color from that.. if shiftInfoDic["location"] == "CMC": thisShift["color"] = "blue" else: thisShift["color"] = "#ffa100" thisShift["id"] = id thisShift["location"] = shiftInfoDic["location"] relevantShifts.append(thisShift) return relevantShifts
def frontEndUnrequestSub(): shiftID = request.form['shiftID'] employeeID = request.form['employeeID'] if current_user.get_id() != employeeID: return jsonify({"Response": "Employee Mismatch"}) else: accessDB(unrequestSub, employeeID, shiftID) return jsonify({"Response": "Success!"})
def frontEndRequestSub(): shiftID = request.form['shiftID'] employeeID = request.form['employeeID'] if current_user.get_id() != employeeID: return jsonify({ "Response": "Error: Employee requesting sub is not employee working shift." }) else: accessDB(requestSub, employeeID, shiftID) return jsonify({"Response": "Successfully submitted Sub Request."})
def quickReport(timeRange, **kwargs): #A function that reports the breakdown of shift checkins overall, over a given timerange, up to the present time. Includes both subbedShifts and regularShifts. #You may specify an individual worker, by employeeID #You may specify a startDate and an endDate. Doing so overrides the timerange parameter and goes from 00:00 on the startDate to 23:59 on the endDate. #get employeeID if there is one. employeeID = kwargs.get("employeeID", None) #get relevant start and end datetimes based on given time range. theNow = datetime.now() theYesterday = theNow - timeRange #timeRange must be a timedelta object. currDateTime = theNow.strftime("%Y/%m/%d %H:%M") yesterDateTime = theYesterday.strftime("%Y/%m/%d %H:%M") #get startDate and endDate if specified. If not, defaults to the previously defined timeranges. startDate = kwargs.get("startDate", theYesterday) endDate = kwargs.get("endDate", currDateTime) if employeeID == None: report = reportFunctions.quickReport(startDate, endDate) else: report = accessDB(reportFunctions.quickWorkerSummary, startDate, endDate, employeeID) #print (report) #bin the shifts. Indices 5 and 6 are the shift's startTime and checkinTime. binnedShifts = shiftBinner(report, 5, 6) #extract the counts and assign to human-readable variables. missed = len(binnedShifts[4]) fiveMin = len(binnedShifts[1]) tenMin = len(binnedShifts[2]) fifteenMin = len(binnedShifts[3]) return (len(report), missed, fiveMin, tenMin, fifteenMin)
def shiftCalendarData(): startDate = request.args.get("start") endDate = request.args.get("end") relevantShifts = accessDB(getShiftCalendarData, startDate, endDate) return jsonify(relevantShifts)
def frontEndcheckIn(): #clientIP = request.environ['REMOTE_ADDR'] #if clientIP != "137.22.5.163" or clientIP != "137.22.29.178" or clientIP != "137.22.2.38" or clientIP != "137.22.7.132" or clientIP != "137.22.7.136": # return jsonify({"Error":"Unauthorized IP"}) #else: #get Employee ID and Shift ID from the POST request employeeID = request.form['employeeID'] shiftID = request.form['shiftID'] #print ("Hello") #print (iemployeeID) #print (shiftID) checkInTime = getCurrentTime() accessDB(checkInEmployee, employeeID, checkInTime, shiftID) return jsonify({"checkInTime": checkInTime})
def frontEndDropSub(): origEmployeeID = request.form['origEmployeeID'] subEmployeeID = request.form['subEmployeeID'] shiftID = request.form["shiftID"] if current_user.get_id() != subEmployeeID: return jsonify({"Response": "Employee Mismatch"}) else: #print (request.form) #print (origEmployeeID) #print (shiftID) accessDB(dropSub, shiftID, origEmployeeID, subEmployeeID) return jsonify({"Response": "Success!"})
def frontEndPickupSub(): origEmployeeID = request.form["origEmployeeID"] subEmployeeID = request.form["subEmployeeID"] shiftID = request.form["shiftID"] if current_user.get_id() != subEmployeeID: return jsonify({"Response": "Employee Mismatch"}) else: if accessDB(checkShiftConflict, subEmployeeID, shiftID): return jsonify({"Response": "Shift Conflicts With Another"}) else: accessDB(pickupSub, shiftID, origEmployeeID, subEmployeeID) return jsonify({"Response": "Success!"})
def frontEndGetSubbableShifts(): subbableShifts = accessDB(getSubbableShifts) shiftInfoList = [] for elem in subbableShifts: shiftID = elem[0] origEmployeeID = elem[5] diclist = {"shiftID": shiftID, "origEmployeeID": origEmployeeID} shiftInfoList.append(diclist) #shiftInfoList.update({shiftID : origEmployeeid}) #respectively, shiftid and origemployeeid. #JSONIFY A LIST. https://stackoverflow.com/questions/12435297/how-do-i-jsonify-a-list-in-flask/35000418#35000418 #print (shiftInfoList) return jsonify(shiftInfoList)
def getSubRequestStatus(): shiftID = request.args.get( 'shiftID' ) #https://stackoverflow.com/questions/10434599/how-to-get-data-received-in-flask-request employeeID = request.args.get('employeeID') # employeeID = request.form['employeeID'] # shiftID = request.form['shiftID'] #print ((employeeID, shiftID)) subStatus = accessDB(getSubStatus, shiftID, employeeID) subFilled = subStatus[1] subRequested = subStatus[0] return (jsonify({"subFilled": subFilled, "subRequested": subRequested}))