def hours(): ####################################################### name = str(request.get_cookie("name")) start = str(request.get_cookie("start")) ####################################################### # try to open file with user's name and retrieve data filePath = hoursDir + "/" + name # for each record, create a new Record object and add to list to pass to template # list of records as [obj] records = Record.parseRecordsFromFile(filePath) # DEBUG print("\n***DEBUG***") for r in records: print(r) print("***********\n") # if file doesn't exist, nullify cookies and proceed if not records: name = "" start = "" ####################################################### return template('hours', records=records, name=name, start=start)
def hours_post(): ####################################################### # name of user name = request.forms.get("name").strip() # index for inserting new Record into the list of records index = int(request.forms.get("insert").strip()) filePath = hoursDir + "/" + name ####################################################### # parses form data and returns a Record obj new_record = Record.getRecordFromHTML(request) ####################################################### # reads and parses Records on file records = Record.parseRecordsFromFile(filePath) ####################################################### # if the cookie is set, the user has pulled any existing files # if there are no existing files, the cookie will be null records_pulled = request.get_cookie("name") if records and not records_pulled: # append to the end of unpulled existing records # prevents adding to the beginning of an unexpected list records.append(new_record) print("Appending to list") else: print("Inserting in list at index:", index) # insert new record at index provided from template form records.insert(index, new_record) Record.adjustAdjacentRecords(records, index) #for i in range(len(records)): # Record.adjustAdjacentRecords(records, i) # write back updated list Record.writeRecords(filePath, records) ####################################################### response.set_cookie("name", name) #response.set_cookie("start", end) # end of record becomes start of next record redirect('hours')