本文整理汇总了Python中messages.models.Message类的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: save
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
开发者ID:phastafrican,项目名称:lernanta,代码行数:25,代码来源:forms.py
示例2: save
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
开发者ID:foxtrotcharlie,项目名称:lernanta,代码行数:28,代码来源:forms.py
示例3: post
def post(self, request):
ls = json.loads(request.body)
# print ls
# save list json from request into DB
newList = List(owner=request.user, \
title=ls["title"], \
num_items=ls["number"], \
privacy=ls["privacy"])
newList.save()
for listItem in ls["list"]:
newListItem = ListItem(listid=newList, \
title=listItem["title"], \
descriptionhtml=listItem["description"], \
descriptionmeta=listItem["description_meta"])
newListItem.save()
slug_dict = {
'slug': newList.slug
}
for tagChoiceID in ls["tags"]:
newTopicTag = TopicTag(list=newList, topic=tagChoiceID)
newTopicTag.save()
friends = Friend.objects.friends(request.user)
for friend in friends:
list_notification = Message(type='LN', to_user=friend, from_user=request.user, content="I've added a new list called " + newList.title + ". Check it out!")
list_notification.save()
return HttpResponse(json.dumps(slug_dict), status=201, \
content_type='application/json')
开发者ID:UCR-CS179-Team7,项目名称:ListVerse,代码行数:31,代码来源:views.py
示例4: save
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
开发者ID:wd5,项目名称:Anklav,代码行数:26,代码来源:forms.py
示例5: save
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
开发者ID:livne,项目名称:Random-Yes,代码行数:31,代码来源:forms.py
示例6: save
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
开发者ID:su-danny,项目名称:famdates,代码行数:33,代码来源:forms.py
示例7: save
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
开发者ID:jakebarnwell,项目名称:PythonGenerator,代码行数:26,代码来源:forms.py
示例8: create_message
def create_message(request):
# only logged in users can write messages
if request.user.is_authenticated():
user_id = request.session['_auth_user_id']
if request.method == "GET":
context = {}
context.update(csrf(request))
if user_id:
user = User.objects.get(id=user_id)
username = user.username
context['username'] = username
return render_to_response("create_message.html", context)
else:
content = request.POST['message'].strip()
if content == '':
context = {}
context['error'] = "Message cannot be blank. Please try again."
context.update(csrf(request))
if user_id:
user = User.objects.get(id=user_id)
username = user.username
context['username'] = username
return render_to_response("create_message.html", context)
# create the message
message = Message(message=content, user_id=user_id)
message.save()
return redirect('/')
开发者ID:SheikGeek,项目名称:squawker,代码行数:27,代码来源:views.py
示例9: save
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
开发者ID:Suggsgested,项目名称:lernanta,代码行数:25,代码来源:forms.py
示例10: sendMessageFromiOS
def sendMessageFromiOS(request):
print 'sendMessageFromiOS'
try:
obj = simplejson.loads(request.raw_post_data)
print obj
msg = obj["message"]
message_text = msg["messageText"]
group = Group.objects.get(pk=obj["groupID"])
recipients = extract_recipients(request.user, group, message_text)
if "error" in recipients:
# send error message back to sender
send_message(recipients["error"], None, user, group)
data = {"errorMessage": recipients["error"]}
return HttpResponse(simplejson.dumps(error_code(50, data)),
mimetype='application/json')
recipients = recipients["recipients"]
# Create Message model instance and send out message
# TODO decomp this code chunk
message = Message(message_text=message_text, sender=request.user,
group=group)
create_ios_push_notification(message)
message.save()
for group_link in recipients:
recipient = group_link.user
message_link = MessageUserLink(message=message, recipient=recipient)
message_link.save()
send_message(message_text, request.user, recipient, group)
data = {"messageID": message.id}
return error_code(0, data)
except Exception, e:
print e
traceback.print_exc()
return error_code(1)
开发者ID:fangsterr,项目名称:Planamo-Django,代码行数:34,代码来源:views.py
示例11: add
def add(request):
text = request.REQUEST['main_message_input']
if '<a' in text:
return HttpResponseRedirect('/?notification='+urllib.quote('No <a href=> links please. You might be a spam bot'))
m = Message(text=text, votes=0, score=time.mktime(time.gmtime()))
m.save()
#return HttpResponseRedirect(reverse('messages.views.index'))
return HttpResponseRedirect('/?notification='+urllib.quote('you added: '+m.text))
开发者ID:bootandy,项目名称:happy-little-messages,代码行数:9,代码来源:views.py
示例12: setUp
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 = datetime.datetime.now()
self.msg2.recipient_deleted_at = datetime.datetime.now()
self.msg1.save()
self.msg2.save()
开发者ID:su-danny,项目名称:famdates,代码行数:9,代码来源:tests.py
示例13: show_mail_compose
def show_mail_compose(self, request):
try:
if request.is_ajax():
mail_sent_complete = False
if request.method == 'POST':
form = ComposeMailForm(request.POST)
if form.is_valid():
new_mail = Message()
user = request.user
new_mail.id_sender = user
user2 = User.objects.get(id= form.cleaned_data['user_id'])
new_mail.id_receiver = user2
new_mail.datetime = datetime.now()
new_mail.id_conversation = 1
new_mail.text = form.cleaned_data['text']
new_mail.subject = form.cleaned_data['subject']
new_mail.save()
form = ComposeMailForm()
mail_sent_complete = MAILSENTCOMPLETE
else:
form = ComposeMailForm()
week = {0:'Lunes',1:'Martes',2:'Miércoles',3:'Jueves',4:'Viernes',5:'Sábado',6:'Domingo'}
month = {0: 'Enero', 1:'Febrero',2:'Marzo',3:'Abril',4:'Mayo',5:'Junio',6:'Julio',7:'Agosto',8:'Septiembre',9:'Octubre',10:'Noviembre',11:'Diciembre'}
date_time = week[datetime.today().weekday()] + " " + str(datetime.today().day) + "/" + month[datetime.today().month - 1] + " " + str(datetime.today().year)
c = { 'form': form , 'date_t':date_time, 'mail_sent_complete' : mail_sent_complete}
c.update(csrf(request))
return render_to_response('user_send_mail.html', c)
else: return HttpResponseRedirect("/usuarios/profile/mail")
except Exception as e: return self.show_error(e)
开发者ID:gruizmir,项目名称:trueque,代码行数:30,代码来源:views.py
示例14: home
def home(request):
if 'text' in request.GET:
author_ = request.GET['author']
text_ = request.GET['text']
message = Message(author=author_, text=text_)
message.save()
messages = Message.objects.all()
return render(request, 'home.html', {'messages': messages})
开发者ID:niggin,项目名称:django-lectures,代码行数:11,代码来源:views.py
示例15: send_to_teams
def send_to_teams(self, team_ids, author):
subject = self.cleaned_data['subject']
content = self.cleaned_data['content']
content = u''.join([content, '\n\n', ugettext('This message is from site administrator.')])
users = User.objects.filter(teams__in=team_ids).exclude(pk=author.pk)
for user in users:
m = Message(author=author, user=user)
m.subject = subject
m.content = content
m.save()
return users.count()
开发者ID:adncentral,项目名称:unisubs,代码行数:11,代码来源:forms.py
示例16: run
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()
开发者ID:quinoescobar,项目名称:batucada,代码行数:11,代码来源:tasks.py
示例17: SendMessage
def SendMessage(profile, otherUserFacebookID, messageBody):
try:
sender = profile
recipient = Profile.objects.get(facebookID=otherUserFacebookID)
body = messageBody
message = Message(sender=sender, recipient=recipient,body=body)
message.save()
message_sent(message)
return True
except:
return False
开发者ID:sirkamran32,项目名称:mutuality,代码行数:11,代码来源:sendMessage.py
示例18: test_view_message
def test_view_message(self):
"""Test user can view message in inbox."""
Relationship(source=self.user, target_user=self.user_two).save()
message = Message(
sender=self.user_two.user,
recipient=self.user.user,
subject='test message subject',
body='test message body')
message.save()
self.client.login(username=self.test_username,
password=self.test_password)
response = self.client.get("/%s/messages/inbox/" % (self.locale,))
self.assertContains(response, 'test message body')
开发者ID:benrito,项目名称:batucada,代码行数:13,代码来源:tests.py
示例19: save
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
开发者ID:rmusina,项目名称:mentorat-alumni-bbu,代码行数:51,代码来源:forms.py
示例20: save
def save(self, new_data, request, user_to = None):
# current date
datetime_now = datetime.now()
# save topic
topic = Topic()
topic.theme = new_data['theme']
topic.user1 = request.user
if user_to is None:
user_to = User.objects.get(id = new_data['userToId'])
topic.user2 = user_to
topic.create_on = datetime_now
topic.update_on = datetime_now
topic.save()
# save message
message = Message()
message.user_from = topic.user1
message.user_to = topic.user2
message.topic = topic
message.body = new_data['body']
message.sent_on = datetime.now()
message.save()
return message
开发者ID:andrewkuzmych,项目名称:litclub,代码行数:27,代码来源:forms.py
注:本文中的messages.models.Message类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论