def makewholemonth(): listOfShifts = [] for i in range(7): listOfShifts.append(int(request.form[str(i)])) template = [] days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ] for i in range(len(listOfShifts)): thisDaysShifts = [] for j in range(listOfShifts[i]): thisShift = [] thisShiftRole = request.form[str(days[i] + "role" + str(j))] thisShiftStart = request.form[str(days[i] + "start" + str(j))] thisShiftEnd = request.form[str(days[i] + "end" + str(j))] thisShift.append(thisShiftRole) thisShift.append(thisShiftStart) thisShift.append( thisShiftEnd ) #Add the List of Role, Start, and End to a small list thisDaysShifts.append( thisShift ) #Add that small list to a list of all shifts for the day template.append( thisDaysShifts) #Add the day's worth of shifts to the template year = request.form['year'] month = request.form['month'] listOfDays = makeCalendarList(int(year), int(month)) roles = ['M', 'MA', 'A', 'C', 'R'] for rowOfDays in listOfDays: for i in range(len( rowOfDays)): #i represents the numerical equivalent of the day if rowOfDays[i] == "": continue else: for j in range( listOfShifts[i] ): #j represents each shift of each day, listOfShifts has each days number of shifts indexed todayRole = roles.index(template[i][j][0]) todayStart = template[i][j][1] todayEnd = template[i][j][2] day = rowOfDays[i] newShift = Shift(day, month, year, todayRole, todayStart, todayEnd) db.session.add(newShift) db.session.commit() table = makeWholeMonthShifts(template, int(year), int(month)) return render_template("month.html", table=table)
def makeWholeMonthShifts(template, year, month): listForm = makeCalendarList(year, month) monthName = datetime.date(1900, month, 1).strftime('%B') htmlTable = """ <h1 align="center">{0} {1} </h1> <br> <table width='100%' border='1px'> <tr> <th> Sunday </th> <th> Monday </th> <th> Tuesday </th> <th> Wednesday </th> <th> Thursday </th> <th> Friday </th> <th> Saturday </th> </tr>""".format(monthName, str(year), str(month)) for row in listForm: htmlTable += "<tr>" for i in range(len(row)): day = row[i] if day == "": htmlTable += "<td></td>" else: dayOfShifts = template[i] tableRows = "" for j in range(len(dayOfShifts)): tableRows = tableRows + "<tr><td>" + str( template[i][j][0]) + "</td><td></td><td>" + str( template[i][j][1]) + "</td><td>" + str( template[i][j][2]) + "</td></tr>" htmlTable += """<td valign='top'> <day style='float: right'>{0}</day> <table border='1px' border-collapse='collapse'><tr><th>Role</th><th>Employee</th><th>Beg</th><th>End</th></tr>{1}</table></td> """.format(day, tableRows) htmlTable += "</tr>" htmlTable += "</table>" return htmlTable
def deleteshifts(): if request.method == 'GET': year = int(request.args.get('year')) month = int(request.args.get('month')) shifts = Shift.query.filter_by(year=year, month=month).order_by( Shift.day.asc(), Shift.timeIn.asc()).all() startTimes = [ '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM' ] endTimes = [ '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM', '6PM', '7PM', '8PM', '9PM', '10PM' ] roles = ['M', 'MA', 'A', 'C', 'R'] listForm = makeCalendarList(year, month) monthName = datetime.date(1900, month, 1).strftime('%B') htmlTable = """<form action='/delete' method='post'> <input type='hidden' name='month' value='{2}'> <input type='hidden' name='year' value='{1}'>: <h1 align="center">{0} {1} </h1> <br> Delete Shifts <br> <table width='100%' border='1px'> <tr> <th> Sunday </th> <th> Monday </th> <th> Tuesday </th> <th> Wednesday </th> <th> Thursday </th> <th> Friday </th> <th> Saturday </th> </tr>""".format(monthName, str(year), str(month)) for row in listForm: htmlTable += "<tr>" for i in range(len(row)): day = row[i] if day == "": htmlTable += "<td></td>" else: tableRows = "" for shift in shifts: employee = User.query.filter_by( id=shift.userId).first() if employee == None: employeeName = "None" else: employeeName = employee.employeeName if shift.day == day: if employeeName == "None": valueFiller = "" else: valueFiller = "value='{0}'".format( employeeName) tableRows = tableRows + "<tr><td>" + roles[ shift. role] + "</td><td>" + employeeName + "</td><td>" + startTimes[ shift.timeIn - 8] + "</td><td>" + endTimes[ shift.timeOut - 8] + "</td><td><input type='checkbox' name='{0}' value='delete'></td></tr>".format( shift.id) htmlTable += """<td valign='top'> <day style='float: right'>{0}</day> <table border='1px' border-collapse='collapse'> <tr> <th>Role</th> <th>Employee</th> <th>Beg</th> <th>End</th> <th>Del</th> </tr>{1}</table></td> """.format(day, tableRows) htmlTable += "</tr>" htmlTable += "</table><label> Delete Shifts as Seen </label><input type='submit'>" return htmlTable if request.method == 'POST': year = request.form['year'] month = request.form['month'] shifts = Shift.query.filter_by(year=year, month=month).all() for shift in shifts: if request.form[str(shift.id)] == True: db.session.delete(shift) db.session.commit()
def editmonth(): year = int(request.args.get('year')) month = int(request.args.get('month')) shifts = Shift.query.filter_by(year=year, month=month).order_by( Shift.day.asc(), Shift.timeIn.asc()).all() startTimes = [ '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM' ] endTimes = [ '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM', '6PM', '7PM', '8PM', '9PM', '10PM' ] roles = ['M', 'MA', 'A', 'C', 'R'] listForm = makeCalendarList(year, month) monthName = datetime.date(1900, month, 1).strftime('%B') htmlTable = """<form action='/assignshifts' method='post'> <input type='hidden' name='month' value='{2}'> <input type='hidden' name='year' value='{1}'>: <h1 align="center">{0} {1} </h1> <br> <table width='100%' border='1px'> <tr> <th> Sunday </th> <th> Monday </th> <th> Tuesday </th> <th> Wednesday </th> <th> Thursday </th> <th> Friday </th> <th> Saturday </th> </tr>""".format(monthName, str(year), str(month)) for row in listForm: htmlTable += "<tr>" for i in range(len(row)): day = row[i] if day == "": htmlTable += "<td></td>" else: tableRows = "" for shift in shifts: employee = User.query.filter_by(id=shift.userId).first() if employee == None: employeeName = "None" else: employeeName = employee.employeeName listOfEmployees = [] optionList = "" if roles[shift.role] == "M": employees = User.query.filter_by(role=0).all() elif roles[shift.role] == "MA": employees = User.query.filter_by(role='0').all() extraEmployees = User.query.filter_by(role='2').all() elif roles[shift.role] == "A": employees = User.query.filter_by(role=2).all() elif roles[shift.role] == "C": employees = User.query.filter_by(role=3).all() else: employees = User.query.filter_by(role=4).all() for employee in employees: listOfEmployees.append(employee.employeeName) optionList = optionList + "<option value='{0}'>{1}</option>".format( employee.id, employee.employeeName) if roles[shift.role] == "MA": for employee in extraEmployees: listOfEmployees.append(employee.employeeName) optionList = optionList + "<option value='{0}'>{1}</option>".format( employee.id, employee.employeeName) if shift.day == day: if employeeName == "None": valueFiller = "" else: valueFiller = "value='{0}'".format(employeeName) tableRows = tableRows + "<tr><td>" + roles[ shift. role] + "</td><td>" + "<select name='{1}'{2}>{0}</select>".format( optionList, shift.id, valueFiller) + "</td><td>" + startTimes[ shift.timeIn - 8] + "</td><td>" + endTimes[ shift.timeOut - 8] + "</td></tr>" htmlTable += """<td valign='top'> <day style='float: right'>{0}</day> <table border='1px' border-collapse='collapse'> <tr> <th>Role</th> <th>Employee</th> <th>Beg</th> <th>End</th> </tr>{1}</table></td> """.format(day, tableRows) htmlTable += "</tr>" htmlTable += "</table><label> Assign Shifts as Seen </label><input type='submit'>" return htmlTable
def viewmonth(): year = int(request.args.get('year')) month = int(request.args.get('month')) shifts = Shift.query.filter_by(year=year, month=month).order_by( Shift.day.asc(), Shift.timeIn.asc()).all() startTimes = [ '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM' ] endTimes = [ '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM', '6PM', '7PM', '8PM', '9PM', '10PM' ] roles = ['M', 'MA', 'A', 'C', 'R'] listForm = makeCalendarList(year, month) monthName = datetime.date(1900, month, 1).strftime('%B') htmlTable = """ <h1 align="center">{0} {1} </h1> <br> <table width='100%' border='1px'> <tr> <th> Sunday </th> <th> Monday </th> <th> Tuesday </th> <th> Wednesday </th> <th> Thursday </th> <th> Friday </th> <th> Saturday </th> </tr>""".format(monthName, str(year), str(month)) for row in listForm: htmlTable += "<tr>" for i in range(len(row)): day = row[i] if day == "": htmlTable += "<td></td>" else: tableRows = "" for shift in shifts: employee = User.query.filter_by(id=shift.userId).first() if employee == None: employeeName = "None" else: employeeName = employee.employeeName if shift.day == day: tableRows = tableRows + "<tr><td>" + roles[ shift.role] + "</td><td>" + str( employeeName) + "</td><td>" + startTimes[ shift.timeIn - 8] + "</td><td>" + endTimes[ shift.timeOut - 8] + "</td></tr>" htmlTable += """<td valign='top'> <day style='float: right'>{0}</day> <table border='1px' border-collapse='collapse'> <tr> <th>Role</th> <th>Employee</th> <th>Beg</th> <th>End</th> </tr>{1}</table></td> """.format(day, tableRows) htmlTable += "</tr>" htmlTable += "</table>" return htmlTable