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


Python Contact.getDefaultSender方法代码示例

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


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

示例1: setUp

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def setUp(self):
        # Set up Google App Engine testbed
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_app_identity_stub()

        self.contactNumber = "+16135551234"

        # Set up some handy constants
        self._APP_ID = app_identity.get_application_id()
        self.MAIL_SUFFIX = "@" + self._APP_ID + ".appspotmail.com"
        self.XMPP_SUFFIX = "@" + self._APP_ID + ".appspotchat.com"

        self.ownerPhoneNumber = "+16135554444"
        self.ownerJid = "[email protected]"
        self.ownerEmailAddress = "[email protected]"
        self.owner = Owner(self.ownerPhoneNumber, self.ownerJid, self.ownerEmailAddress)
        self.xmppvoicemail = XmppVoiceMail(self.owner)
        self.communications = self.xmppvoicemail._communications = CommunicationsFixture()

        # Subscribe the default sender.
        defaultSender = Contact.getDefaultSender()
        defaultSender.subscribed = True
        Contact.update(defaultSender)
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:28,代码来源:xmppvoicemail_test.py

示例2: main

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
def main():
    routes = [
        (r'/recording', PostRecording),
        (r'/call', CallHandler),
        (r'/sms', SMSHandler),
        
        (r'/api/login', LoginHandler),
        (r'/api/admin/contacts', AdminContactsHandler),
        (r'/api/admin/contacts/(.*)', AdminContactsHandler),
        (r'/api/admin/log', AdminLogHandler),
        (r'/api/invite', InviteHandler),
        (r'/api/sendSms', SendSmsHandler),
        
        (r'/_ah/xmpp/message/chat/', XMPPHandler),
        (r'/_ah/xmpp/presence/(available|unavailable)/', XmppPresenceHandler),
        (r'/_ah/xmpp/subscription/(subscribe|subscribed|unsubscribe|unsubscribed)/', XmppSubscribeHandler),
        
        MailHandler.mapping(),
    ]

    webapp2Config = {}
    webapp2Config['webapp2_extras.sessions'] = {
        'secret_key': config.SESSION_SECRET_KEY,
    }
            
    app = webapp2.WSGIApplication(routes=routes, debug=True, config=webapp2Config)
    app.error_handlers[404] = handle_404
    app.error_handlers[500] = handle_500

    # Send an invite for the default sender if the default sender is not subscribed.
    defaultSender = Contact.getDefaultSender()
    if not defaultSender.subscribed:
        xmppVoiceMail.sendXmppInvite(defaultSender.name)
       
    return app
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:37,代码来源:main.py

示例3: test_incomingXmppFromBadUser

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def test_incomingXmppFromBadUser(self):
        """
        Test an incoming email to the default sender with a number in the message body.
        """
        with self.assertRaises(PermissionException):
            defaultSender = Contact.getDefaultSender()

            self.xmppvoicemail.handleIncomingXmpp(
                sender="[email protected]", to=defaultSender.name + self.XMPP_SUFFIX, messageBody="(613)555-1235: Hello"
            )
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:12,代码来源:xmppvoicemail_test.py

示例4: getDisplayNameAndContact

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
 def getDisplayNameAndContact(self, number):
     displayName = toPrettyNumber(number)
     
     # Find the XMPP user to send this from
     contact = Contact.getByPhoneNumber(number)
     if contact:
         displayName = contact.name
     else:
         contact = Contact.getDefaultSender()
         
     return (displayName, contact)
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:13,代码来源:xmppvoicemail.py

示例5: test_incomingXmppForInvalidNumber

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def test_incomingXmppForInvalidNumber(self):
        """
        Test an incoming XMPP to the default sender, with an invalid number
        in the body.
        """
        with self.assertRaises(InvalidParametersException):
            defaultSender = Contact.getDefaultSender()

            self.xmppvoicemail.handleIncomingXmpp(
                sender=self.ownerJid, to=defaultSender.name + self.XMPP_SUFFIX, messageBody="(613)555-123a: Hello"
            )
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:13,代码来源:xmppvoicemail_test.py

