本文整理汇总了Python中models.Contact.getByName方法的典型用法代码示例。如果您正苦于以下问题:Python Contact.getByName方法的具体用法?Python Contact.getByName怎么用?Python Contact.getByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Contact
的用法示例。
在下文中一共展示了Contact.getByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getByName [as 别名]
def post(self):
user = json.loads(self.request.body)
if not phonenumberutils.validateNumber(user['phoneNumber']):
raise errors.ValidationError("Invalid phone number.")
#return validationError(self.response, 'Invalid number ' + user['phoneNumber'])
if not user['name']:
raise errors.ValidationError("Name is required.")
# Make sure we're not duplicating another contact
existingContact = Contact.getByName(user['name'])
if existingContact:
raise errors.ValidationError('User already exists with name ' + user['name'])
existingContact = Contact.getByPhoneNumber(user['phoneNumber'])
if existingContact:
raise errors.ValidationError('User ' + existingContact.name +
' already exists with number ' + existingContact.phoneNumber)
logging.info("Creating contact " + user["name"])
contact = Contact(
name = user['name'].lower(),
phoneNumber = phonenumberutils.toPrettyNumber(user['phoneNumber']),
normalizedPhoneNumber = phonenumberutils.toNormalizedNumber(user['phoneNumber']))
Contact.update(contact)
xmppVoiceMail.sendXmppInvite(contact.name)
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps(contact.toDict()))
示例2: _forwardToSms
# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import getByName [as 别名]
def _forwardToSms(self, to, messageBody):
toName = to.split("@")[0]
contact = Contact.getByName(toName)
if not contact:
raise InvalidParametersException("Unknown contact " + toName)
toNumber, body = self._getNumberAndBody(contact, messageBody)
self._communications.sendSMS(self._owner.phoneNumber, toNumber, body)
self._log(LogItem.FROM_OWNER, contact, body)