def signon(sessionID): numberOfHeldReadings=numberOfPartials() Sessions.putSessionValueInDB(sessionID, "numberOfHeldReadings", numberOfHeldReadings) respData = MultiDict(url=url, title='Blood Glucose', sessionID=sessionID) respData.update(MultiDict(numberOfHeldReadings=numberOfHeldReadings)) if Sessions.getSessionValueFromDB(sessionID, 'isSignedOn'): return jinja2_template('Admin.jinja2', respData, template_lookup=['templates']) else: return jinja2_template('Signon.jinja2', respData, template_lookup=['templates'])
def adminCommon(request, response, sessionID=None): Sessions.purgeOldSessions() sessionID = Sessions.initializeSession(sessionID, request, response) Sessions.putSessionValueInDB(sessionID, 'currentDB', str(dbPath)) respData = MultiDict(url=url, title='Blood Glucose', sessionID=sessionID) respData.update(MultiDict(numberOfHeldReadings=numberOfPartials())) isSignedOn = Sessions.getSessionValueFromDB(sessionID, 'isSignedOn') if isSignedOn: template = jinja2_template('Admin.jinja2', respData, template_lookup=['templates']) else: template = jinja2_template('Signon.jinja2', respData, template_lookup=['templates']) log('adminCommon', 'made new session', sessionID=sessionID) return template
def selectPost(): rf = request.forms sessionID = rf.sessionID selectedDate = rf.selectedDate respData = MultiDict(url=url, title='Blood Glucose', sessionID=sessionID) with db_session: reading = Readings[selectedDate] form = MultiDict() form.date = reading.date form.am = reading.am form.pm = reading.pm if reading.pm is not None else '' form.comment = reading.comment if reading.comment is not None else '' respData.update(MultiDict(form=form, dbFileName=dbFileName)) return jinja2_template('EditReading.jinja2', respData, template_lookup=['templates'])
def signonPost(): sessionID = request.forms.sessionID if isNone(sessionID): sessionID = HTTPCookie.getSessionCookie(request) syscode = System.getCode() formcode = request.forms.get('code') isSignedOn = verify_password(syscode, formcode) Sessions.putSessionValueInDB(sessionID, 'isSignedOn', isSignedOn) respData = MultiDict(url=url, title='Blood Glucose', sessionID=sessionID) respData.update(MultiDict(numberOfHeldReadings=numberOfPartials())) if isSignedOn: return jinja2_template('Admin.jinja2', respData, template_lookup=['templates']) else: respData.update(MultiDict(tryAgain=True)) return jinja2_template('Signon.jinja2', respData, template_lookup=['templates'])
def edit(): respData = MultiDict(url=url, title='Blood Glucose') rf = request.forms updated = False isFloatOK = False with db_session: reading = Readings[rf.date] if rf.pm != '': reading.pm = rf.pm isFloatOK = isFloat(rf.pm) updated = True if rf.comment != '': reading.comment = rf.comment updated = True if not isFloatOK: respData.update(MultiDict(PMisNotOK=True, errorValue=rf.pm)) return jinja2_template('EditReading.jinja2', respData, template_lookup=['templates']) if updated: System.putLastReadingDateStr(dateTimeStr(datetime.now(), 'America/Vancouver',ampm=True, month=True)) return jinja2_template('UpdateDone.jinja2', respData, template_lookup=['templates'])
def selectReadings(sessionID=None): respData = MultiDict(url=url, title='Blood Glucose', sessionID=sessionID) if sessionID is None or not Sessions.ifSessionExistsInDB(sessionID): return jinja2_template('Home.jinja2', respData, template_lookup=['templates']) Sessions.putSessionValueInDB(sessionID, 'sessionIDtoSelect', sessionID) if not Sessions.getSessionValueFromDB(sessionID, 'isSignedOn'): return jinja2_template('Signon.jinja2', respData, template_lookup=['templates']) with db_session: heldReadings = Readings.select(lambda c: c.am is not None and c.pm is None).order_by(1) heldReadingsList = list(heldReadings) numberOfHeldReadings = len(heldReadingsList) respData.update(MultiDict(numberOfHeldReadings=numberOfHeldReadings)) if numberOfHeldReadings > 0: heldReadingDates = [] index = 1 for heldReading in heldReadingsList: heldReadingDates.append((f'D{index}', heldReading.date)) index += 1 respData.update(MultiDict(heldReadingDates=heldReadingDates)) respData.update(MultiDict(heldData=None)) return jinja2_template('SelectReading.jinja2', respData, template_lookup=['templates']) else: return jinja2_template('NoneHeld.jinja2', respData, template_lookup=['templates'])
def enter(sessionID): sessionID = Sessions.initializeSession(sessionID, request, response) respData = MultiDict(url=url, title='Blood Glucose') isSignedOn = Sessions.getSessionValueFromDB(sessionID, 'isSignedOn') respData.update(MultiDict(sessionID=sessionID, numberOfHeldReadings=numberOfPartials())) respData.update(MultiDict(dbFileName=dbFileName)) if isSignedOn: with db_session: maxReadingDate = max(r.date for r in Readings) respData.update(MultiDict(maxDate=maxReadingDate)) return jinja2_template('EnterReading.jinja2', respData, template_lookup=['templates']) else: return jinja2_template('Signon.jinja2', respData, template_lookup=['templates'])
def enterPost(): rf = request.forms formDate = rf.date formAM = rf.am formAM = None if formAM == '' else formAM formPM = rf.pm formPM = None if formPM == '' else formPM formNote = rf.comment sessionID = HTTPCookie.getSessionCookie(request) respData = MultiDict(url=url, title='Blood Glucose', sessionID=sessionID) respData.update(MultiDict(numberOfHeldReadings=numberOfPartials())) respData.update(MultiDict(editDate=formDate)) with db_session: maxReadingDate = max(r.date for r in Readings) respData.update(MultiDict(maxDate=maxReadingDate)) valueError = False if not isFloat(formAM): valueError = True respData.update(MultiDict(AMisNotOK=True, errorValue=formAM)) if formPM is not None: if not isFloat(formPM): valueError = True respData.update(MultiDict(PMisNotOK=True, errorValue=formPM)) if valueError: return jinja2_template('EnterReading.jinja2', respData, template_lookup=['templates']) alreadyEntered = False try: with db_session: Readings(date=formDate, am=formAM, pm=formPM, comment=formNote) except (IntegrityError, Exception): alreadyEntered = True if alreadyEntered: respData.update(MultiDict(alreadyEntered=True)) return jinja2_template('EnterReading.jinja2', respData, template_lookup=['templates']) respData.update(MultiDict(numberOfHeldReadings=numberOfPartials())) System.putLastReadingDateStr(dateTimeStr(datetime.now(), 'America/Vancouver', ampm=True, month=True)) return jinja2_template('Admin.jinja2', respData, template_lookup=['templates'])