Beispiel #1
0
def get_location_fixture_queryset(user):
    if toggles.SYNC_ALL_LOCATIONS.enabled(user.domain):
        return SQLLocation.active_objects.filter(
            domain=user.domain).prefetch_related('location_type')

    user_locations = user.get_sql_locations(user.domain)

    if user_locations.query.is_empty():
        return user_locations

    user_location_ids = list(user_locations.order_by().values_list("id",
                                                                   flat=True))

    if toggles.RELATED_LOCATIONS.enabled(user.domain):
        # Retrieve all of the locations related to a user's location and child
        # location and add them to the flat fixture
        related_location_ids = LocationRelation.from_locations(
            SQLLocation.objects.get_descendants(
                Q(domain=user.domain, id__in=user_location_ids)))
        user_location_ids.extend(
            list(
                SQLLocation.objects.filter(
                    location_id__in=related_location_ids).values_list(
                        'id', flat=True)))

    return _location_queryset_helper(user.domain, user_location_ids)
Beispiel #2
0
    def __call__(self, restore_state):
        if not toggles.RELATED_LOCATIONS.enabled(restore_state.domain):
            return []

        restore_user = restore_state.restore_user
        user_locations = restore_user.get_sql_locations(restore_user.domain)
        related_location_ids = LocationRelation.from_locations(user_locations)
        related_location_pks = (
            SQLLocation.objects.filter(location_id__in=related_location_ids)
            .values_list('pk', flat=True)
        )
        locations_queryset = _location_queryset_helper(restore_user.domain, list(related_location_pks))
        data_fields = _get_location_data_fields(restore_user.domain)
        return self.serializer.get_xml_nodes(self.id, restore_user, locations_queryset, data_fields)
Beispiel #3
0
def get_location_fixture_queryset(user):
    if toggles.SYNC_ALL_LOCATIONS.enabled(user.domain):
        return SQLLocation.active_objects.filter(domain=user.domain).prefetch_related('location_type')

    user_locations = user.get_sql_locations(user.domain)

    if user_locations.query.is_empty():
        return user_locations

    user_location_ids = list(user_locations.order_by().values_list("id", flat=True))

    if toggles.RELATED_LOCATIONS.enabled(user.domain):
        # Retrieve all of the locations related to a user's location and child
        # location and add them to the flat fixture
        related_location_ids = LocationRelation.from_locations(
            SQLLocation.objects.get_descendants(Q(domain=user.domain, id__in=user_location_ids))
        )
        user_location_ids.extend(
            list(SQLLocation.objects.filter(location_id__in=related_location_ids).values_list('id', flat=True))
        )

    return _location_queryset_helper(user.domain, user_location_ids)