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
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))
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('')
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("")
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
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))