def produceCSVList(context): logger.info("peep->produceCSVList Entry") objHandler = mycontext.getObjectHandler() peepList = objHandler.getList("People") #peepList = mycontext.getPeeps(context) logger.info("peep->produceCSVList - peepList has " + str(len(peepList)) + " peeps in it") list = [] for peep in peepList: row = {} row['index'] = fieldOrDefault(peep, 'index', "0") row['id'] = fieldOrDefault(peep, 'id') row['level'] = fieldOrDefault(peep, 'level') row['firstName'] = fieldOrDefault(peep, 'firstName') row['familyName'] = fieldOrDefault(peep, 'familyName') row['preferredName'] = fieldOrDefault(peep, 'preferredName') row['dob'] = fieldOrDefault(peep, 'dob') row['dod'] = fieldOrDefault(peep, 'dod') row['maidenName'] = fieldOrDefault(peep, 'maidenName') row['fatherIndex'] = getParentIndex(context, peep, 'fatherid') row['motherIndex'] = getParentIndex(context, peep, 'motherid') list.append(row) logger.info("peep->produceCSVList Exit - returning list with " + str(len(list)) + " peeps in it") return list
def produceDecendentList(context, id): decendentLines = [] logger.info("peep->produceDecendentList Entry") #peepList = mycontext.getPeeps(context) objHandler = mycontext.getObjectHandler() peepList = objHandler.getList("People") logger.info("peep->produceDecendentList - peepList has " + str(len(peepList)) + " peeps in it") # first dump the top level parent (find them first) line = "" for peep in peepList: if peep['id'] == id: line = peep['firstName'] break decendentLines.append(line) lines = processDecendentNode(peepList, id, 1) decendentLines += lines logger.info("peep->produceDecendentList Exit") return decendentLines
def getEnvoy5s(): logger.info("power->getEnvoy5s entry") objHandler = mycontext.getObjectHandler() rec = objHandler.get("Power", "envoy5s") logger.info("peep->getEnvoy5s exit") return rec
def putEnvoy5s(rec): logger.info("power->putEnvoy5s entry") objHandler = mycontext.getObjectHandler() x = objHandler.put(rec, "Power", "envoy5s") if x == 1: #print("fn returned " + str(x)) result = {'result': 'Success', 'id': "envoy5s"} else: result = {'result': 'Failed'} logger.info("peep->putEnvoy5s exit") return result
def getPeep(context, id): objHandler = mycontext.getObjectHandler() aPeep = objHandler.get("People", id) #peepList = mycontext.getPeeps(context) logger.info("peep->getPeeps - aPeep is " + str(aPeep)) if not aPeep is None: theList = [] theList.append(aPeep) logger.info("peep->getPeep - returned list has " + str(len(theList)) + " peeps in it (one expected)") return theList
def getParentIndex(context, peep, parentGuid): if not parentGuid in peep: logger.debug('peep->getParentIndex no guid for ' + parentGuid) return "" if len(peep[parentGuid]) != 36: logger.debug('peep->getParentIndex guid not valid for ' + parentGuid) return "" objHandler = mycontext.getObjectHandler() peepList = objHandler.getList("People") #peepList = mycontext.getPeeps(context) for lookupPeep in peepList: if lookupPeep['id'] == peep[parentGuid]: logger.debug('peep->getParentIndex FOUND parent ' + parentGuid + " its " + lookupPeep['firstName'] + " with id = " + lookupPeep['index'] + ' for ' + peep['firstName']) return lookupPeep['index'] logger.debug('peep->getParentIndex did not find Parent ' + parentGuid + " for peep " + lookupPeep['firstName']) return ""
def getPeepsList(context, familyName="", birthSex=""): objHandler = mycontext.getObjectHandler() peepList = objHandler.getList("People") #peepList = mycontext.getPeeps(context) logger.info("peep->getPeepsList - peepList has " + str(len(peepList)) + " peeps in it") logger.info("peep->getPeepsList - familyName = " + familyName + " sex = " + birthSex) theList = [] for peep in peepList: # Check for the id first if familyName != "": #logger.info("peep->getPeepsList - trying to match familyName = " + familyName + " with peep familyname = " + peep['familyName']) if compareIfExists(peep, 'familyName', familyName) or compareIfExists( peep, 'maidenName', familyName): if birthSex != "": if peep['birthCertificateSex'] == birthSex: theList.append(peep) continue else: # I.e. FamilyName specfied but not sex. only match of family name in this case. theList.append(peep) continue else: #TODO match on sex only if needed #logger.info("Appending the fallthrough") theList.append(peep) # Sort the key by family name if len(theList) > 1: theList.sort(key=peepSort) logger.info("peep->getPeepsList - returned list has " + str(len(theList)) + " peeps in it") return theList
def getBirthdayList(context, level, daysUntil, daysSince, allPeeps): logger.info("peep->getBirthdayList Entry - level - " + level + " daysUntil = " + daysUntil + " daysSince = " + daysSince + " allPeeps = " + allPeeps) objHandler = mycontext.getObjectHandler() peepList = objHandler.getList("People") logger.info("peep->getBirthdayList - peepList has " + str(len(peepList)) + " peeps in it") list = [] today = mycontext.getToday(context) logger.debug("peep->getBirthdayList - today is " + str(today)) for peep in peepList: logger.debug("peep->getBirthdayList - processing peep " + peep['firstName']) if not validDate(peep, "dob"): logger.debug( "peep->getBirthdayList - peep skipped as no valid dob") continue # In theory a peep can be added twice (TODO NEED TO CHECK FOR 365 days) dob = datetime.datetime.strptime(peep['dob'], "%Y-%m-%d") logger.debug("peep->getBirthdayList - peep (" + peep['firstName'] + ") DOB is " + str(dob)) # Check for past birthdays... cbd = getClosestBirthday(today, dob, -1 * int(daysSince)) logger.debug("peep->getBirthdayList - peep " + peep['firstName'] + " closest birthday is " + str(cbd)) if cbd is None: logger.debug("peep->getBirthdayList - peep " + peep['firstName'] + " does not have a birthday in the past close enough") else: daysAway = (cbd - today).days pastPeep = peep.copy() # Clone the peep logger.debug( "peep->getBirthdayList (in the past) - days away is " + str(daysAway)) pastPeep['daysAway'] = str(daysAway) age = relativedelta(today, dob).years pastPeep['age'] = str(age) if isIncludePeep(peep, level, allPeeps): logger.debug("peep->getBirthdayList adding peep (past) " + peep['firstName']) addPeepToBirthdayList(list, pastPeep) # Check for future birthdays... cbd = getClosestBirthday(today, dob, int(daysUntil)) logger.debug("peep->getBirthdayList - peep " + peep['firstName'] + " closest birthday is " + str(cbd)) if cbd is None: logger.debug( "peep->getBirthdayList - peep " + peep['firstName'] + " does not have a birthday in the future close enough") else: daysAway = (cbd - today).days futurePeep = peep.copy() # Clone the peep logger.debug( "peep->getBirthdayList (in the future) - days away is " + str(daysAway)) futurePeep['daysAway'] = str(daysAway) age = relativedelta(today, dob).years if daysAway == 0: futurePeep['age'] = str(age) else: futurePeep['age'] = str(age + 1) if isIncludePeep( peep, level, allPeeps ) or daysAway == 0: # Always include birthday peeps logger.debug("peep->getBirthdayList adding peep (future) " + peep['firstName']) addPeepToBirthdayList(list, futurePeep) logger.info("peep-> getBirthdayList Exit - returning " + str(len(list)) + " birthday events") return list
def putPeep(context, peep): logger.info("peep->putPeep entry") # List of fields that can be in a peep stdPeep = [ "id", "firstName", "familyName", "otherNames", "maidenName", "level", "motherid", "fatherid", "stepFatherid", "stepMotherid", "dob", "dod", "birthCertificateSex", "version", "notes" ] result = None id = None if 'id' in peep: id = peep['id'] if id == "": id = None else: # TODO Check for stale copy logger.info("peep->putPeep check for updated blah blah") if id is None: id = str(uuid.uuid4()) # Set the ID logger.info("peep->putPeep - NEW PEEP - Id assigned = " + id) ver = 0 targetPeep = {} else: # Get the current record logger.info("peep->putPeep - EXITING PEEP - Id = " + id) targetPeep = getPeep(context, id)[0] ver = 0 if 'version' in targetPeep: ver = int(targetPeep['version']) ver += 1 targetPeep['id'] = id targetPeep['version'] = str(ver) # Assume it's the first for fld in stdPeep: if fld in peep: if (peep[fld] != "Recorded") and ( peep[fld] != "Not Recorded") and (peep[fld] != ""): targetPeep[fld] = peep[fld] if 'familyName' not in targetPeep: targetPeep['familyName'] = "<<NOT DEFINED>>" if 'level' not in targetPeep: targetPeep[ 'level'] = "3" # Most likely a baby? ToDo. Maybe can look up parents... if 'birthCertificateSex' not in targetPeep: targetPeep['birthCertificateSex'] = "<<NOT DEFINED>>" if 'birthSex' in peep: targetPeep['birthCertificateSex'] = peep['birthSex'] objHandler = mycontext.getObjectHandler() x = objHandler.put(targetPeep, "People", id) if x == 1: #print("fn returned " + str(x)) result = {'result': 'Success', 'id': id} else: result = {'result': 'Failed'} logger.info("peep->putPeep exit") return result