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


Python Contact.get_or_create_by_urns方法代码示例

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


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

示例1: create_contact

# 需要导入模块: from temba.contacts.models import Contact [as 别名]
# 或者: from temba.contacts.models.Contact import get_or_create_by_urns [as 别名]
    def create_contact(self, name=None, number=None, twitter=None, twitterid=None, urn=None, is_test=False, **kwargs):
        """
        Create a contact in the master test org
        """
        urns = []
        if number:
            urns.append(URN.from_tel(number))
        if twitter:
            urns.append(URN.from_twitter(twitter))
        if twitterid:
            urns.append(URN.from_twitterid(twitterid))
        if urn:
            urns.append(urn)

        if not name and not urns:  # pragma: no cover
            raise ValueError("Need a name or URN to create a contact")

        kwargs["name"] = name
        kwargs["urns"] = urns
        kwargs["is_test"] = is_test

        if "org" not in kwargs:
            kwargs["org"] = self.org
        if "user" not in kwargs:
            kwargs["user"] = self.user

        return Contact.get_or_create_by_urns(**kwargs)
开发者ID:mxabierto,项目名称:rapidpro,代码行数:29,代码来源:base.py

示例2: save

# 需要导入模块: from temba.contacts.models import Contact [as 别名]
# 或者: from temba.contacts.models.Contact import get_or_create_by_urns [as 别名]
    def save(self):
        """
        Update our contact
        """
        name = self.validated_data.get("name")
        language = self.validated_data.get("language")
        urns = self.validated_data.get("urns")
        groups = self.validated_data.get("groups")
        custom_fields = self.validated_data.get("fields")

        changed = []

        if self.instance:
            # update our name and language
            if "name" in self.validated_data and name != self.instance.name:
                self.instance.name = name
                changed.append("name")
            if "language" in self.validated_data and language != self.instance.language:
                self.instance.language = language
                changed.append("language")

            if changed:
                self.instance.save(update_fields=changed, handle_update=True)

            if "urns" in self.validated_data and urns is not None:
                self.instance.update_urns(self.context["user"], urns)

        else:
            self.instance = Contact.get_or_create_by_urns(
                self.context["org"], self.context["user"], name, urns=urns, language=language
            )

        # update our fields
        if custom_fields is not None:
            self.instance.set_fields(user=self.context["user"], fields=custom_fields)

        # update our groups
        if groups is not None:
            self.instance.update_static_groups(self.context["user"], groups)

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


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