本文整理汇总了Python中rapidsms_httprouter.models.Message.save方法的典型用法代码示例。如果您正苦于以下问题:Python Message.save方法的具体用法?Python Message.save怎么用?Python Message.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapidsms_httprouter.models.Message
的用法示例。
在下文中一共展示了Message.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_message_without_batch
# 需要导入模块: from rapidsms_httprouter.models import Message [as 别名]
# 或者: from rapidsms_httprouter.models.Message import save [as 别名]
def create_message_without_batch(self, id, backend):
fake_connection = Connection(identity=str(id))
fake_connection.backend, created = Backend.objects.get_or_create(name=backend)
fake_connection.save()
message = Message(status='Q', direction="O")
message.text = "this is an important message"
message.connection = fake_connection
message.batch = None
message.save()
return message
示例2: create_message
# 需要导入模块: from rapidsms_httprouter.models import Message [as 别名]
# 或者: from rapidsms_httprouter.models.Message import save [as 别名]
def create_message(self, id, backend, batch=None):
fake_connection = Connection(identity=str(id))
fake_connection.backend, created = Backend.objects.get_or_create(name=backend)
fake_connection.save()
message = Message(status='Q', direction="O")
message.connection = fake_connection
message.batch = self.batch1 if batch is None else batch
message.save()
return message
示例3: handle
# 需要导入模块: from rapidsms_httprouter.models import Message [as 别名]
# 或者: from rapidsms_httprouter.models.Message import save [as 别名]
def handle (self, message):
escargot = 'mrs_autoreg'
match = None
matched = None
for keywd in settings.KEYWORDS_AND_SLUGS:
match = re.match(keywd, message.text, re.IGNORECASE)
if match:
escargot = settings.KEYWORDS_AND_SLUGS[keywd]
matched = message.text[len(match.group(0)):]
#message.text = matched
break
if escargot == 'mrs_opt_out':
if not message.connection.contact:
# Stop sending you nothing? :-p
return False
sps = ScriptProgress.objects.filter(connection = message.connection)
sps.delete()
sps = ScriptSession.objects.filter(connection = message.connection)
sps.delete()
message.connection.contact.interested = False
message.connection.contact.save()
# ScriptProgress.objects.create(
# script = Script.objects.get(slug = escargot),
# connection = message.connection)
msg = Message(connection = message.connection, status = 'Q', direction = 'O', text = 'You will no longer receive FREE messages from Mother Reminder. If you want to join again please send JOIN to 6400.')
msg.save()
return False
if (not message.connection.contact) or (not ScriptProgress.objects.filter(connection = message.connection)):
# if match:
if True: # Any word goes for registration.
message.connection.contact = Contact.objects.create(name='Anonymous User')
message.connection.contact.interested = True
message.connection.contact.last_menses = datetime.now() - timedelta(days = 45)
message.connection.contact.save()
message.connection.save()
ScriptProgress.objects.create(
script = Script.objects.get(slug = escargot),
connection = message.connection)
else:
msg = Message(connection = message.connection, status = 'Q', direction = 'O', text = "You just contacted Mother Reminder. Did you know that pregnant women should go to the health clinic 4 times during preganancy? Stay Healthy!")
msg.save()
return False
else:
if ScriptProgress.objects.filter(connection = message.connection):
return False
if match and escargot == 'mrs_autoreg':
msg = Message(connection = message.connection, status = 'Q', direction = 'O', text = "You just contacted Mother Reminder. Did you know that pregnant women should go to the health clinic 4 times during preganancy? Stay Healthy!")
msg.save()
else:
msg = Message(connection = message.connection, status = 'Q', direction = 'O', text = "You just contacted Mother Reminder. Did you know that pregnant women should go to the health clinic 4 times during preganancy? Stay Healthy!")
msg.save()
return False
示例4: handle
# 需要导入模块: from rapidsms_httprouter.models import Message [as 别名]
# 或者: from rapidsms_httprouter.models.Message import save [as 别名]
def handle(self, **options):
text = options.get('text') or 'If you want to stop receiving FREE messages from Mother Reminder please reply with STOP.'
outmsgs = ReminderMessage.as_hash().keys()
outmsgs.sort()
try:
lastweek = outmsgs[-1]
query = Contact.objects.filter(interested = True).exclude(connection = None)
if not options.get('all'):
query.filter(last_menses__lt = (datetime.now() - timedelta(weeks=lastweek)))
for mother in query:
last_optout = Message.objects.filter(connection=mother.default_connection).filter(text=text).order_by('-date')
message = Message(connection = mother.default_connection, direction = 'O', status = 'Q', text = text)
if not last_optout:
message.save()
else:
if last_optout[0].date + timedelta(weeks=8) <= datetime.now():
message.save()
# msg.save()
# application, batch, connection, date, direction, flags, id, in_response_to, poll, poll_responses, priority, responses, status, submissions, text
except IndexError:
pass