views.py
2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from django.shortcuts import get_object_or_404, redirect, render
from django.core.paginator import Paginator, EmptyPage
from django.http import Http404
from django.views import generic
from django.contrib import messages
from django.http import JsonResponse
from django.template.loader import render_to_string
from django.core.urlresolvers import reverse, reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q
from users.models import User
from .models import Conversation, ChatVisualizations
class GeneralIndex(LoginRequiredMixin, generic.ListView):
login_url = reverse_lazy("users:login")
redirect_field_name = 'next'
template_name = 'chat/list.html'
context_object_name = "conversations"
paginate_by = 10
totals = {}
def get_queryset(self):
user = self.request.user
page = self.request.GET.get('page', False)
conversations = Conversation.objects.filter(Q(user_one = user) | Q(user_two = user))
self.totals['general'] = ChatVisualizations.objects.filter(user = user, viewed = False, message__talk__generaltalk__isnull = False).count()
self.totals['category'] = ChatVisualizations.objects.filter(user = user, viewed = False, message__talk__categorytalk__isnull = False).count()
self.totals['subject'] = ChatVisualizations.objects.filter(user = user, viewed = False, message__talk__subjecttalk__isnull = False).count()
return conversations
def get_context_data(self, **kwargs):
context = super(GeneralIndex, self).get_context_data(**kwargs)
context['title'] = _('Messages')
context['totals'] = self.totals
context['chat_menu_active'] = 'subjects_menu_active'
return context
class GeneralParticipants(LoginRequiredMixin, generic.ListView):
login_url = reverse_lazy("users:login")
redirect_field_name = 'next'
template_name = 'chat/list_participants.html'
context_object_name = "participants"
paginate_by = 10
totals = {}
def get_queryset(self):
user = self.request.user
users = User.objects.all().exclude(id = user.id).order_by('social_name','username')
self.totals['general'] = ChatVisualizations.objects.filter(user = user, viewed = False, message__talk__generaltalk__isnull = False).count()
self.totals['category'] = ChatVisualizations.objects.filter(user = user, viewed = False, message__talk__categorytalk__isnull = False).count()
self.totals['subject'] = ChatVisualizations.objects.filter(user = user, viewed = False, message__talk__subjecttalk__isnull = False).count()
return users
def get_context_data(self, **kwargs):
context = super(GeneralParticipants, self).get_context_data(**kwargs)
context['title'] = _('Messages - Participants')
context['totals'] = self.totals
context['chat_menu_active'] = 'subjects_menu_active'
return context