示例6: _sendXMPPMessage

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def _sendXMPPMessage(self, message, fromContact=None, fromNumber=None):
        if not fromContact:
            fromContact = Contact.getDefaultSender()

        # Add the fromNumber to the message if this is from the default sender.
        if fromContact.isDefaultSender() and fromNumber:
            message = toPrettyNumber(fromNumber) + ": " + message

        logging.debug("Sending XMPP message to " + self._owner.jid + ": " + message)

        fromJid = fromContact.name + "@" + self._APP_ID + ".appspotchat.com"
        return self._communications.sendXmppMessage(fromJid, self._owner.jid, message)
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:14,代码来源:xmppvoicemail.py

示例7: handleIncomingCall

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
 def handleIncomingCall(self, fromNumber, callStatus):
     """Handle an incoming call.
     """
     displayFrom = toPrettyNumber(fromNumber)
     
     # Find the XMPP user to send this from
     contact = Contact.getByPhoneNumber(fromNumber)
     if contact:
         displayFrom = contact.name
     else:
         contact = Contact.getDefaultSender()
         
     self.sendMessageToOwner("Call from: " + displayFrom + " status:" + callStatus, contact, fromNumber)
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:15,代码来源:xmppvoicemail.py

示例8: get

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def get(self):
        answer = []

        # Always put the default sender at the top.
        defaultSender = Contact.getDefaultSender()
        answer.append(defaultSender.toDict())

        contacts = Contact.all()
        contacts.filter('__key__ !=', defaultSender.key())
        
        for contact in contacts:
            answer.append(contact.toDict())
            
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(answer))
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:17,代码来源:main.py

示例9: test_incomingSmsMessageFromUnknownUserSubscribed

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def test_incomingSmsMessageFromUnknownUserSubscribed(self):
        """
        Tests an incoming SMS message from an unknown user with xmppVoiceMail subscribed.
        """
        defaultSender = Contact.getDefaultSender()

        # Send the SMS
        self.xmppvoicemail.handleIncomingSms("+16135551234", self.ownerPhoneNumber, "Hello")

        # Should get an XMPP from the default sender.
        self.assertEqual(1, len(self.communications.xmppMessages), "Should have sent an XMPP message")
        message = self.communications.xmppMessages[0]
        self.assertEqual(defaultSender.name + self.XMPP_SUFFIX, message["fromJid"])
        self.assertEqual(self.ownerJid, message["toJid"])
        self.assertEqual("(613)555-1234: Hello", message["message"])
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:17,代码来源:xmppvoicemail_test.py

示例10: test_incomingXmppForNumber

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def test_incomingXmppForNumber(self):
        """
        Test an incoming XMPP to the default sender, with a number in the body.
        """
        defaultSender = Contact.getDefaultSender()

        self.xmppvoicemail.handleIncomingXmpp(
            sender=self.ownerJid, to=defaultSender.name + self.XMPP_SUFFIX, messageBody="(613)555-1234: Hello"
        )

        # Should send an SMS to 555-1234
        self.assertEqual(1, len(self.communications.sms), "Should have sent an SMS")
        sms = self.communications.sms[0]
        self.assertEqual("+16135551234", sms["toNumber"])
        self.assertEqual("Hello", sms["body"])
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:17,代码来源:xmppvoicemail_test.py

示例11: test_incomingEmailFromBadUser

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def test_incomingEmailFromBadUser(self):
        """
        Test an incoming email to the default sender with a number in the message body.
        """
        with self.assertRaises(PermissionException):
            defaultSender = Contact.getDefaultSender()

            self.xmppvoicemail.handleIncomingEmail(
                sender="[email protected]",
                to=defaultSender.name + self.XMPP_SUFFIX,
                subject="Foo",
                messageBody="16135551234: Hello",
            )

        # We don't deal with terrorists:
        self.assertEqual(0, len(self.communications.mails))
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:18,代码来源:xmppvoicemail_test.py

