def get_people(user=None, personIDs=[], sync=False):
        if not personIDs:
            return []
        # select the persons that need to be fetched
        api = API(session["access_token"])
        pdict = {}
        ids = []
        for personID in personIDs:
            person = Person.get(user=user, api_id=personID, quick=True)
            pdict[personID] = person
            if sync or person.stale():
                ids.append(personID)

        # get person data
        pdata = api.get_individuals(ids)
        for data in pdata:
            personID = data["persons"][0]["id"]
            pdict[personID].api_data = data
            pdict[personID].parse()

        # save any fetched persons
        for api_id in ids:
            pdict[api_id].save()

        # collect results
        people = []
        for personID in personIDs:
            person = pdict[personID]
            people.append(person)

        return people
 def run(self):
     # get all the IDs of people in the pedigree
     api = API(self.access_token)
     data = api.get_pedigree(self.api_id)
     self.personIDs = []
     for person in data["persons"]:
         self.personIDs.append(person["id"])
    def get(user=None, api_id="", sync=False, quick=False):
        if not user or not api_id:
            raise DBError

        # lookup person in deceased DB first then living
        data = db.deceased.find_one({"api_id": api_id})
        if not data:
            data = db.living.find_one({"user_id": user.api_id, "api_id": api_id})
        # wrap in person object
        if not data:
            person = Person.new(user_id=user.api_id, api_id=api_id)
        else:
            person = Person(data)

        # convert to new version
        if person.version != "1.0":
            person = person.copy(person)
            person.save()

        if not quick and (sync or person.stale()):
            api = API(session["access_token"])
            person.api_data = api.get_individual(api_id)
            person.parse()
            person.save()

        return person
Exemple #4
0
    def get(user=None, api_id='', sync=False, quick=False):
        if not user or not api_id:
            raise DBError

        # lookup person in deceased DB first then living
        data = db.deceased.find_one({'api_id': api_id})
        if not data:
            data = db.living.find_one({
                'user_id': user.api_id,
                'api_id': api_id
            })
        # wrap in person object
        if not data:
            person = Person.new(user_id=user.api_id, api_id=api_id)
        else:
            person = Person(data)

        # convert to new version
        if person.version != "1.0":
            person = person.copy(person)
            person.save()

        if not quick and (sync or person.stale()):
            api = API(session['access_token'])
            person.api_data = api.get_individual(api_id)
            person.parse()
            person.save()

        return person
Exemple #5
0
    def get_people(user=None, personIDs=[], sync=False):
        if not personIDs:
            return []
        # select the persons that need to be fetched
        api = API(session['access_token'])
        pdict = {}
        ids = []
        for personID in personIDs:
            person = Person.get(user=user, api_id=personID, quick=True)
            pdict[personID] = person
            if sync or person.stale():
                ids.append(personID)

        # get person data
        pdata = api.get_individuals(ids)
        for data in pdata:
            personID = data['persons'][0]['id']
            pdict[personID].api_data = data
            pdict[personID].parse()

        # save any fetched persons
        for api_id in ids:
            pdict[api_id].save()

        # collect results
        people = []
        for personID in personIDs:
            person = pdict[personID]
            people.append(person)

        return people
Exemple #6
0
 def run(self):
     # get all the IDs of people in the pedigree
     api = API(self.access_token)
     data = api.get_pedigree(self.api_id)
     self.personIDs = []
     for person in data['persons']:
         self.personIDs.append(person['id'])
Exemple #7
0
 def ldsPermission(self):
     api = API(session['access_token'])
     api_data = api.get_permissions()
     if 'permissions' in api_data:
         for permission in api_data['permissions']:
             if permission['value'] == 'View LDS Information':
                 self.lds = True
                 return
     self.lds = False
 def ldsPermission(self):
     api = API(session["access_token"])
     api_data = api.get_permissions()
     if "permissions" in api_data:
         for permission in api_data["permissions"]:
             if permission["value"] == "View LDS Information":
                 self.lds = True
                 return
     self.lds = False
Exemple #9
0
    def pedigree(user=None, api_id='', generations=4, sync=False):
        if not sync:
            # check cached IDs and people
            people = Person.get_pedigree(user=user, api_id=api_id)
            if people != []:
                return people

        # get all the IDs of people in the pedigree
        api = API(session['access_token'])
        data = api.get_pedigree(api_id)
        personIDs = []
        for person in data['persons']:
            personIDs.append(person['id'])

        # get all the people in the pedigree
        people = Person.get_people(user=user, personIDs=personIDs, sync=sync)

        # find the leaves and get another four generations for each one
        pdict = {}
        for person in people:
            pdict[person.getID()] = person
        appIDs = Person.find_fourth(api_id=api_id, pdict=pdict)
        appPersonIDs = Person.get_pedigrees(user=user, appIDs=appIDs)
        # remove the people we already fetched
        for personID in personIDs:
            if personID in appPersonIDs:
                appPersonIDs.remove(personID)

        # get all those people
        app_people = Person.get_people(user=user,
                                       personIDs=appPersonIDs,
                                       sync=sync)

        # add them all up
        people.extend(app_people)

        # save people into person
        person = Person.get(user=user, api_id=api_id)
        person.pedigree = []
        for p in people:
            person.pedigree.append(p.api_id)
        person.save()
        return people
    def pedigree(user=None, api_id="", generations=4, sync=False):
        if not sync:
            # check cached IDs and people
            people = Person.get_pedigree(user=user, api_id=api_id)
            if people != []:
                return people

        # get all the IDs of people in the pedigree
        api = API(session["access_token"])
        data = api.get_pedigree(api_id)
        personIDs = []
        for person in data["persons"]:
            personIDs.append(person["id"])

        # get all the people in the pedigree
        people = Person.get_people(user=user, personIDs=personIDs, sync=sync)

        # find the leaves and get another four generations for each one
        pdict = {}
        for person in people:
            pdict[person.getID()] = person
        appIDs = Person.find_fourth(api_id=api_id, pdict=pdict)
        appPersonIDs = Person.get_pedigrees(user=user, appIDs=appIDs)
        # remove the people we already fetched
        for personID in personIDs:
            if personID in appPersonIDs:
                appPersonIDs.remove(personID)

        # get all those people
        app_people = Person.get_people(user=user, personIDs=appPersonIDs, sync=sync)

        # add them all up
        people.extend(app_people)

        # save people into person
        person = Person.get(user=user, api_id=api_id)
        person.pedigree = []
        for p in people:
            person.pedigree.append(p.api_id)
        person.save()
        return people
Exemple #11
0
 def get_current():
     # get API object
     api = API(session['access_token'])
     # get current user
     api_data = api.get_user()
     if sandbox:
         user_person = api.get_user_person()
         userID = user_person['id']
     else:
         userID = api_data['personId']
     user = User.get(userID)
     # store user information
     user.api_data = api_data
     if sandbox:
         user.lds = True
     else:
         user.ldsPermission()
     # This is what we'll use when it is implemented
     # user.ldsMember()
     user.save()
     return user
 def get_current():
     # get API object
     api = API(session["access_token"])
     # get current user
     api_data = api.get_user()
     if sandbox:
         user_person = api.get_user_person()
         userID = user_person["id"]
     else:
         userID = api_data["personId"]
     user = User.get(userID)
     # store user information
     user.api_data = api_data
     if sandbox:
         user.lds = True
     else:
         user.ldsPermission()
     # This is what we'll use when it is implemented
     # user.ldsMember()
     user.save()
     return user