本文整理汇总了Python中django_messages.models.Message.save方法的典型用法代码示例。如果您正苦于以下问题:Python Message.save方法的具体用法?Python Message.save怎么用?Python Message.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_messages.models.Message
的用法示例。
在下文中一共展示了Message.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def save(self, sender, parent_msg=None):
if sender is None:
raise ValidationError(self.error_messages['empty_sender'], code='empty_sender')
recipients = self.cleaned_data['recipient']
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
for r in recipients:
msg = Message(
sender = sender,
recipient = r,
subject = subject,
body = body,
)
if parent_msg is not None:
msg.parent_msg = parent_msg
parent_msg.replied_at = timezone.now()
parent_msg.save()
msg.save()
message_list.append(msg)
if notification:
if parent_msg is not None:
notification.send([sender], "messages_replied", {'message': msg,})
notification.send([r], "messages_reply_received", {'message': msg,})
else:
notification.send([sender], "messages_sent", {'message': msg,})
notification.send([r], "messages_received", {'message': msg,})
return message_list
示例2: save
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def save(self, parent_msg=None):
# recipients = self.cleaned_data['recipient']
recipient = self.cleaned_data['recipient']
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
# for r in recipients:
r = recipient
if True:
msg = Message(
sender = self.sender,
recipient = r,
subject = subject,
body = body,
)
if parent_msg is not None:
msg.parent_msg = parent_msg
parent_msg.replied_at = datetime.datetime.now()
parent_msg.save()
msg.conversation = parent_msg.conversation
msg.save()
# FIXME: workaround to make sure msg.conversation is saved
# even when creating a new conversation
if not msg.conversation:
msg.conversation = msg
msg.save()
return msg
示例3: save
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def save(self, sender, parent_msg=None):
recipients = self.cleaned_data['recipient']
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
for r in recipients:
msg = Message(
sender=sender,
recipient=r,
subject=subject,
body=body,
)
if parent_msg is not None:
msg.parent_msg = parent_msg
parent_msg.replied_at = timezone.now()
parent_msg.save()
msg.save()
message_list.append(msg)
UserOnBoardNotification.objects.create(user=r, title="Nachricht", notify_typ="info",
notify_message="Hallo, " + str(
sender) + " hat Ihnen eine Nachricht zugesendet!")
UserOnBoardNotification.objects.create(user=sender, title="Nachricht", notify_typ="info",
notify_message="Ihr Nachricht wurde erfolgreich versendet!")
if notification:
if parent_msg is not None:
notification.send([sender], "messages_replied", {'message': msg, })
notification.send([r], "messages_reply_received", {'message': msg, })
else:
notification.send([sender], "messages_sent", {'message': msg, })
notification.send([r], "messages_received", {'message': msg, })
return message_list
示例4: save
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def save(self, sender, parent_msg=None):
recipients = self.cleaned_data['recipient']
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
for r in recipients:
msg = Message(
sender = sender,
recipient = r,
subject = subject,
body = body,
)
if parent_msg is not None:
msg.parent_msg = parent_msg
parent_msg.replied_at = datetime.datetime.now()
parent_msg.save()
msg.save()
message_list.append(msg)
if notification:
if parent_msg is not None:
notification.send([sender], "messages_replied", {'message': msg,})
notification.send([r], "messages_reply_received", {'message': msg,})
else:
notification.send([sender], "messages_sent", {'message': msg,})
notification.send([r], "messages_received", {'message': msg,})
return message_list
示例5: send_message
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def send_message(request,msg_body,msg_subject,msg_receiver):
'''
JSON-RPC view : meow.sendMsg
Returns True, if the currently authenticated user is successful in sending the message.
Inbound parameters: test string 'msg_body' & 'msg_subject'. text string 'msg_receiver' shld
be username of MEOW user.
Requires authentication to call this function.
'''
try:
logging.debug('start meow.sendMsg with %s %s %s ' % (msg_body,msg_subject,msg_receiver))
msg_receiver_user = User.objects.all().filter(username=msg_receiver)
if len(msg_receiver_user) != 1:
return False
msg_receiver_user = msg_receiver_user[0]
logging.debug(" MSG %s %s %s %s " % (request.user, msg_receiver_user, msg_subject, msg_body))
msg = Message(
sender = request.user,
recipient = msg_receiver_user,
subject = msg_subject,
body = msg_body,
)
msg.save()
return True
except:
logging.error('meow.sendMsg got exception')
return False
示例6: save
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def save(self, sender, parent_msg=None):
recipients = self.cleaned_data['recipient']
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
final_recipients = set()
for r in recipients:
if isinstance(r, User):
final_recipients.add(r)
elif isinstance(r, Group):
[final_recipients.add(u) for u in r.user_set.all()]
else:
raise NotImplementedError
for r in final_recipients:
msg = Message(
sender = sender,
recipient = r,
subject = subject,
body = body,
)
if parent_msg is not None:
msg.parent_msg = parent_msg
parent_msg.replied_at = datetime.datetime.now()
parent_msg.save()
msg.save()
message_list.append(msg)
if notification:
if parent_msg is not None:
notification.send([sender], "messages_replied", {'message': msg,})
notification.send([r], "messages_reply_received", {'message': msg,})
else:
notification.send([sender], "messages_sent", {'message': msg,})
notification.send([r], "messages_received", {'message': msg,})
return message_list
示例7: send_reply
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def send_reply(request,msg_body,msg_subject,msg_receiver,parent_id):
'''
JSON-RPC view : meow.sendMsgReply
Returns True, if the currently authenticated user is successful in sending the reply message.
Inbound parameters: test string 'msg_body' & 'msg_subject'. text string 'msg_receiver' shld
be username of MEOW user, 'parent_id' shld be the msg id of an existing mesage.
Requires authentication to call this function.
'''
try:
logging.debug('start meow.sendMsgReply with %s %s %s %d ' % (msg_body,msg_subject,msg_receiver, parent_id))
msg_receiver_user = User.objects.all().filter(username=msg_receiver)
if len(msg_receiver_user) != 1:
return False
msg_receiver_user = msg_receiver_user[0]
logging.debug(" MSG %s %s %s %s %d" % (request.user, msg_receiver_user, msg_subject, msg_body,parent_id))
msg = Message(
sender = request.user,
recipient = msg_receiver_user,
subject = msg_subject,
body = msg_body,
)
parent_msg_obj = Message.objects.filter(id=parent_id)
if (len(parent_msg_obj)!=1):
return False
msg.parent_msg=parent_msg_obj[0]
msg.save()
return True
except:
logging.error('meow.sendMsgReply got exception')
return False
示例8: SendTestCase
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
class SendTestCase(TestCase):
fixtures = ['uploadeXe/fixtures/initial-model-data.json']
def setUp(self):
self.user1 = User.objects.create_user('user1', '[email protected]', '123456')
self.user2 = User.objects.create_user('user2', '[email protected]', '123456')
adminrole=Role.objects.get(pk=1)
self.user1_role=User_Roles(name="test", user_userid=self.user1, role_roleid=adminrole)
self.user1_role.save()
self.user2_role=User_Roles(name="test", user_userid=self.user2, role_roleid=adminrole)
self.user2_role.save()
mainorganisation = Organisation.objects.get(pk=1)
user_organisation1 = User_Organisations(user_userid=self.user1, organisation_organisationid=mainorganisation)
user_organisation1.save()
user_organisation2 = User_Organisations(user_userid=self.user2, organisation_organisationid=mainorganisation)
user_organisation2.save()
print(User.objects.all())
print(User_Roles.objects.all())
self.msg1 = Message(sender=self.user1, recipient=self.user2, subject='Subject Text', body='Body Text')
self.msg1.save()
def testBasic(self):
self.assertEqual(self.msg1.sender, self.user1)
self.assertEqual(self.msg1.recipient, self.user2)
self.assertEqual(self.msg1.subject, 'Subject Text')
self.assertEqual(self.msg1.body, 'Body Text')
self.assertEqual(self.user1.sent_messages.count(), 1)
self.assertEqual(self.user1.received_messages.count(), 0)
self.assertEqual(self.user2.received_messages.count(), 1)
self.assertEqual(self.user2.sent_messages.count(), 0)
示例9: report_spam
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def report_spam(request, content_type_id, object_id):
"""
Sends message and email to superuser regarding the object being flagged as spam.
"""
ctype = get_object_or_404(ContentType, pk=content_type_id)
object = get_object_or_404(ctype.model_class(), pk=object_id)
sender = request.user
r = User.objects.get(is_superuser=True)
subject = u"Spam Report"
body = str(request.build_absolute_uri(object.get_absolute_url()))
msg = Message(
sender = sender,
recipient = r,
subject = subject,
body = body,
)
msg.save()
if notification:
notification.send([sender], "messages_sent", {'message': msg,})
notification.send([r], "messages_received", {'message': msg,})
if request.is_ajax():
return HttpResponse('ok')
else:
return render_to_response('django_messages/report_spam.html', {}, RequestContext(request))
示例10: send_apply_messsage
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def send_apply_messsage(recipient, message, sender):
# subject = self.cleaned_data['subject']
msg = Message(
sender = sender,
recipient = recipient,
subject = "",
body = message,
)
msg.save()
return msg
示例11: send_message
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def send_message(self, sender, recipient, parent=None, conversation=None):
msg = Message(
sender=sender,
recipient=recipient,
subject='Subject Text',
body='Body Text',
parent_msg=parent,
conversation=conversation,
)
msg.save()
return msg
示例12: create
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def create(self, host_class, sender, recipient, subject, body):
from auxiliary import int_to_base36
print 'creating ', host_class, sender, recipient, subject, body
host_class_to_from = ','.join([int_to_base36(host_class.pk), sender.username, recipient.username])
m, c = self.get_or_create(host_class_to_from=host_class_to_from)
if c:
message = Message(sender=sender,recipient=recipient,subject=subject,body=body)
message.save()
m.message=message
m.save()
print 'created', m
return m
示例13: inbox
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
def inbox(request, template_name='django_messages/inbox.html'):
"""
Displays a list of received messages for the current user.
Optional Arguments:
``template_name``: name of the template to use.
"""
message_list = Message.objects.inbox_for(request.user)
if request.method == 'POST':
data = request.POST
msg = Message(body=data['body'], subject="default", sender=request.user, recipient=data['recipient'], sent_at=datetime.datetime.now())
msg.save()
return render_to_response(template_name, {
'message_list': message_list,
}, context_instance=RequestContext(request))
示例14: DeleteTestCase
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
class DeleteTestCase(TestCase):
def setUp(self):
self.user1 = User.objects.create_user(
'user3', '[email protected]', '123456')
self.user2 = User.objects.create_user(
'user4', '[email protected]', '123456')
self.msg1 = Message(sender=self.user1, recipient=self.user2,
subject='Subject Text 1', body='Body Text 1')
self.msg2 = Message(sender=self.user1, recipient=self.user2,
subject='Subject Text 2', body='Body Text 2')
self.msg1.sender_deleted_at = timezone.now()
self.msg2.recipient_deleted_at = timezone.now()
self.msg1.save()
self.msg2.save()
def testBasic(self):
self.assertEqual(Message.objects.outbox_for(self.user1).count(), 1)
self.assertEqual(
Message.objects.outbox_for(self.user1)[0].subject,
'Subject Text 2'
)
self.assertEqual(Message.objects.inbox_for(self.user2).count(), 1)
self.assertEqual(
Message.objects.inbox_for(self.user2)[0].subject,
'Subject Text 1'
)
#undelete
self.msg1.sender_deleted_at = None
self.msg2.recipient_deleted_at = None
self.msg1.save()
self.msg2.save()
self.assertEqual(Message.objects.outbox_for(self.user1).count(), 2)
self.assertEqual(Message.objects.inbox_for(self.user2).count(), 2)
示例15: SendTestCase
# 需要导入模块: from django_messages.models import Message [as 别名]
# 或者: from django_messages.models.Message import save [as 别名]
class SendTestCase(TestCase):
def setUp(self):
self.user1 = User.objects.create_user('user1', '[email protected]', '123456')
self.user2 = User.objects.create_user('user2', '[email protected]', '123456')
self.msg1 = Message(sender=self.user1, recipient=self.user2, body='Body Text')
self.msg1.save()
def testBasic(self):
self.assertEquals(self.msg1.sender, self.user1)
self.assertEquals(self.msg1.recipient, self.user2)
self.assertEquals(self.msg1.body, 'Body Text')
self.assertEquals(self.user1.sent_messages.count(), 1)
self.assertEquals(self.user1.received_messages.count(), 0)
self.assertEquals(self.user2.received_messages.count(), 1)
self.assertEquals(self.user2.sent_messages.count(), 0)