本文整理汇总了Python中messages.models.Message类的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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')
示例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
示例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
示例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
示例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
示例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('/')
示例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
示例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)
示例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))
示例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()
示例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)
示例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})
示例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()