示例#1
0
文件: views.py 项目: redfox-qu/Rancho
    def get_messages(request, p_id):
        SUMMARY_NUMBER = 15
        user = request.user
        project = get_object_or_404(Project, id=p_id)

        project.check_user_in_project_or_404(user)

        try:
            chat_data = ChatData.objects.get(user=user, project=project)
        except ChatData.DoesNotExist:
            chat_data = ChatData(user=user,
                                 project=project,
                                 last_request=-1,
                                 is_connected=True)
            chat_data.save()
        posts = []
        if chat_data:
            posts = Post.objects.filter(
                project=project,
                id__gt=chat_data.last_request).order_by('date')
        else:
            posts = Post.objects.filter(
                project=project).order_by('-date')[-SUMMARY_NUMBER:]

        if posts:
            chat_data.last_request = posts[len(posts) - 1].id

        chat_data.is_connected = True
        chat_data.save()
        return posts
示例#2
0
文件: views.py 项目: redfox-qu/Rancho
def general_chat(request, p_id):
    SUMMARY_NUMBER = 15
    user = request.user
    project = get_object_or_404(Project, id=p_id)

    project.check_user_in_project_or_404(user)

    posts = Post.objects.filter(project=project)

    try:
        chat_data = ChatData.objects.get(project=project, user=user)
    except ChatData.DoesNotExist:
        chat_data = ChatData(user=user, project=project, last_request=-1)
        chat_data.save()
    chat_data.is_connected = True
    chat_data.save()

    chat_form = ChatForm()

    recent_log = list(
        Post.objects.filter(
            project=project,
            date__lt=datetime.now()).order_by('date'))[-SUMMARY_NUMBER:]

    context = {
        'posts': posts,
        'project': project,
        'chat_form': chat_form,
        'recent_log': recent_log
    }

    return render_to_response("chat/general.html",
                              context,
                              context_instance=RequestContext(request))
示例#3
0
文件: views.py 项目: redfox-qu/Rancho
def disconnect(request, p_id):
    user = request.user
    project = get_object_or_404(Project, id=p_id)

    project.check_user_in_project_or_404(user)

    try:
        chat_data = ChatData.objects.get(project=project, user=user)
    except ChatData.DoesNotExist:
        chat_data = ChatData(user=user, project=project, last_request=-1)
        chat_data.save()
    chat_data.is_connected = False
    chat_data.save()
    return HttpResponse('')
示例#4
0
def disconnect(request, p_id):
    user = request.user
    project = get_object_or_404(Project, id=p_id)

    project.check_user_in_project_or_404(user)

    try:
        chat_data = ChatData.objects.get(project=project, user=user)
    except ChatData.DoesNotExist:
        chat_data = ChatData(user=user, project=project, last_request=-1)
        chat_data.save()
    chat_data.is_connected = False
    chat_data.save()
    return HttpResponse("")
示例#5
0
    def get_messages(request, p_id):
        SUMMARY_NUMBER = 15
        user = request.user
        project = get_object_or_404(Project, id=p_id)

        project.check_user_in_project_or_404(user)

        try:
            chat_data = ChatData.objects.get(user=user, project=project)
        except ChatData.DoesNotExist:
            chat_data = ChatData(user=user, project=project, last_request=-1, is_connected=True)
            chat_data.save()
        posts = []
        if chat_data:
            posts = Post.objects.filter(project=project, id__gt=chat_data.last_request).order_by("date")
        else:
            posts = Post.objects.filter(project=project).order_by("-date")[-SUMMARY_NUMBER:]

        if posts:
            chat_data.last_request = posts[len(posts) - 1].id

        chat_data.is_connected = True
        chat_data.save()
        return posts
示例#6
0
def general_chat(request, p_id):
    SUMMARY_NUMBER = 15
    user = request.user
    project = get_object_or_404(Project, id=p_id)

    project.check_user_in_project_or_404(user)

    posts = Post.objects.filter(project=project)

    try:
        chat_data = ChatData.objects.get(project=project, user=user)
    except ChatData.DoesNotExist:
        chat_data = ChatData(user=user, project=project, last_request=-1)
        chat_data.save()
    chat_data.is_connected = True
    chat_data.save()

    chat_form = ChatForm()

    recent_log = list(Post.objects.filter(project=project, date__lt=datetime.now()).order_by("date"))[-SUMMARY_NUMBER:]

    context = {"posts": posts, "project": project, "chat_form": chat_form, "recent_log": recent_log}

    return render_to_response("chat/general.html", context, context_instance=RequestContext(request))