本文整理匯總了Python中DatabaseController.insertNewTimetableRecord方法的典型用法代碼示例。如果您正苦於以下問題:Python DatabaseController.insertNewTimetableRecord方法的具體用法?Python DatabaseController.insertNewTimetableRecord怎麽用?Python DatabaseController.insertNewTimetableRecord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DatabaseController
的用法示例。
在下文中一共展示了DatabaseController.insertNewTimetableRecord方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: updateTimetable
# 需要導入模塊: import DatabaseController [as 別名]
# 或者: from DatabaseController import insertNewTimetableRecord [as 別名]
def updateTimetable(listOfTimetableData):
if listOfTimetableData.__len__() > 0:
schoolId = int(listOfTimetableData[4])
studentId = int(listOfTimetableData[5])
listOfStoredRecords = DatabaseController.getStudentTimetable(schoolId, studentId)
currentStateIndex = 0
storedStateIndex = 0
while currentStateIndex < listOfTimetableData.__len__():
weekdayId = int(listOfTimetableData[currentStateIndex])
startHour = int(listOfTimetableData[currentStateIndex + 1])
startMin = int(listOfTimetableData[currentStateIndex + 2])
lessonLength = int(listOfTimetableData[currentStateIndex + 3])
schoolLessonId = int(listOfTimetableData[currentStateIndex + 6])
teacherId = int(listOfTimetableData[currentStateIndex + 7])
locationId = int(listOfTimetableData[currentStateIndex + 8])
classroomId = int(listOfTimetableData[currentStateIndex + 9])
# Determine the endHour for the lesson and the classroomLocationId
endMinutes = startMin + lessonLength
additionalHours = 0
while endMinutes > 60:
additionalHours += 1
endMinutes -= 60
endHour = int(startHour + additionalHours)
classroomLocationIdRecord = DatabaseController.getClassroomLocationIdBasedOnLocationIdAndClassroomId(locationId, classroomId)
classroomLocationId = int(classroomLocationIdRecord[0][0])
# Overwrite an existing timetable entry or insert a brand new one if required
if storedStateIndex < listOfStoredRecords.__len__():
existingRecordId = int(listOfStoredRecords[storedStateIndex][0])
DatabaseController.updateExistingTimetableRecord(existingRecordId, weekdayId, startHour, startMin, lessonLength, endHour, schoolLessonId,
teacherId, locationId, classroomLocationId)
storedStateIndex += 1
else:
maxCountRecord = DatabaseController.countNumberOfTimetableRecords()
maxCount = int(maxCountRecord[0][0])
newRecordId = maxCount + 1
DatabaseController.insertNewTimetableRecord(newRecordId, weekdayId, startHour, startMin, lessonLength, endHour, schoolLessonId, schoolId, studentId,
teacherId, locationId, classroomLocationId)
currentStateIndex += 10
# If there are any remaining existing lessons after all updates are complete - remove them
while storedStateIndex < listOfStoredRecords.__len__():
existingRecordId = int(listOfStoredRecords[storedStateIndex][0])
DatabaseController.deleteTimetableRecord(existingRecordId)
storedStateIndex += 1
else:
# No lessons currently on the timetable - delete all of the records stored in the database
schoolId = session.get("loginId")
studentId = session.get("studentId")
listOfStoredRecords = DatabaseController.getStudentTimetable(schoolId, studentId)
for eachRecord in listOfStoredRecords:
existingRecordId = int(eachRecord[0])
DatabaseController.deleteTimetableRecord(existingRecordId)