本文整理汇总了Python中models.Message.user方法的典型用法代码示例。如果您正苦于以下问题:Python Message.user方法的具体用法?Python Message.user怎么用?Python Message.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.user方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: store_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import user [as 别名]
def store_message(text, tagList, user, tags_required, private):
#Construct the message itself.
message = Message()
message.user = user
message.text = text
message.tags_required = tags_required
message.private = private
message.save()
#Store each tag.
for tag in tagList:
#Remove the prefix.
prefix = tag[0]
tag = tag[1:]
if prefix=="#":
if tag_exists(tag):
add_tag_to_message(tag, message)
else:
store_tag(tag, message)
elif prefix=="@":
if user_exists(tag):
add_user_to_message(tag, message);
else:
raise Exception("Tag has inapproriate prefix. Choices are '@' or '#'.")
message.save()
return message
示例2: detail_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import user [as 别名]
def detail_message(request, conv_id):
"""
view untuk menampilkan detail pesan
beserta percakapan
"""
conv = get_object_or_404(Conversation, id=conv_id, users=request.user, membership__deleted=False)
list_messages = Message.objects.filter(conversation=conv)
msg = list_messages[0]
if request.POST:
form = SendConversationForm(request.POST)
if form.is_valid():
msg = Message()
msg.conversation = conv
msg.user = request.user
msg.content = form.cleaned_data['content']
msg.save()
to2 = list(conv.users.all())
to2.remove(request.user)
notification.send(to2, 'new_message', {'user': request.user, 'message': conv})
messages.info(request, _('Message sent'))
return HttpResponseRedirect(conv.get_absolute_url())
else:
form = SendConversationForm()
return render_to_response('message/detail_message.html',
{"conv": conv,
'form': form,
'msg': msg,
'list_messages': list_messages},
context_instance=RequestContext(request))
示例3: store_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import user [as 别名]
def store_message(text, tagList, user, tags_required, private):
#Construct the message itself.
message = Message()
message.user = user
message.text = text
message.tags_required = tags_required
message.private = private
message.save()
#Store each tag.
for tag in tagList:
connect_tag(tag, message=message)
message.save()
return message
示例4: store_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import user [as 别名]
def store_message(text, tagList, user, tags_required):
#Construct the message itself.
message = Message()
message.user = user
message.text = text
message.tags_required = tags_required
message.save()
#Store each tag.
for new_tag in tagList:
if tag_exists(new_tag):
new_tag.message.add(message)
else:
store_tag(new_tag, message)
return message
示例5: create_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import user [as 别名]
def create_message(request, username=None):
"""
view untuk menampilkan pembuatan pesan
"""
to = []
if username:
to.append(username)
if request.POST:
to = request.POST.getlist('to')
form = CreateMessageForm(request.POST)
if form.is_valid():
title = form.cleaned_data['title']
message = form.cleaned_data['content']
location = form.cleaned_data['location']
conv = Conversation()
conv.title = title
conv.origin = request.user
conv.location = location
conv.save()
Membership.objects.create(user=request.user,
conversation=conv)
to2 = []
for person in to:
to_person = User.objects.get(username=person)
to2.append(to_person)
Membership.objects.create(user=to_person,
conversation=conv)
msg = Message()
msg.conversation = conv
msg.content = message
msg.user = request.user
msg.save()
notification.send(to2, 'new_message',
{'user': request.user, 'message': conv})
messages.info(request, _('Message sent'))
return HttpResponseRedirect(reverse('message_list'))
else:
form = CreateMessageForm()
return render_to_response('message/create_message.html',
{'form': form,
'to': to},
context_instance=(RequestContext(request)))
示例6: thread
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import user [as 别名]
def thread(request, **args):
t = loader.get_template("discussion.view")
thread = None
if "id" in args:
thread = Thread.objects.get(id=int(args["id"]))
message_form = None
if thread and thread.openForEvent():
if request.method == "POST":
# Post dictionary needs to be mutable in order to remove the value from the messagebox
post_vars = {}
for key in request.POST:
post_vars[key] = request.POST[key]
message_form = MessageForm(post_vars)
if message_form.is_valid():
message = Message()
message.content = message_form.cleaned_data["content"]
message_form.data["content"] = ""
message.time = datetime.now()
message.user = request.user
message.thread = thread
message.save()
else:
message_form = MessageForm()
c = {
"thread": thread,
"thread_message": thread.getStatusMessage(),
"thread_status": thread.getStatus(),
"messages": None,
"message_form": message_form,
"is_authenticated": request.user.is_authenticated(),
}
if thread:
messages = Message.objects.filter(thread__id=thread.id)
c["messages"] = messages
c.update(csrf(request))
return HttpResponse(t.render(Context(c)))