当前位置: 首页>>代码示例>>Python>>正文


Python Message.receiver方法代码示例

本文整理汇总了Python中models.Message.receiver方法的典型用法代码示例。如果您正苦于以下问题:Python Message.receiver方法的具体用法?Python Message.receiver怎么用?Python Message.receiver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Message的用法示例。


在下文中一共展示了Message.receiver方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import receiver [as 别名]
    def post(self, request, **kwargs):

        file = request.FILES.get('file')
        content = request.POST.get('message')
        sender = request.user
        message = Message()

        message.file=file


        # print message.file

        message.content=content
        message.receiver = kwargs['receiver']
        message.sender=User.objects.get(username=sender)
        message.sender_full_name = message.sender.userprofile.get_full_name()
        print message.sender_full_name
        message.save()

        # print message
        #
        # print message.file


        # print (request.user)

        messages = Message.objects.filter(Q(sender=request.user, receiver=kwargs['receiver']) | Q(sender=User.objects.get(username=kwargs['receiver']), receiver=request.user))

        messages5 = Message.objects.filter(Q(sender=request.user) | Q(receiver=request.user))[::-1]
        if len(messages5) <=5:
            message5 = messages5
        else :
            message5 = messages5[:5]

        # message5=message5[::-1]

        # print profile

        profile = User.objects.filter(username=kwargs['receiver'])[0]

        auth_form = AuthenticateForm()


        return render(request, 'message.html', {'messages':messages, 'profile':profile ,'auth_form':auth_form, 'message5':message5})
开发者ID:bh00t,项目名称:donateinbd,代码行数:46,代码来源:views.py

示例2: Http404

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import receiver [as 别名]
    host: The hostname of the computer the client is running on
    """
    if request.method != "POST":
        print "Did not post"
        raise Http404("You must post to this URL")

    receiver_account = get_or_create_account(protocol, request.POST["receiver_account"], request.POST["owner_account"])
    sender_account = get_or_create_account(protocol, request.POST["sender_account"], request.POST["owner_account"])  
    if sender_account.full_name == "":
        sender_account.full_name = request.POST["alias"]
        sender_account.save()
    
    try:
        timestamp = datetime.datetime.strptime(request.POST["timestamp"][:-6], "%Y-%m-%dT%H:%M:%S")
    except Exception, e:
        print e.message
        timestamp = datetime.datetime.strptime(request.POST["timestamp"][:-6], "%Y-%m-%d %H:%M:%S")
    messages = Message.objects.filter(sender=sender_account).filter(receiver=receiver_account).filter(timestamp=timestamp)
    if len(messages) > 0:
        return HttpResponse(simplejson.dumps({"result":False,"reason":"Duplicate message"}), mimetype="application/json")
    message = Message()
    message.receiver = receiver_account
    message.sender = sender_account
    message.timestamp = timestamp
    message.text = request.POST["message_text"]
    message.client_type = request.POST["client_type"]
    message.host = request.POST["host"]
    message.save()

    data = simplejson.dumps({"result":True})
    return HttpResponse(data, mimetype="application/json")
开发者ID:tangerilli,项目名称:dool,代码行数:33,代码来源:views.py


注:本文中的models.Message.receiver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。