Commit ac365a54fb5cd56986f397dc9faa8c6917a9e80f
1 parent
08acff87
Exists in
master
and in
2 other branches
Resolvendo problema de messagem no relatório de webpage
Showing
1 changed file
with
36 additions
and
7 deletions
Show diff stats
webpage/views.py
@@ -20,12 +20,19 @@ from .forms import WebpageForm | @@ -20,12 +20,19 @@ from .forms import WebpageForm | ||
20 | from .models import Webpage | 20 | from .models import Webpage |
21 | 21 | ||
22 | from log.models import Log | 22 | from log.models import Log |
23 | -from chat.models import Conversation, TalkMessages | 23 | +from chat.models import Conversation, TalkMessages, ChatVisualizations |
24 | from users.models import User | 24 | from users.models import User |
25 | from subjects.models import Subject | 25 | from subjects.models import Subject |
26 | 26 | ||
27 | from .forms import FormModalMessage | 27 | from .forms import FormModalMessage |
28 | 28 | ||
29 | +from django.template.loader import render_to_string | ||
30 | +from django.utils import formats | ||
31 | +import textwrap | ||
32 | +from django.utils.html import strip_tags | ||
33 | +import json | ||
34 | +from channels import Group | ||
35 | + | ||
29 | class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): | 36 | class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): |
30 | log_component = 'resources' | 37 | log_component = 'resources' |
31 | log_action = 'view' | 38 | log_action = 'view' |
@@ -456,7 +463,7 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -456,7 +463,7 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
456 | 463 | ||
457 | slug = self.kwargs.get('slug') | 464 | slug = self.kwargs.get('slug') |
458 | webpage = get_object_or_404(Webpage, slug = slug) | 465 | webpage = get_object_or_404(Webpage, slug = slug) |
459 | - print (self.request.GET.get('init_date','')) | 466 | + |
460 | date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p" | 467 | date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p" |
461 | if self.request.GET.get('language','') == "": | 468 | if self.request.GET.get('language','') == "": |
462 | start_date = datetime.datetime.now() - datetime.timedelta(30) | 469 | start_date = datetime.datetime.now() - datetime.timedelta(30) |
@@ -476,15 +483,12 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -476,15 +483,12 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
476 | data_n_did,data_history = [],[] | 483 | data_n_did,data_history = [],[] |
477 | json_n_did, json_history = {},{} | 484 | json_n_did, json_history = {},{} |
478 | 485 | ||
479 | - from django.db.models import Count, Max | ||
480 | - views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | ||
481 | - date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | ||
482 | - | ||
483 | for log_al in vis_ou.order_by("datetime"): | 486 | for log_al in vis_ou.order_by("datetime"): |
484 | data_history.append([str(alunos.get(email=log_al.user_email)), | 487 | data_history.append([str(alunos.get(email=log_al.user_email)), |
485 | ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), | 488 | ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), |
486 | log_al.action,log_al.datetime]) | 489 | log_al.action,log_al.datetime]) |
487 | - json_history["data"] = data_history | 490 | + |
491 | + json_history["data"] = data_history | ||
488 | 492 | ||
489 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) | 493 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
490 | index = 0 | 494 | index = 0 |
@@ -549,6 +553,31 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | @@ -549,6 +553,31 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | ||
549 | to_user = User.objects.get(email=u) | 553 | to_user = User.objects.get(email=u) |
550 | talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | 554 | talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) |
551 | created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) | 555 | created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) |
556 | + | ||
557 | + simple_notify = textwrap.shorten(strip_tags(message), width = 30, placeholder = "...") | ||
558 | + | ||
559 | + if image is not '': | ||
560 | + simple_notify += " ".join(_("[Photo]")) | ||
561 | + | ||
562 | + notification = { | ||
563 | + "type": "chat", | ||
564 | + "subtype": "subject", | ||
565 | + "space": subject.slug, | ||
566 | + "user_icon": created.user.image_url, | ||
567 | + "notify_title": str(created.user), | ||
568 | + "simple_notify": simple_notify, | ||
569 | + "view_url": reverse("chat:view_message", args = (created.id, ), kwargs = {}), | ||
570 | + "complete": render_to_string("chat/_message.html", {"talk_msg": created}, self.request), | ||
571 | + "container": "chat-" + str(created.user.id), | ||
572 | + "last_date": _("Last message in %s")%(formats.date_format(created.create_date, "SHORT_DATETIME_FORMAT")) | ||
573 | + } | ||
574 | + | ||
575 | + notification = json.dumps(notification) | ||
576 | + | ||
577 | + Group("user-%s" % to_user.id).send({'text': notification}) | ||
578 | + | ||
579 | + ChatVisualizations.objects.create(viewed = False, message = created, user = to_user) | ||
580 | + | ||
552 | success = str(_('The message was successfull sent!')) | 581 | success = str(_('The message was successfull sent!')) |
553 | return JsonResponse({"message":success}) | 582 | return JsonResponse({"message":success}) |
554 | erro = HttpResponse(str(_("No user selected!"))) | 583 | erro = HttpResponse(str(_("No user selected!"))) |