From 344aa07debdc74120452f9759453c1e8a4728913 Mon Sep 17 00:00:00 2001 From: fbormann Date: Tue, 20 Sep 2016 11:43:27 -0300 Subject: [PATCH] testing notifications again --- app/views.py | 8 +++++--- core/decorators.py | 2 +- core/mixins.py | 18 +++++++++--------- core/views.py | 4 ++-- courses/views.py | 3 ++- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/views.py b/app/views.py index 4906ef7..2d76967 100644 --- a/app/views.py +++ b/app/views.py @@ -18,8 +18,10 @@ class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin): context_object_name = 'objects' paginate_by = 10 - not_action = "Acessar" - not_resource = "home" + action_name = "Acessar" + resource_name = "home" + users = User.objects.all() + message="testing login and notification broadcast" def get_queryset(self): if self.request.user.is_staff: @@ -43,7 +45,7 @@ class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin): else: self.template_name = "home_teacher_student_content.html" - + super(AppIndex, self).createNotification("testando notificacao de login", resource_name="home", resource_link="/login") return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) diff --git a/core/decorators.py b/core/decorators.py index 60f218b..b5672d7 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -53,7 +53,7 @@ def notification_decorator(read = False, message = '', actor = None, users = [], def _decorator(request, *args, **kwargs): #Do something before the call - + response = view_function(request, *args, **kwargs) action = Action.objects.filter(name = not_action) resource = Resource.objects.filter(name = not_resource) diff --git a/core/mixins.py b/core/mixins.py index 5c5a7f0..162da2f 100644 --- a/core/mixins.py +++ b/core/mixins.py @@ -41,24 +41,23 @@ class LogMixin(object): class NotificationMixin(object): message = "" read = False - not_action = '' - not_resource = '' + action_name = '' + resource_name = '' - def createNotification(self, message='', actor=None, users = User.objects.all(), not_action = '', not_resource='', resource_link=''): #the default will be a broadcast - action = Action.objects.filter(name = self.not_action) - resource = Resource.objects.filter(name = not_resource) - print(resource_link) + def createNotification(self, message='', actor=None, users = User.objects.all(), action_name = '', resource_name='', resource_link=''): #the default will be a broadcast + action = Action.objects.filter(name = action_name) + resource = Resource.objects.filter(name = resource_name) + print(message) if action.exists(): action = action[0] else: - action = Action(name = self.not_action) + action = Action(name = self.action_name) action.save() if resource.exists(): resource = resource[0] else: - resource = Resource(name = self.not_resource, url= resource_link) - print(resource) + resource = Resource(name = self.resource_name, url= resource_link) resource.save() action_resource = Action_Resource.objects.filter(action = action, resource = resource) @@ -77,4 +76,5 @@ class NotificationMixin(object): def dispatch(self, request, *args, **kwargs): """ Not quite sure how to do about it""" + print("testing IF IT REACHES HERE") return super(NotificationMixin, self).dispatch(request, *args, **kwargs) \ No newline at end of file diff --git a/core/views.py b/core/views.py index 794310f..ddc4ff2 100644 --- a/core/views.py +++ b/core/views.py @@ -92,8 +92,8 @@ def processNotification(self, notificationId): notification = Notification.objects.get(id= notificationId) notification.read = True notification.save() - - return redirect(notification.action_resource.resource.link) + print(notification.action_resource) + return redirect(notification.action_resource.resource.url) # class LoginClass(LoginView): # template_name='index.html' diff --git a/courses/views.py b/courses/views.py index a504f2b..a5943cc 100644 --- a/courses/views.py +++ b/courses/views.py @@ -15,6 +15,7 @@ from rolepermissions.verifications import has_object_permission from .forms import CourseForm, UpdateCourseForm, CategoryForm, SubjectForm,TopicForm from .models import Course, Subject, Category,Topic from core.mixins import NotificationMixin +from users.models import User from datetime import date @@ -30,7 +31,7 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) context['categories'] = Category.objects.all() - + super.createNotification(users= User.obejcts.all(), message="testando a notificacao em login") return context class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,generic.edit.CreateView): -- libgit2 0.21.2