Ejemplo n.º 1
0
    def get_queryset(self):
        queryset = self.get_base_queryset(self.request)

        before = self.request.query_params.get("before", None)
        if before:
            try:
                before = iso8601.parse_date(before)
                queryset = queryset.filter(modified_on__lte=before)
            except Exception:  # pragma: needs cover
                queryset = queryset.filter(pk=-1)

        after = self.request.query_params.get("after", None)
        if after:
            try:
                after = iso8601.parse_date(after)
                queryset = queryset.filter(modified_on__gte=after)
            except Exception:  # pragma: needs cover
                queryset = queryset.filter(pk=-1)

        phones = splitting_getlist(self.request,
                                   "phone")  # deprecated, use urns
        if phones:
            queryset = queryset.filter(urns__path__in=phones,
                                       urns__scheme=TEL_SCHEME)

        urns = self.request.query_params.getlist("urns", None)
        if urns:
            queryset = queryset.filter(urns__identity__in=urns)

        groups = self.request.query_params.getlist(
            "group", None)  # deprecated, use group_uuids
        if groups:
            queryset = queryset.filter(
                all_groups__name__in=groups,
                all_groups__group_type=ContactGroup.TYPE_USER_DEFINED)

        group_uuids = self.request.query_params.getlist("group_uuids", None)
        if group_uuids:
            queryset = queryset.filter(
                all_groups__uuid__in=group_uuids,
                all_groups__group_type=ContactGroup.TYPE_USER_DEFINED)

        uuids = self.request.query_params.getlist("uuid", None)
        if uuids:
            queryset = queryset.filter(uuid__in=uuids)

        # can't prefetch a custom manager directly, so here we prefetch user groups as new attribute
        user_groups_prefetch = Prefetch(
            "all_groups",
            queryset=ContactGroup.user_groups.all(),
            to_attr="prefetched_user_groups")

        return queryset.select_related("org").prefetch_related(
            user_groups_prefetch).order_by("-modified_on", "pk")
Ejemplo n.º 2
0
    def get_queryset(self):
        queryset = self.get_base_queryset(self.request)

        before = self.request.query_params.get('before', None)
        if before:
            try:
                before = json_date_to_datetime(before)
                queryset = queryset.filter(modified_on__lte=before)
            except Exception:  # pragma: needs cover
                queryset = queryset.filter(pk=-1)

        after = self.request.query_params.get('after', None)
        if after:
            try:
                after = json_date_to_datetime(after)
                queryset = queryset.filter(modified_on__gte=after)
            except Exception:  # pragma: needs cover
                queryset = queryset.filter(pk=-1)

        phones = splitting_getlist(self.request,
                                   'phone')  # deprecated, use urns
        if phones:
            queryset = queryset.filter(urns__path__in=phones,
                                       urns__scheme=TEL_SCHEME)

        urns = self.request.query_params.getlist('urns', None)
        if urns:
            queryset = queryset.filter(urns__identity__in=urns)

        groups = self.request.query_params.getlist(
            'group', None)  # deprecated, use group_uuids
        if groups:
            queryset = queryset.filter(
                all_groups__name__in=groups,
                all_groups__group_type=ContactGroup.TYPE_USER_DEFINED)

        group_uuids = self.request.query_params.getlist('group_uuids', None)
        if group_uuids:
            queryset = queryset.filter(
                all_groups__uuid__in=group_uuids,
                all_groups__group_type=ContactGroup.TYPE_USER_DEFINED)

        uuids = self.request.query_params.getlist('uuid', None)
        if uuids:
            queryset = queryset.filter(uuid__in=uuids)

        # can't prefetch a custom manager directly, so here we prefetch user groups as new attribute
        user_groups_prefetch = Prefetch(
            'all_groups',
            queryset=ContactGroup.user_groups.all(),
            to_attr='prefetched_user_groups')

        return queryset.select_related('org').prefetch_related(
            user_groups_prefetch).order_by('-modified_on', 'pk')
Ejemplo n.º 3
0
    def get_queryset(self):
        queryset = self.get_base_queryset(self.request)

        before = self.request.query_params.get("before", None)
        if before:
            try:
                before = iso8601.parse_date(before)
                queryset = queryset.filter(modified_on__lte=before)
            except Exception:  # pragma: needs cover
                queryset = queryset.filter(pk=-1)

        after = self.request.query_params.get("after", None)
        if after:
            try:
                after = iso8601.parse_date(after)
                queryset = queryset.filter(modified_on__gte=after)
            except Exception:  # pragma: needs cover
                queryset = queryset.filter(pk=-1)

        phones = splitting_getlist(self.request, "phone")  # deprecated, use urns
        if phones:
            queryset = queryset.filter(urns__path__in=phones, urns__scheme=TEL_SCHEME)

        urns = self.request.query_params.getlist("urns", None)
        if urns:
            queryset = queryset.filter(urns__identity__in=urns)

        groups = self.request.query_params.getlist("group", None)  # deprecated, use group_uuids
        if groups:
            queryset = queryset.filter(
                all_groups__name__in=groups, all_groups__group_type=ContactGroup.TYPE_USER_DEFINED
            )

        group_uuids = self.request.query_params.getlist("group_uuids", None)
        if group_uuids:
            queryset = queryset.filter(
                all_groups__uuid__in=group_uuids, all_groups__group_type=ContactGroup.TYPE_USER_DEFINED
            )

        uuids = self.request.query_params.getlist("uuid", None)
        if uuids:
            queryset = queryset.filter(uuid__in=uuids)

        # can't prefetch a custom manager directly, so here we prefetch user groups as new attribute
        user_groups_prefetch = Prefetch(
            "all_groups", queryset=ContactGroup.user_groups.all(), to_attr="prefetched_user_groups"
        )

        return queryset.select_related("org").prefetch_related(user_groups_prefetch).order_by("-modified_on", "pk")