Commit 140a898b56901cf59cfba29dfe2cc92082d344d1
1 parent
f0160434
Exists in
master
and in
2 other branches
Resolvendo problema de messagem no relatório de links
Showing
1 changed file
with
37 additions
and
8 deletions
Show diff stats
links/views.py
... | ... | @@ -2,7 +2,7 @@ from django.shortcuts import render, get_object_or_404, redirect |
2 | 2 | from django.views import generic |
3 | 3 | from .models import Link |
4 | 4 | from django.utils.translation import ugettext_lazy as _ |
5 | -from django.core.urlresolvers import reverse_lazy | |
5 | +from django.core.urlresolvers import reverse_lazy, reverse | |
6 | 6 | from django.contrib.auth.mixins import LoginRequiredMixin |
7 | 7 | from .forms import LinkForm |
8 | 8 | from rolepermissions.mixins import HasRoleMixin |
... | ... | @@ -19,13 +19,20 @@ from amadeus.permissions import has_subject_permissions, has_resource_permission |
19 | 19 | from topics.models import Topic |
20 | 20 | |
21 | 21 | import datetime |
22 | -from chat.models import Conversation, TalkMessages | |
22 | +from chat.models import Conversation, TalkMessages, ChatVisualizations | |
23 | 23 | from users.models import User |
24 | 24 | from subjects.models import Subject |
25 | 25 | |
26 | 26 | from webpage.forms import FormModalMessage |
27 | 27 | from django.http import JsonResponse |
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 | # Create your views here. |
30 | 37 | class CreateLinkView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
31 | 38 | log_component = 'resources' |
... | ... | @@ -379,7 +386,7 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
379 | 386 | |
380 | 387 | slug = self.kwargs.get('slug') |
381 | 388 | link = get_object_or_404(Link, slug = slug) |
382 | - print (self.request.GET.get('init_date','')) | |
389 | + | |
383 | 390 | date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p" |
384 | 391 | if self.request.GET.get('language','') == "": |
385 | 392 | start_date = datetime.datetime.now() - datetime.timedelta(30) |
... | ... | @@ -399,15 +406,12 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
399 | 406 | data_n_did,data_history = [],[] |
400 | 407 | json_n_did, json_history = {},{} |
401 | 408 | |
402 | - from django.db.models import Count, Max | |
403 | - views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | |
404 | - date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | |
405 | - | |
406 | 409 | for log_al in vis_ou.order_by("datetime"): |
407 | 410 | data_history.append([str(alunos.get(email=log_al.user_email)), |
408 | 411 | ", ".join([str(x) for x in link.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), |
409 | 412 | log_al.action,log_al.datetime]) |
410 | - json_history["data"] = data_history | |
413 | + | |
414 | + json_history["data"] = data_history | |
411 | 415 | |
412 | 416 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
413 | 417 | index = 0 |
... | ... | @@ -470,6 +474,31 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): |
470 | 474 | to_user = User.objects.get(email=u) |
471 | 475 | talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) |
472 | 476 | created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) |
477 | + | |
478 | + simple_notify = textwrap.shorten(strip_tags(message), width = 30, placeholder = "...") | |
479 | + | |
480 | + if image is not '': | |
481 | + simple_notify += " ".join(_("[Photo]")) | |
482 | + | |
483 | + notification = { | |
484 | + "type": "chat", | |
485 | + "subtype": "subject", | |
486 | + "space": subject.slug, | |
487 | + "user_icon": created.user.image_url, | |
488 | + "notify_title": str(created.user), | |
489 | + "simple_notify": simple_notify, | |
490 | + "view_url": reverse("chat:view_message", args = (created.id, ), kwargs = {}), | |
491 | + "complete": render_to_string("chat/_message.html", {"talk_msg": created}, self.request), | |
492 | + "container": "chat-" + str(created.user.id), | |
493 | + "last_date": _("Last message in %s")%(formats.date_format(created.create_date, "SHORT_DATETIME_FORMAT")) | |
494 | + } | |
495 | + | |
496 | + notification = json.dumps(notification) | |
497 | + | |
498 | + Group("user-%s" % to_user.id).send({'text': notification}) | |
499 | + | |
500 | + ChatVisualizations.objects.create(viewed = False, message = created, user = to_user) | |
501 | + | |
473 | 502 | success = str(_('The message was successfull sent!')) |
474 | 503 | return JsonResponse({"message":success}) |
475 | 504 | erro = HttpResponse(str(_("No user selected!"))) | ... | ... |