Commit 08acff8723c61e76cdfd607055fd3c9acca1b00e
1 parent
140a898b
Exists in
master
and in
2 other branches
Resolvendo problema de messagem no relatório de pdf_link
Showing
1 changed file
with
35 additions
and
6 deletions
Show diff stats
pdf_file/views.py
@@ -19,12 +19,19 @@ from topics.models import Topic, Resource | @@ -19,12 +19,19 @@ from topics.models import Topic, Resource | ||
19 | from .models import PDFFile | 19 | from .models import PDFFile |
20 | from pendencies.forms import PendenciesForm | 20 | from pendencies.forms import PendenciesForm |
21 | 21 | ||
22 | -from chat.models import Conversation, TalkMessages | 22 | +from chat.models import Conversation, TalkMessages, ChatVisualizations |
23 | from users.models import User | 23 | from users.models import User |
24 | from subjects.models import Subject | 24 | from subjects.models import Subject |
25 | from webpage.forms import FormModalMessage | 25 | from webpage.forms import FormModalMessage |
26 | from django.http import JsonResponse | 26 | from django.http import JsonResponse |
27 | 27 | ||
28 | +from django.template.loader import render_to_string | ||
29 | +from django.utils import formats | ||
30 | +import textwrap | ||
31 | +from django.utils.html import strip_tags | ||
32 | +import json | ||
33 | +from channels import Group | ||
34 | + | ||
28 | 35 | ||
29 | class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): | 36 | class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): |
30 | template_name='pdf_file/view.html' | 37 | template_name='pdf_file/view.html' |
@@ -423,16 +430,13 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -423,16 +430,13 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
423 | data_n_did,data_history = [],[] | 430 | data_n_did,data_history = [],[] |
424 | json_n_did, json_history = {},{} | 431 | json_n_did, json_history = {},{} |
425 | 432 | ||
426 | - from django.db.models import Count, Max | ||
427 | - views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | ||
428 | - date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | ||
429 | - | ||
430 | 433 | ||
431 | for log_al in vis_ou.order_by("datetime"): | 434 | for log_al in vis_ou.order_by("datetime"): |
432 | data_history.append([str(alunos.get(email=log_al.user_email)), | 435 | data_history.append([str(alunos.get(email=log_al.user_email)), |
433 | ", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), | 436 | ", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), |
434 | log_al.action,log_al.datetime]) | 437 | log_al.action,log_al.datetime]) |
435 | - json_history["data"] = data_history | 438 | + |
439 | + json_history["data"] = data_history | ||
436 | 440 | ||
437 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) | 441 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
438 | index = 0 | 442 | index = 0 |
@@ -495,6 +499,31 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | @@ -495,6 +499,31 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | ||
495 | to_user = User.objects.get(email=u) | 499 | to_user = User.objects.get(email=u) |
496 | talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | 500 | talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) |
497 | created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) | 501 | created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) |
502 | + | ||
503 | + simple_notify = textwrap.shorten(strip_tags(message), width = 30, placeholder = "...") | ||
504 | + | ||
505 | + if image is not '': | ||
506 | + simple_notify += " ".join(_("[Photo]")) | ||
507 | + | ||
508 | + notification = { | ||
509 | + "type": "chat", | ||
510 | + "subtype": "subject", | ||
511 | + "space": subject.slug, | ||
512 | + "user_icon": created.user.image_url, | ||
513 | + "notify_title": str(created.user), | ||
514 | + "simple_notify": simple_notify, | ||
515 | + "view_url": reverse("chat:view_message", args = (created.id, ), kwargs = {}), | ||
516 | + "complete": render_to_string("chat/_message.html", {"talk_msg": created}, self.request), | ||
517 | + "container": "chat-" + str(created.user.id), | ||
518 | + "last_date": _("Last message in %s")%(formats.date_format(created.create_date, "SHORT_DATETIME_FORMAT")) | ||
519 | + } | ||
520 | + | ||
521 | + notification = json.dumps(notification) | ||
522 | + | ||
523 | + Group("user-%s" % to_user.id).send({'text': notification}) | ||
524 | + | ||
525 | + ChatVisualizations.objects.create(viewed = False, message = created, user = to_user) | ||
526 | + | ||
498 | success = str(_('The message was successfull sent!')) | 527 | success = str(_('The message was successfull sent!')) |
499 | return JsonResponse({"message":success}) | 528 | return JsonResponse({"message":success}) |
500 | erro = HttpResponse(str(_("No user selected!"))) | 529 | erro = HttpResponse(str(_("No user selected!"))) |