diff --git a/goals/templates/goals/_form_submit.html b/goals/templates/goals/_form_submit.html
index 319c629..2fa8040 100644
--- a/goals/templates/goals/_form_submit.html
+++ b/goals/templates/goals/_form_submit.html
@@ -46,6 +46,15 @@
{% endif %}
{% endfor %}
+
+
+
+
diff --git a/goals/utils.py b/goals/utils.py
index c94650d..3f6344f 100644
--- a/goals/utils.py
+++ b/goals/utils.py
@@ -1,5 +1,16 @@
+import json
+import textwrap
+from django.db.models import Q
from django.utils import timezone
+from django.utils import formats
+from django.utils.html import strip_tags
+from django.template.loader import render_to_string
+from django.core.urlresolvers import reverse
+from django.utils.translation import ugettext_lazy as _
+from channels import Group
+
+from chat.models import Conversation, TalkMessages, ChatVisualizations
from users.models import User
from .models import GoalItem, MyGoals
@@ -16,3 +27,41 @@ def set_goals():
entries.append(MyGoals(user = user, item = goal, value = goal.ref_value))
MyGoals.objects.bulk_create(entries)
+
+def brodcast_dificulties(request, message, subject):
+ msg = TalkMessages()
+ msg.text = message
+ msg.user = request.user
+ msg.subject = subject
+
+ simple_notify = textwrap.shorten(strip_tags(msg.text), width = 30, placeholder = "...")
+
+ for p in subject.professor.all():
+ talks = Conversation.objects.filter((Q(user_one = request.user) & Q(user_two__email = p.email)) | (Q(user_two = request.user) & Q(user_one__email = p.email)))
+
+ if talks.count() > 0:
+ msg.talk = talks[0]
+ else:
+ msg.talk = Conversation.objects.create(user_one = request.user, user_two = p)
+
+ msg.save()
+
+ notification = {
+ "type": "chat",
+ "subtype": subject.slug,
+ "space": "subject",
+ "user_icon": request.user.image_url,
+ "notify_title": str(request.user),
+ "simple_notify": simple_notify,
+ "view_url": reverse("chat:view_message", args = (msg.id, ), kwargs = {}),
+ "complete": render_to_string("chat/_message.html", {"talk_msg": msg}, request),
+ "container": "chat-" + str(request.user.id),
+ "last_date": _("Last message in %s")%(formats.date_format(msg.create_date, "SHORT_DATETIME_FORMAT"))
+ }
+
+ notification = json.dumps(notification)
+
+ Group("user-%s" % p.id).send({'text': notification})
+
+ ChatVisualizations.objects.create(viewed = False, message = msg, user = p)
+
diff --git a/goals/views.py b/goals/views.py
index a9b0124..372e3e0 100644
--- a/goals/views.py
+++ b/goals/views.py
@@ -17,6 +17,7 @@ from amadeus.permissions import has_subject_permissions, has_resource_permission
from topics.models import Topic
from users.models import User
+from .utils import brodcast_dificulties
from .forms import GoalsForm, MyGoalsForm, InlinePendenciesFormset, InlineGoalItemFormset
from .models import Goals, MyGoals
@@ -344,6 +345,16 @@ class NewWindowSubmit(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
form.save()
+ dificulties = self.request.POST.get('dificulties', None)
+
+ if not dificulties is None:
+ slug = self.kwargs.get('slug', '')
+ goals = get_object_or_404(Goals, slug = slug)
+
+ message = _("#Dificulty(ies) found in %s")%(str(goals)) + ":" + dificulties + "
"
+
+ brodcast_dificulties(self.request, message, goals.topic.subject)
+
return redirect(self.get_success_url())
def get_context_data(self, **kwargs):
@@ -445,7 +456,7 @@ class SubmitView(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
def post(self, request, *args, **kwargs):
self.object = None
-
+
form_class = self.get_form_class()
form = self.get_form(form_class)
@@ -470,6 +481,16 @@ class SubmitView(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
form.save()
+ dificulties = self.request.POST.get('dificulties', None)
+
+ if not dificulties is None:
+ slug = self.kwargs.get('slug', '')
+ goals = get_object_or_404(Goals, slug = slug)
+
+ message = _("#Dificulty(ies) found in %s")%(str(goals)) + ":" + dificulties + "
"
+
+ brodcast_dificulties(self.request, message, goals.topic.subject)
+
return redirect(self.get_success_url())
def get_context_data(self, **kwargs):
@@ -578,6 +599,16 @@ class UpdateSubmit(LoginRequiredMixin, LogMixin, generic.UpdateView):
form.save()
+ dificulties = self.request.POST.get('dificulties', None)
+
+ if not dificulties is None:
+ slug = self.kwargs.get('slug', '')
+ goals = get_object_or_404(Goals, slug = slug)
+
+ message = _("#Dificulty(ies) found in %s")%(str(goals)) + ":" + dificulties + "
"
+
+ brodcast_dificulties(self.request, message, goals.topic.subject)
+
return redirect(self.get_success_url())
def get_context_data(self, **kwargs):
--
libgit2 0.21.2