Commit 71c243c01f344841ab5c2ecc5a385a4d9129fada

Authored by Jailson Dias
1 parent ac365a54

Resolvendo problema de messagem no relatório de youtube

Showing 1 changed file with 35 additions and 8 deletions   Show diff stats
youtube_video/views.py
... ... @@ -20,13 +20,19 @@ from .models import YTVideo
20 20  
21 21 import datetime
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 webpage.forms import FormModalMessage
28 28  
29 29 from django.db.models import Q
  30 +from django.template.loader import render_to_string
  31 +from django.utils import formats
  32 +import textwrap
  33 +from django.utils.html import strip_tags
  34 +import json
  35 +from channels import Group
30 36  
31 37 class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView):
32 38 log_component = 'resources'
... ... @@ -516,7 +522,7 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
516 522  
517 523 slug = self.kwargs.get('slug')
518 524 ytvideo = get_object_or_404(YTVideo, slug = slug)
519   - print (self.request.GET.get('init_date',''))
  525 +
520 526 date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p"
521 527 if self.request.GET.get('language','') == "":
522 528 start_date = datetime.datetime.now() - datetime.timedelta(30)
... ... @@ -536,15 +542,12 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
536 542 data_n_did,data_history = [],[]
537 543 json_n_did, json_history = {},{}
538 544  
539   - from django.db.models import Count, Max
540   - views_user = vis_ou.values("user_email").annotate(views=Count("user_email"))
541   - date_last = vis_ou.values("user_email").annotate(last=Max("datetime"))
542   -
543 545 for log_al in vis_ou.order_by("datetime"):
544 546 data_history.append([str(alunos.get(email=log_al.user_email)),
545 547 ", ".join([str(x) for x in ytvideo.topic.subject.group_subject.filter(participants__email=log_al.user_email)]),
546 548 log_al.action,log_al.datetime])
547   - json_history["data"] = data_history
  549 +
  550 + json_history["data"] = data_history
548 551  
549 552 column_view,column_watch,column_finish = str(_('View')),str(_('Watch')),str(_('Finish'))
550 553  
... ... @@ -619,7 +622,7 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView):
619 622  
620 623 def form_valid(self, form):
621 624 message = form.cleaned_data.get('comment')
622   - image = form.cleaned_data.get("image")
  625 + image = form.cleaned_data.get("image",'')
623 626 users = (self.request.POST.get('users[]','')).split(",")
624 627 user = self.request.user
625 628 subject = self.ytvideo.topic.subject
... ... @@ -629,6 +632,30 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView):
629 632 to_user = User.objects.get(email=u)
630 633 talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user)
631 634 created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image)
  635 +
  636 + simple_notify = textwrap.shorten(strip_tags(message), width = 30, placeholder = "...")
  637 +
  638 + if image is not '':
  639 + simple_notify += " ".join(_("[Photo]"))
  640 +
  641 + notification = {
  642 + "type": "chat",
  643 + "subtype": "subject",
  644 + "space": subject.slug,
  645 + "user_icon": created.user.image_url,
  646 + "notify_title": str(created.user),
  647 + "simple_notify": simple_notify,
  648 + "view_url": reverse("chat:view_message", args = (created.id, ), kwargs = {}),
  649 + "complete": render_to_string("chat/_message.html", {"talk_msg": created}, self.request),
  650 + "container": "chat-" + str(created.user.id),
  651 + "last_date": _("Last message in %s")%(formats.date_format(created.create_date, "SHORT_DATETIME_FORMAT"))
  652 + }
  653 +
  654 + notification = json.dumps(notification)
  655 +
  656 + Group("user-%s" % to_user.id).send({'text': notification})
  657 +
  658 + ChatVisualizations.objects.create(viewed = False, message = created, user = to_user)
632 659 success = str(_('The message was successfull sent!'))
633 660 return JsonResponse({"message":success})
634 661 erro = HttpResponse(str(_("No user selected!")))
... ...