当前位置: 首页>>代码示例>>Python>>正文


Python URN.identity方法代码示例

本文整理汇总了Python中temba.contacts.models.URN.identity方法的典型用法代码示例。如果您正苦于以下问题:Python URN.identity方法的具体用法?Python URN.identity怎么用?Python URN.identity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在temba.contacts.models.URN的用法示例。


在下文中一共展示了URN.identity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: normalize_urn

# 需要导入模块: from temba.contacts.models import URN [as 别名]
# 或者: from temba.contacts.models.URN import identity [as 别名]
    def normalize_urn(self, value):
        if self.request.user.get_org().is_anon:
            raise InvalidQueryError("URN lookups not allowed for anonymous organizations")

        try:
            return URN.identity(URN.normalize(value))
        except ValueError:
            raise InvalidQueryError("Invalid URN: %s" % value)
开发者ID:teehamaral,项目名称:rapidpro,代码行数:10,代码来源:views_base.py

示例2: get_object

# 需要导入模块: from temba.contacts.models import URN [as 别名]
# 或者: from temba.contacts.models.URN import identity [as 别名]
    def get_object(self, value):
        # try to normalize as URN but don't blow up if it's a UUID
        try:
            as_urn = URN.identity(URN.normalize(value))
        except ValueError:
            as_urn = value

        contact_ids_with_urn = list(ContactURN.objects.filter(identity=as_urn).values_list("contact_id", flat=True))

        return self.get_queryset().filter(Q(uuid=value) | Q(id__in=contact_ids_with_urn)).first()
开发者ID:teehamaral,项目名称:rapidpro,代码行数:12,代码来源:fields.py

示例3: validate

# 需要导入模块: from temba.contacts.models import URN [as 别名]
# 或者: from temba.contacts.models.URN import identity [as 别名]
    def validate(self, data):
        if data.get("urns") is not None and data.get("phone") is not None:
            raise serializers.ValidationError("Cannot provide both urns and phone parameters together")

        if data.get("group_uuids") is not None and data.get("groups") is not None:
            raise serializers.ValidationError(
                "Parameter groups is deprecated and can't be used together with group_uuids"
            )

        if self.org.is_anon and self.instance and self.parsed_urns is not None:
            raise serializers.ValidationError("Cannot update contact URNs on anonymous organizations")

        if self.parsed_urns is not None:
            # look up these URNs, keeping track of the contacts that are connected to them
            urn_contacts = set()
            country = self.org.get_country_code()

            for parsed_urn in self.parsed_urns:
                normalized_urn = URN.identity(URN.normalize(parsed_urn, country))
                urn = ContactURN.objects.filter(org=self.org, identity__exact=normalized_urn).first()
                if urn and urn.contact:
                    urn_contacts.add(urn.contact)

            if len(urn_contacts) > 1:
                raise serializers.ValidationError(_("URNs are used by multiple contacts"))

            contact_by_urns = urn_contacts.pop() if len(urn_contacts) > 0 else None

            if self.instance and contact_by_urns and contact_by_urns != self.instance:  # pragma: no cover
                raise serializers.ValidationError(_("URNs are used by other contacts"))
        else:
            contact_by_urns = None

        contact = self.instance or contact_by_urns

        # if contact is blocked, they can't be added to groups
        if contact and contact.is_blocked and self.group_objs:
            raise serializers.ValidationError("Cannot add blocked contact to groups")

        return data
开发者ID:teehamaral,项目名称:rapidpro,代码行数:42,代码来源:serializers.py


注:本文中的temba.contacts.models.URN.identity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。