本文整理汇总了Python中models.Message.time方法的典型用法代码示例。如果您正苦于以下问题:Python Message.time方法的具体用法?Python Message.time怎么用?Python Message.time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.time方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import time [as 别名]
def post(self):
text = cgi.escape(self.request.get('text'))
sender = cgi.escape(self.request.get('sender'))
recipient = cgi.escape(self.request.get('recipient'))
subject = cgi.escape(self.request.get('subject'))
parent_message = cgi.escape(self.request.get('parent'))
q = User.query(User.username == recipient)
user = q.get()
if(user):
if len(parent_message) > 0:
message_key = ndb.Key(urlsafe=parent_message)
message = Message(parent = message_key)
else:
message = Message()
message.subject = subject
message.text = text
message.sender = sender
message.recipient = recipient
message.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
message.put()
#Increment message count for navbar
q = User.query(User.username == recipient)
user = q.get()
user.message_count += 1
user.put()
self.redirect('/messages')
else:
self.redirect('/compose')
示例2: save
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import time [as 别名]
def save(self, author, reciever):
new = Message()
new.user1 = author
new.user2 = reciever
new.time = datetime.now()
new.title = self.cleaned_data['title']
new.text = self.cleaned_data['text']
new.save()
示例3: thread
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import time [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)))
示例4: post
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import time [as 别名]
def post(self):
recipient = cgi.escape(self.request.get('recipient'))
text = cgi.escape(self.request.get('text'))
sender = cgi.escape(self.request.get('sender'))
#create msg and put
#is this conversation already existed?
#Yes
#attach message
#No create a new one
#owner, sender, msg
#put
#There's a new coming msg to owner
mesg = Message()
mesg.time = datetime.datetime.now() - datetime.timedelta(hours=8)
mesg.sender = sender
mesg.recipient = recipient
mesg.text = text
mesg.put()
owners_temp = []
owners_temp.append(sender)
owners_temp.append(recipient)
temp1 = " ".join((sender, recipient))
temp2 = " ".join((recipient, sender))
recipient_user = User.query(User.username == recipient).get()
if recipient_user:
recipient_user.msg_count += 1
recipient_user.put()
conversation_qry = Conversation.query(ndb.OR(Conversation.owners == temp1, Conversation.owners == temp2)).get()
if conversation_qry:
logging.info("yes")
#logging.info(conversation_qry.owners)
conversation_qry.children.append(mesg.key)
conversation_qry.msg_count = conversation_qry.msg_count + 1
conversation_qry.most_recent_msg = mesg.text
conversation_qry.most_recent_date = str(mesg.time)
conversation_qry.put()
else:
logging.info("noooooooooo")
#logging.info(conversation_qry)
conv = Conversation()
conv.sender = sender
conv.recipient = recipient
conv.owners = " ".join((sender, recipient))
conv.children.append(mesg.key)
conv.msg_count = conv.msg_count + 1
conv.most_recent_msg = mesg.text
conv.most_recent_date = str(mesg.time)
conv.put()