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


Python Customer.find_by_contact_number方法代码示例

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


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

示例1: get

# 需要导入模块: from models import Customer [as 别名]
# 或者: from models.Customer import find_by_contact_number [as 别名]
    def get(self, request):

        """


            summary: This endpoint is called by the ASMX server. It then publishes a push notification of
            the concerned agent on their cogent_agent_id

            Auth: Doesn't require the auth token in request headers

            ---

            serializer: CustomerDetailSerializer
            parameters:
                - name: contact_number
                  required: true
                  type: string
                - name: forwarded_for
                  required: true
                  type: string
                - name: agent_id
                  required: true
                  type: integer

            """

        client, order = None, False
        print "request from asmx server", request.query_params
        # TODO  Check for a B2B customer
        try:
            forwarded_for = request.query_params["forwarded_for"]
            if forwarded_for in B2BCall.keys():
                print forwarded_for
            # client = PhoneNumber.objects.filter(number= forwarded_for, number_type=NUMBER_TYPE[0][0])[0]
            from restaurant.models import Restaurant

            restaurant = Restaurant.objects.get(id=B2BCall[forwarded_for])
            client = ClientSerializer(instance=restaurant).data
        except (KeyError, IndexError):
            pass

        try:
            contact_number = request.query_params["contact_number"]
            customer = Customer.find_by_contact_number(contact_number=contact_number)

            customer_info = {"primary_number": contact_number, "name": "New Customer", "call_count": 1}

            if customer:
                customer.call_count += 1
                customer.save()
                customer_info = CustomerDetailSerializer(instance=customer).data

                order = customer.get_pending_order()

                if order:
                    order = OrderDetailViewSerializer(instance=order).data

                CallLog.log_call(customer, request.query_params["agent_id"])

            pusher = PushMessage(channel=request.query_params["agent_id"])
            print "pusher order ", order
            pusher.push(
                json.dumps({"client": client, "customer": customer_info, "order": order}, default=self.date_handler)
            )

            return JSONResponse({"customer": customer_info}, status=200)
        except Exception as e:
            print traceback.format_exc(e)
            beam(e, request)
            return JSONResponse({"Success": False}, status=200)
开发者ID:trolltartar,项目名称:nomnom,代码行数:72,代码来源:views.py


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