當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。