diff --git a/app/templates/home_teacher_student_content.html b/app/templates/home_teacher_student_content.html index 28c430a..99fe24e 100644 --- a/app/templates/home_teacher_student_content.html +++ b/app/templates/home_teacher_student_content.html @@ -15,8 +15,8 @@
-

{{ notification.user }}

-

{{notification.message}} em : Recurso

+

{{ notification.actor }}

+

{{notification.message}} em : {{ notification.action_resource.resource.name }}

{{ notification.datetime|timesince }} {% trans "ago" %}

diff --git a/core/decorators.py b/core/decorators.py index 566624c..c2e439e 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -60,7 +60,7 @@ def notification_decorator(read = False, message = '', actor = None, users = [], if action.exists(): action = action[0] else: - action = Action(name = not_action) + action = Action(name = not_action) action.save() if resource.exists(): diff --git a/core/migrations/0002_auto_20161022_0158.py b/core/migrations/0002_auto_20161022_0158.py new file mode 100644 index 0000000..b6721f7 --- /dev/null +++ b/core/migrations/0002_auto_20161022_0158.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-10-22 04:58 +from __future__ import unicode_literals + +import autoslug.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='action', + name='slug', + field=autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True, verbose_name='Slug'), + ), + ] diff --git a/core/mixins.py b/core/mixins.py index 743e1fa..f5e49b8 100644 --- a/core/mixins.py +++ b/core/mixins.py @@ -41,16 +41,16 @@ class LogMixin(object): class NotificationMixin(object): message = "" read = False - action_name = '' + action_slug = '' resource_name = '' - def createNotification(self, message='', actor=None, users = User.objects.all(), resource_slug='' ,action_name = '', resource_name='', resource_link=''): #the default will be a broadcast - action = Action.objects.filter(name = action_name) + def createNotification(self, message='', actor=None, users = User.objects.all(), resource_slug='' ,action_slug = '', resource_name='', resource_link=''): #the default will be a broadcast + action = Action.objects.filter(slug = action_slug) resource = Resource.objects.filter(slug = resource_slug) if action.exists(): action = action[0] else: - action = Action(name = self.action_name) + action = Action(name = self.action_slug) action.save() if resource.exists(): @@ -76,3 +76,9 @@ class NotificationMixin(object): """ Not quite sure how to do about it""" return super(NotificationMixin, self).dispatch(request, *args, **kwargs) + + def createorRetrieveAction(self, action_name): + action = Action.objects.filter(name=action_name) + if action is None: + action = Action(name=action_name) + return action \ No newline at end of file diff --git a/core/models.py b/core/models.py index a8deeee..e5a90ea 100644 --- a/core/models.py +++ b/core/models.py @@ -25,6 +25,7 @@ class Action(models.Model): """ name = models.CharField(_('Name'), max_length = 100) + slug = AutoSlugField(_("Slug"), populate_from=('name'), unique=True) created_date = models.DateField(_('Created Date'), auto_now_add=True) class Meta: @@ -84,7 +85,7 @@ class Notification(models.Model): @action_resource: The Object that holds the information about which action was perfomed on the Resource @actor: The user who applied the action """ - + message = models.TextField(_('Message')) user = models.ForeignKey(User, related_name = _('%(class)s_Actor'), verbose_name= _('User')) read = models.BooleanField(_('Read'), default = False) diff --git a/core/static/css/base/amadeus.css b/core/static/css/base/amadeus.css index 2cb6c7e..fa6fd9d 100644 --- a/core/static/css/base/amadeus.css +++ b/core/static/css/base/amadeus.css @@ -12,7 +12,7 @@ #notification-dropdown{ max-height: 500%; overflow: auto; - width: 200px; + width: 300px; } /* HEADER */ diff --git a/core/templates/notifications.html b/core/templates/notifications.html index 75363b8..b70502e 100644 --- a/core/templates/notifications.html +++ b/core/templates/notifications.html @@ -6,7 +6,7 @@
icon -
{{ notification.datetime }}
+
{{ notification.datetime }}

{{ notification.message }}

diff --git a/core/views.py b/core/views.py index a2b3343..53a99e9 100644 --- a/core/views.py +++ b/core/views.py @@ -68,7 +68,7 @@ def remember_password(request): context['danger'] = 'E-mail does not send' return render(request, "remember_password.html",context) -@notification_decorator(message='just connected') +@notification_decorator(message='just connected', not_action="logged in", not_resource="") @log_decorator('Acessar', 'Sistema') def login(request): context = {} diff --git a/courses/models.py b/courses/models.py index 31a3298..e3658e3 100644 --- a/courses/models.py +++ b/courses/models.py @@ -7,6 +7,7 @@ from core.models import Resource, MimeType from s3direct.fields import S3DirectField from django.core.urlresolvers import reverse +from core.models import Resource class CourseCategory(models.Model): diff --git a/courses/templates/subject/form_view_teacher.html b/courses/templates/subject/form_view_teacher.html index 7d50e1f..32e9b17 100644 --- a/courses/templates/subject/form_view_teacher.html +++ b/courses/templates/subject/form_view_teacher.html @@ -178,7 +178,7 @@
diff --git a/courses/views.py b/courses/views.py index 16d6253..051b25e 100644 --- a/courses/views.py +++ b/courses/views.py @@ -429,7 +429,11 @@ class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, gener self.object.subject = subject self.object.owner = self.request.user self.object.save() - + action = super(CreateTopicView, self).createorRetrieveAction("create Topic") + super(CreateTopicView, self).createNotification("Topic "+ self.object.name + " was created", + resource_name=self.object.name, resource_link= 'topics/'+self.object.slug, + actor=self.request.user, users = self.object.subject.course.students.all() ) + return super(CreateTopicView, self).form_valid(form) class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): diff --git a/forum/views.py b/forum/views.py index c857b74..e8ed7b3 100644 --- a/forum/views.py +++ b/forum/views.py @@ -10,6 +10,7 @@ from django.http import Http404 from .models import Forum, Post, PostAnswer from courses.models import Topic from core.mixins import NotificationMixin +from core.models import Action, Resource from .forms import ForumForm, PostForm, PostAnswerForm @@ -52,10 +53,12 @@ class CreateForumView(LoginRequiredMixin, generic.edit.CreateView, NotificationM def get_success_url(self): self.success_url = reverse('course:forum:render_forum', args = (self.object.id, )) - print(self.object) - print(self) - #super(CreateForumView, self).createNotification(message="The Forum",action_name="create forum", ) + + action = super(CreateForumView, self).createorRetrieveAction("create Topic") + super(CreateForumView, self).createNotification("Forum "+ self.object.name + " was created", + resource_name=self.object.name, resource_link= 'topics/'+self.object.slug, + actor=self.request.user, users = self.object.topic.subject.course.students.all() ) return self.success_url def render_forum(request, forum): -- libgit2 0.21.2