本文整理汇总了Python中messages.models.Message.parent_msg方法的典型用法代码示例。如果您正苦于以下问题:Python Message.parent_msg方法的具体用法?Python Message.parent_msg怎么用?Python Message.parent_msg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类messages.models.Message
的用法示例。
在下文中一共展示了Message.parent_msg方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def save(self, sender, parent_msg=None):
r = self.cleaned_data['recipient']
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
r = User.objects.get(id=r)
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,})
else:
notification.send([sender], "messages_sent", {'message': msg,})
return message_list
示例2: save
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def save(self, sender, parent_msg=None):
project = self.cleaned_data['project']
try:
project = Project.objects.get(id=int(project))
except Project.DoesNotExist:
raise forms.ValidationError(
_(u'That study group does not exist.'))
recipients = project.participants()
subject = "[p2pu-%s] " % project.slug + self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
for r in recipients:
msg = Message(
sender=sender,
recipient=r.user.user,
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)
return message_list
示例3: save
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def save(self, sender, parent_msg=None):
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
for r in self.cleaned_data['recipient']:
try:
profile = r.get_profile()
if profile.blocked_users.filter(id=sender.id).exists():
continue
except:
pass
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:
pass
# 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 messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def save(self, sender, parent_msg=None):
if parent_msg is None:
recipients = sender.recipients.all()
else:
recipients = [parent_msg.sender]
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
token=''
message_list = []
for r in recipients:
msg = Message(
sender = sender,
recipient = r,
subject = subject,
body = body,
token = token,
)
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(recipients, "messages_reply_received", {'message': msg,})
else:
notification.send([sender], "messages_sent", {'message': msg,})
notification.send(recipients, "messages_received", {'message': msg,})
return message_list
示例5: save
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def save(self, sender, parent_msg=None):
project = self.cleaned_data['project']
try:
project = Project.objects.get(id=int(project))
except Project.DoesNotExist:
raise forms.ValidationError(_(u'That study group does not exist.'))
recipients = project.organizers()
subject = "[%s] " % project.name[:20] + self.cleaned_data['subject']
body = self.cleaned_data['body']
body = '%s\n\n%s' % (self.cleaned_data['body'], _('You received this message through the Contact Organizer form '
'at %(project)s: http://%(domain)s%(url)s') % {'project':project.name,
'domain':Site.objects.get_current().domain, 'url':project.get_absolute_url()})
message_list = []
for r in recipients:
msg = Message(
sender=sender,
recipient=r.user.user,
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)
return message_list
示例6: save
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def save(self, sender, parent_msg=None):
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
role = self.cleaned_data['recipient']
user = role.profile.user
msg = Message(
sender = sender,
recipient = user,
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)
send_mail(
u"Анклав: новое сообщение в личных",
u"Вам было послано сообщение. Вы можете прочитать его по ссылке http://%s%s" % (settings.DOMAIN, reverse('messages_inbox')),
settings.DEFAULT_FROM_EMAIL,
[user.email],
)
return message_list
示例7: save
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def save(self, sender, parent_msg=None):
project = self.cleaned_data['project']
try:
project = Project.objects.get(id=int(project))
except Project.DoesNotExist:
raise forms.ValidationError(
_(u'Hmm, that does not look like a valid course'))
recipients = project.followers()
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
for r in recipients:
msg = Message(
sender=sender,
recipient=r.user,
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)
return message_list
示例8: run
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def run(self, form, messages, **kwargs):
log = self.get_logger(**kwargs)
log.debug("Sending email to %d user(s)." % (len(messages),))
for message in messages:
(sender, recipient, subject, body, parent) = message
msg = Message(sender=sender, recipient=recipient, subject=subject, body=body)
if parent is not None:
msg.parent_msg = parent
parent.replied_at = datetime.datetime.now()
parent.save()
msg.save()
示例9: save
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [as 别名]
def save(self, sender, parent_msg=None):
recipients = self.cleaned_data['recipient']
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
send_to_email = self.cleaned_data['send_to_email']
send_to_students = self.cleaned_data['send_to_students']
send_to_mentors = self.cleaned_data['send_to_mentors']
if isinstance(recipients, str):
recipients = []
if send_to_students:
student_list = [stud.pk for stud in StudentProfile.objects.all()]
students_as_users = [u for u in User.objects.all().filter(user__profile__pk__in=student_list)]
recipients.extend(students_as_users)
if send_to_mentors:
mentor_list = [ment.pk for ment in MentorProfile.objects.all()]
mentors_as_users = [u for u in User.objects.all().filter(user__profile__pk__in=mentor_list)]
recipients.extend(mentors_as_users)
# filter only unique users
recipients = list(set(recipients))
message_list = []
if send_to_email:
recipient_emails = [r.get_profile().email for r in recipients]
for email in recipient_emails:
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [email], priority="high")
else:
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(recipients, "messages_reply_received", {'message': msg,})
else:
notification.send([sender], "messages_sent", {'message': msg,})
notification.send(recipients, "messages_received", {'message': msg,})
return message_list
示例10: save
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import parent_msg [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(recipients, "messages_reply_received", {"message": msg})
else:
notification.send([sender], "messages_sent", {"message": msg})
notification.send(recipients, "messages_received", {"message": msg})
return message_list