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


Python Message.thread方法代码示例

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


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

示例1: message_thread

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import thread [as 别名]
def message_thread(request, user_id=0):
    """
    Returns current & other user's message thread.
    Allowed HTTP methods are:\n
        1. GET to view\n
            Returns:\n
            [
                {
                    "msg_id": [msg_id],
                    "created_at": [message_date],
                    "title": [title],
                    "message": [message],
                    "from_user_id": [user_id],
                    "from_first_name": [first_name],
                    "from_last_name": [last_name],
                    "from_title": [title],
                    "from_thumbnail_url": [thumbnail_url],
                    "from_profile_url": [profile_url],
                    "to_user_id": [user_id],
                    "to_first_name": [first_name],
                    "to_last_name": [last_name],
                    "to_title": [title],
                    "to_thumbnail_url": [thumbnail_url],
                    "to_profile_url": [profile_url]
                },
            ]
    Status:\n
        1. 200 on success
        2. 401 if un-authorized
    Notes:\n
        1. Require user's token to be sent in the header as:\n
            Authorization: Token [token]\n
    """
    user = request.user
    other = User.objects.filter(id=user_id).first()
    all_messages = Message.thread(user, other)

    all_plain_msgs = []
    for message in all_messages:
        all_plain_msgs.append(message.plain())

    paginator = Paginator(all_plain_msgs, 10)
    page = request.QUERY_PARAMS.get('page')

    try:
        page_messages = paginator.page(page)
    except PageNotAnInteger:
        page_messages = paginator.page(1)
    except EmptyPage:
        page_messages = paginator.page(paginator.num_pages)

    serializer_context = {
        'request': request
    }

    serializer = PaginatedMessageSerializer(page_messages, context=serializer_context)
    return Response(serializer.data)
开发者ID:aftabaig,项目名称:py_castm,代码行数:59,代码来源:views.py

示例2: thread

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import thread [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)))
开发者ID:jeroen51,项目名称:Game-calendar,代码行数:44,代码来源:discussion.py


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