Ejemplo n.º 1
0
    def pull():
        """
        Pull all elvanto people into db, then pull down groups to add people.
        Then iterate through them to add them to the correct groups
        """
        data = e_api("people/getAll",
                     page_size=settings.ELVANTO_PEOPLE_PAGE_SIZE)

        people = data['people']
        num_synced = people["on_this_page"]
        page = 2
        while num_synced < people["total"]:
            more_data = e_api("people/getAll",
                              page_size=settings.ELVANTO_PEOPLE_PAGE_SIZE,
                              page=page)
            for person in more_data["people"]["person"]:
                people["person"].append(person)
            num_synced += more_data["people"]["on_this_page"]
            page += 1

        for e_prsn in people['person']:
            prsn, created = ElvantoPerson.objects.get_or_create(e_id=e_prsn['id'])
            prsn.first_name = e_prsn['firstname'].strip()
            prsn.preferred_name = e_prsn['preferred_name'].strip()
            prsn.last_name = e_prsn['lastname'].strip()
            prsn.save()
Ejemplo n.º 2
0
    def remove_people(self, ids_to_remove=None):
        if ids_to_remove is None:
            return

        print(
            'Removing {0} from {1}'.format(
                str(ids_to_remove),
                str(self.main_group)
            )
        )
        for p_id in ids_to_remove:
            e_api(
                "groups/removePerson",
                id=self.main_group.e_id,
                person_id=p_id
            )
Ejemplo n.º 3
0
    def add_people(self, ids_to_add=None):
        if ids_to_add is None:
            return

        print(
            'Adding {0} to {1}'.format(
                str(ids_to_add),
                str(self.main_group)
            )
        )
        for p_id in ids_to_add:
            e_api(
                "groups/addPerson",
                id=self.main_group.e_id,
                person_id=p_id
            )
Ejemplo n.º 4
0
 def pull():
     """
     Pull all elvanto groups and create entries in local db.
     """
     data = e_api("groups/getAll")
     for e_grp in data['groups']['group']:
         grp, created = ElvantoGroup.objects.get_or_create(e_id=e_grp['id'])
         grp.name = e_grp['name'].encode('utf-8', 'replace').strip()
         grp.save()
Ejemplo n.º 5
0
 def populate():
     data = e_api("groups/getAll", fields=['people'])
     if data['status'] == 'ok':
         for grp in data['groups']['group']:
             grp_obj = ElvantoGroup.objects.get(e_id=grp["id"])
             grp_obj.group_members.clear()
             if len(grp['people']) > 0:
                 for x in grp['people']['person']:
                     prsn = ElvantoPerson.objects.get(e_id=x['id'])
                     prsn.elvanto_groups.add(grp_obj)
                     prsn.save()