示例12: test_incomingSmsMessageFromUnknownUser

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def test_incomingSmsMessageFromUnknownUser(self):
        """
        Tests an incoming SMS message from an unknown user with xmppVoiceMail unsubscribed.
        """
        # Unsubscribe the default sender.
        defaultSender = Contact.getDefaultSender()
        defaultSender.subscribed = False
        Contact.update(defaultSender)

        # Send the SMS
        self.xmppvoicemail.handleIncomingSms("+16135551234", self.ownerPhoneNumber, "Hello")

        # Should get an email, since user is not subscribed to xmppVoiceMail via XMPP.
        self.assertEqual(1, len(self.communications.mails), "Should have sent an email.")
        message = self.communications.mails[0]
        self.assertEqual('"' + defaultSender.name + '" <16135551234' + self.MAIL_SUFFIX + ">", message["sender"])
        self.assertEqual(self.ownerEmailAddress, message["to"])
        self.assertEqual("Hello", message["subject"])
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:20,代码来源:xmppvoicemail_test.py

示例13: test_incomingEmailForNumber

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def test_incomingEmailForNumber(self):
        """
        Test an incoming email to the default sender with a number in the message body.
        """
        defaultSender = Contact.getDefaultSender()

        self.xmppvoicemail.handleIncomingEmail(
            sender=self.ownerEmailAddress,
            to=defaultSender.name + self.XMPP_SUFFIX,
            subject="Foo",
            messageBody="16135551234: Hello",
        )

        # Should send an SMS to 555-1234
        self.assertEqual(1, len(self.communications.sms), "Should have sent an SMS")
        sms = self.communications.sms[0]
        self.assertEqual("+16135551234", sms["toNumber"])
        self.assertEqual("Hello", sms["body"])
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:20,代码来源:xmppvoicemail_test.py

示例14: sendMessageToOwner

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def sendMessageToOwner(self, message, contact=None, fromNumber=None):
        """
        Send a message to the user who owns this XmppVoiceMail account.

        contact is the contact to send the message from.
        
        fromNumber is the phone number to send the message from if contact is
        the default sender.

        Returns True on success, False on failure.
        """
        answer = False

        defaultSender = Contact.getDefaultSender()
        if not contact:
            contact = defaultSender

        fromJid = contact.name  + "@" + self._APP_ID + ".appspotchat.com"
        xmppOnline = self._ownerXmppPresent(fromJid)
                
        sendByEmail = self._owner.emailEnabled() and ( (not xmppOnline) or \
                      ((not contact.subscribed) and (not defaultSender.subscribed)) ) 
                
        if sendByEmail:
            self.sendEmailMessageToOwner(
                subject=message,
                fromContact=contact,
                fromNumber=fromNumber)
            answer = True
             
        elif self._owner.xmppEnabled():
            if not contact.subscribed:
                # Need a subscribed contact for XMPP; use the default sender.
                contact = defaultSender

            result = self._sendXMPPMessage(
                message=message,
                fromContact=contact,
                fromNumber=fromNumber)
            answer = result == xmpp.NO_ERROR
                
        return answer
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:44,代码来源:xmppvoicemail.py

示例15: sendEmailMessageToOwner

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getDefaultSender [as 别名]
    def sendEmailMessageToOwner(self, subject, body=None, fromContact=None, fromNumber=None):
        if not body:
            body = ""

        if not fromContact:
            fromContact = Contact.getDefaultSender()

        fromName = fromContact.name
        if fromNumber:
            fromAddress = stripNumber(toNormalizedNumber(fromNumber))
        elif not fromContact.isDefaultSender():
            fromContact.normalizedPhoneNumber
        else:
            fromAddress = fromName
            
        logging.debug("Sending eMail message to " + self._owner.emailAddress + ": " + subject)

        fromAddress = '"' + fromName + '" <' + fromAddress + "@" + self._APP_ID + ".appspotmail.com>"
        self._communications.sendMail(
            sender=fromAddress,
            to=self._owner.emailAddress,
            subject=subject,
            body=body)
开发者ID:jwalton,项目名称:xmppvoicemail,代码行数:25,代码来源:xmppvoicemail.py


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