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()))