Commit ac365a54fb5cd56986f397dc9faa8c6917a9e80f

Authored by Jailson Dias
1 parent 08acff87

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 20 from .models import Webpage
21 21  
22 22 from log.models import Log
23   -from chat.models import Conversation, TalkMessages
  23 +from chat.models import Conversation, TalkMessages, ChatVisualizations
24 24 from users.models import User
25 25 from subjects.models import Subject
26 26  
27 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 36 class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView):
30 37 log_component = 'resources'
31 38 log_action = 'view'
... ... @@ -456,7 +463,7 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
456 463  
457 464 slug = self.kwargs.get('slug')
458 465 webpage = get_object_or_404(Webpage, slug = slug)
459   - print (self.request.GET.get('init_date',''))
  466 +
460 467 date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p"
461 468 if self.request.GET.get('language','') == "":
462 469 start_date = datetime.datetime.now() - datetime.timedelta(30)
... ... @@ -476,15 +483,12 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
476 483 data_n_did,data_history = [],[]
477 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 486 for log_al in vis_ou.order_by("datetime"):
484 487 data_history.append([str(alunos.get(email=log_al.user_email)),
485 488 ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=log_al.user_email)]),
486 489 log_al.action,log_al.datetime])
487   - json_history["data"] = data_history
  490 +
  491 + json_history["data"] = data_history
488 492  
489 493 not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")])
490 494 index = 0
... ... @@ -549,6 +553,31 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView):
549 553 to_user = User.objects.get(email=u)
550 554 talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user)
551 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 581 success = str(_('The message was successfull sent!'))
553 582 return JsonResponse({"message":success})
554 583 erro = HttpResponse(str(_("No user selected!")))
... ...