From 6d1a1af1c8c7038994ce3853fff85e4f381fd436 Mon Sep 17 00:00:00 2001 From: Zambom Date: Tue, 28 Mar 2017 22:41:30 -0300 Subject: [PATCH] Adding subjects messages page --- amadeus/static/js/socket.js | 17 +++++++++++++++++ chat/templates/chat/list.html | 3 +++ chat/templates/chat/subject_view.html | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ chat/urls.py | 1 + chat/views.py | 39 ++++++++++++++++++++++++++++++++++++++- subjects/templates/subjects/subject_card.html | 5 ++++- subjects/templates/subjects/view.html | 5 ++++- subjects/templatetags/subject_counter.py | 10 ++++++++++ 8 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 chat/templates/chat/subject_view.html diff --git a/amadeus/static/js/socket.js b/amadeus/static/js/socket.js index 5128091..3bb5389 100644 --- a/amadeus/static/js/socket.js +++ b/amadeus/static/js/socket.js @@ -290,6 +290,23 @@ function messageReceived(content) { span.text(actual); } + + if (content.subtype == "subject") { + var subject_cbadge = $("#subject_" + content.space).find('.chat_notify'), + actual = subject_cbadge.text(); + + if (actual != "+99") { + actual = parseInt(actual, 10) + 1; + + if (actual > 99) { + actual = "+99"; + } + + subject_cbadge.text(actual); + } + + subject_cbadge.show(); + } } if (("Notification" in window)) { diff --git a/chat/templates/chat/list.html b/chat/templates/chat/list.html index 6c4a97b..76410f2 100644 --- a/chat/templates/chat/list.html +++ b/chat/templates/chat/list.html @@ -54,6 +54,9 @@ {% include 'chat/_view.html' with space="0" space_type='general' %} {% endfor %} + + {% pagination request paginator page_obj %} + {% else %}
diff --git a/chat/templates/chat/subject_view.html b/chat/templates/chat/subject_view.html new file mode 100644 index 0000000..30354ce --- /dev/null +++ b/chat/templates/chat/subject_view.html @@ -0,0 +1,97 @@ +{% extends 'subjects/view.html' %} + +{% load static i18n pagination permissions_tags subject_counter %} +{% load django_bootstrap_breadcrumbs %} + +{% block breadcrumbs %} + {{ block.super }} + + {% trans 'Messages' as bread %} + + {% breadcrumb bread 'chat:subject_view' subject.slug %} +{% endblock %} + +{% block content %} + {% subject_permissions request.user subject as has_subject_permissions %} + + {% if subject.visible %} +
+
+ {% elif has_subject_permissions %} +
+
+ {% endif %} +
+
+

+ {{subject.name}} +

+ +
+ {% if request.user in subject.professor.all or request.user in subject.category.coordinators.all or request.user.is_staff %} + + + {% endif %} + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ + {% if conversations.count > 0 %} +
+

{% trans 'Conversations' %}

+ +
+ {% for chat in conversations %} + {% include 'chat/_view.html' with space=subject.id space_type='subject' %} + {% endfor %} +
+ + {% pagination request paginator page_obj %} +
+ {% else %} +
+ +

{% trans 'You do not posses messages in this space yet.' %}

+
+ {% endif %} +
+ + + + + + +{% endblock %} \ No newline at end of file diff --git a/chat/urls.py b/chat/urls.py index 843df3c..459d896 100644 --- a/chat/urls.py +++ b/chat/urls.py @@ -5,6 +5,7 @@ urlpatterns = [ url(r'^$', views.GeneralIndex.as_view(), name='manage_general'), url(r'^categories/$', views.CategoryIndex.as_view(), name='manage_category'), url(r'^subjects/$', views.SubjectIndex.as_view(), name='manage_subject'), + url(r'^subject/(?P[\w_-]+)/$', views.SubjectView.as_view(), name='subject_view'), url(r'^participants/$', views.GeneralParticipants.as_view(), name='participants_general'), url(r'^category/talks/(?P[\w_-]+)/$', views.CategoryTalks.as_view(), name='category_talks'), url(r'^category/participants/(?P[\w_-]+)/$', views.CategoryParticipants.as_view(), name='participants_category'), diff --git a/chat/views.py b/chat/views.py index e3c3cdd..f89ef10 100644 --- a/chat/views.py +++ b/chat/views.py @@ -15,6 +15,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.decorators import login_required from django.db.models import Q +from amadeus.permissions import has_subject_view_permissions + from channels import Group import json @@ -37,7 +39,6 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView): 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)) & Q(categorytalk__isnull = True) & Q(subjecttalk__isnull = True)) @@ -250,6 +251,42 @@ class SubjectParticipants(LoginRequiredMixin, generic.ListView): return context +class SubjectView(LoginRequiredMixin, generic.ListView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'chat/subject_view.html' + context_object_name = "conversations" + paginate_by = 10 + + def dispatch(self, request, *args,**kwargs): + subject = get_object_or_404(Subject, slug = kwargs.get('slug', '')) + + if not has_subject_view_permissions(request.user, subject): + return redirect(reverse_lazy('subjects:home')) + + return super(SubjectView, self).dispatch(request, *args, **kwargs) + + def get_queryset(self): + user = self.request.user + slug = self.kwargs.get('slug') + subject = get_object_or_404(Subject, slug = slug) + + conversations = SubjectTalk.objects.filter((Q(user_one = user) | Q(user_two = user)) & Q(space = subject)) + + return conversations + + def get_context_data(self, **kwargs): + context = super(SubjectView, self).get_context_data(**kwargs) + + slug = self.kwargs.get('slug', None) + subject = get_object_or_404(Subject, slug = slug) + + context['title'] = _('%s - Messages')%(str(subject)) + context['subject'] = subject + + return context + class ParticipantProfile(LoginRequiredMixin, generic.DetailView): login_url = reverse_lazy("users:login") redirect_field_name = 'next' diff --git a/subjects/templates/subjects/subject_card.html b/subjects/templates/subjects/subject_card.html index 515d749..cd00ad9 100644 --- a/subjects/templates/subjects/subject_card.html +++ b/subjects/templates/subjects/subject_card.html @@ -39,7 +39,10 @@ {% notifies_number subject request.user %} - + + + {% chat_number subject request.user %} + {% mural_number subject request.user %} diff --git a/subjects/templates/subjects/view.html b/subjects/templates/subjects/view.html index decdb60..faaf739 100644 --- a/subjects/templates/subjects/view.html +++ b/subjects/templates/subjects/view.html @@ -61,7 +61,10 @@ {% notifies_number subject request.user %} - + + + {% chat_number subject request.user %} + {% mural_number subject request.user %} diff --git a/subjects/templatetags/subject_counter.py b/subjects/templatetags/subject_counter.py index 6ae23d8..9a4f90f 100644 --- a/subjects/templatetags/subject_counter.py +++ b/subjects/templatetags/subject_counter.py @@ -2,6 +2,7 @@ import datetime from django import template from django.db.models import Q +from chat.models import ChatVisualizations from mural.models import MuralVisualizations from notifications.models import Notification @@ -39,6 +40,15 @@ def mural_number(subject, user): return context @register.inclusion_tag('subjects/badge.html') +def chat_number(subject, user): + context = {} + + context['number'] = ChatVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & Q(message__talk__subjecttalk__space = subject)).count() + context['custom_class'] = 'chat_notify' + + return context + +@register.inclusion_tag('subjects/badge.html') def resource_mural_number(resource, user): context = {} -- libgit2 0.21.2