Commit f0160434123a84eb56a0699c36d7237b8caed9d1

Authored by Jailson Dias
1 parent 74e082e1

Resolvendo problema de messagem no relatório de file_link

Showing 1 changed file with 36 additions and 7 deletions   Show diff stats
file_link/views.py
... ... @@ -21,13 +21,20 @@ from .models import FileLink
21 21  
22 22 import datetime
23 23 from log.models import Log
24   -from chat.models import Conversation, TalkMessages
  24 +from chat.models import Conversation, TalkMessages, ChatVisualizations
25 25 from users.models import User
26 26 from subjects.models import Subject
27 27  
28 28 from webpage.forms import FormModalMessage
29 29 from django.http import JsonResponse
30 30  
  31 +from django.template.loader import render_to_string
  32 +from django.utils import formats
  33 +import textwrap
  34 +from django.utils.html import strip_tags
  35 +import json
  36 +from channels import Group
  37 +
31 38 class DownloadFile(LoginRequiredMixin, LogMixin, generic.DetailView):
32 39 log_component = 'resources'
33 40 log_action = 'view'
... ... @@ -399,7 +406,7 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
399 406  
400 407 slug = self.kwargs.get('slug')
401 408 filelink = get_object_or_404(FileLink, slug = slug)
402   - print (self.request.GET.get('init_date',''))
  409 +
403 410 date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p"
404 411 if self.request.GET.get('language','') == "":
405 412 start_date = datetime.datetime.now() - datetime.timedelta(30)
... ... @@ -419,15 +426,12 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
419 426 data_n_did,data_history = [],[]
420 427 json_n_did, json_history = {},{}
421 428  
422   - from django.db.models import Count, Max
423   - views_user = vis_ou.values("user_email").annotate(views=Count("user_email"))
424   - date_last = vis_ou.values("user_email").annotate(last=Max("datetime"))
425   -
426 429 for log_al in vis_ou.order_by("datetime"):
427 430 data_history.append([str(alunos.get(email=log_al.user_email)),
428 431 ", ".join([str(x) for x in filelink.topic.subject.group_subject.filter(participants__email=log_al.user_email)]),
429 432 log_al.action,log_al.datetime])
430   - json_history["data"] = data_history
  433 +
  434 + json_history["data"] = data_history
431 435  
432 436 not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")])
433 437 index = 0
... ... @@ -490,6 +494,31 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView):
490 494 to_user = User.objects.get(email=u)
491 495 talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user)
492 496 created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image)
  497 +
  498 + simple_notify = textwrap.shorten(strip_tags(message), width = 30, placeholder = "...")
  499 +
  500 + if image is not '':
  501 + simple_notify += " ".join(_("[Photo]"))
  502 +
  503 + notification = {
  504 + "type": "chat",
  505 + "subtype": "subject",
  506 + "space": subject.slug,
  507 + "user_icon": created.user.image_url,
  508 + "notify_title": str(created.user),
  509 + "simple_notify": simple_notify,
  510 + "view_url": reverse("chat:view_message", args = (created.id, ), kwargs = {}),
  511 + "complete": render_to_string("chat/_message.html", {"talk_msg": created}, self.request),
  512 + "container": "chat-" + str(created.user.id),
  513 + "last_date": _("Last message in %s")%(formats.date_format(created.create_date, "SHORT_DATETIME_FORMAT"))
  514 + }
  515 +
  516 + notification = json.dumps(notification)
  517 +
  518 + Group("user-%s" % to_user.id).send({'text': notification})
  519 +
  520 + ChatVisualizations.objects.create(viewed = False, message = created, user = to_user)
  521 +
493 522 success = str(_('The message was successfull sent!'))
494 523 return JsonResponse({"message":success})
495 524 erro = HttpResponse(str(_("No user selected!")))
... ...