예제 #1
0
def sync_org_contacts(org_id):
    """
    Syncs all contacts for the given org
    """
    from chatpro.orgs_ext import TaskType
    from chatpro.rooms.models import Room
    from .models import Contact

    org = Org.objects.get(pk=org_id)

    logger.info('Starting contact sync task for org #%d' % org.id)

    sync_fields = [org.get_chat_name_field()]
    sync_groups = [r.uuid for r in Room.get_all(org)]

    created, updated, deleted, failed = sync_pull_contacts(org, Contact, fields=sync_fields, groups=sync_groups)

    task_result = dict(time=datetime_to_ms(timezone.now()),
                       counts=dict(created=len(created),
                                   updated=len(updated),
                                   deleted=len(deleted),
                                   failed=len(failed)))
    org.set_task_result(TaskType.sync_contacts, task_result)

    logger.info("Finished contact sync for org #%d (%d created, %d updated, %d deleted, %d failed)"
                % (org.id, len(created), len(updated), len(deleted), len(failed)))
예제 #2
0
    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)

        if self.user.get_org():
            org_rooms = Room.get_all(self.user.get_org()).order_by('name')
            self.fields['rooms'].queryset = org_rooms
            self.fields['manage_rooms'].queryset = org_rooms
예제 #3
0
    def __init__(self, *args, **kwargs):
        super(ContactForm, self).__init__(*args, **kwargs)

        if self.user.is_admin_for(self.user.get_org()):
            self.fields['room'].queryset = Room.get_all(self.user.get_org()).order_by('name')
        else:
            self.fields['room'].queryset = self.user.manage_rooms.all()
예제 #4
0
    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)

        if self.user.get_org():
            org_rooms = Room.get_all(self.user.get_org()).order_by('name')
            self.fields['rooms'].queryset = org_rooms
            self.fields['manage_rooms'].queryset = org_rooms
예제 #5
0
    def __init__(self, *args, **kwargs):
        super(ContactForm, self).__init__(*args, **kwargs)

        if self.user.is_admin_for(self.user.get_org()):
            self.fields['room'].queryset = Room.get_all(
                self.user.get_org()).order_by('name')
        else:
            self.fields['room'].queryset = self.user.manage_rooms.all()
예제 #6
0
    def kwargs_from_temba(cls, org, temba_contact):
        org_room_uuids = [r.uuid for r in Room.get_all(org)]
        room_uuids = intersection(org_room_uuids, temba_contact.groups)
        room = Room.objects.get(org=org, uuid=room_uuids[0]) if room_uuids else None

        if not room:
            raise ValueError("No room with uuid in %s" % ", ".join(temba_contact.groups))

        return dict(org=org,
                    full_name=temba_contact.name,
                    chat_name=temba_contact.fields.get(org.get_chat_name_field(), None),
                    urn=temba_contact.urns[0],
                    room=room,
                    uuid=temba_contact.uuid)
예제 #7
0
 def test_get_all(self):
     self.assertEqual(len(Room.get_all(self.unicef)), 3)
     self.assertEqual(len(Room.get_all(self.nyaruka)), 1)
예제 #8
0
 def calculate():
     # org admins have implicit access to all rooms
     if user.is_admin_for(org):
         return Room.get_all(org)
     else:
         return user.rooms.filter(is_active=True)
예제 #9
0
 def calculate():
     # org admins have implicit access to all rooms
     if user.is_admin_for(org):
         return Room.get_all(org)
     else:
         return user.rooms.filter(is_active=True)
예제 #10
0
 def test_get_all(self):
     self.assertEqual(len(Room.get_all(self.unicef)), 3)
     self.assertEqual(len(Room.get_all(self.nyaruka)), 1)