Commit 344aa07debdc74120452f9759453c1e8a4728913

Authored by fbormann
1 parent a8a36303

testing notifications again

app/views.py
... ... @@ -18,8 +18,10 @@ class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin):
18 18 context_object_name = 'objects'
19 19 paginate_by = 10
20 20  
21   - not_action = "Acessar"
22   - not_resource = "home"
  21 + action_name = "Acessar"
  22 + resource_name = "home"
  23 + users = User.objects.all()
  24 + message="testing login and notification broadcast"
23 25  
24 26 def get_queryset(self):
25 27 if self.request.user.is_staff:
... ... @@ -43,7 +45,7 @@ class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin):
43 45 else:
44 46 self.template_name = "home_teacher_student_content.html"
45 47  
46   -
  48 + super(AppIndex, self).createNotification("testando notificacao de login", resource_name="home", resource_link="/login")
47 49 return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs)
48 50  
49 51  
... ...
core/decorators.py
... ... @@ -53,7 +53,7 @@ def notification_decorator(read = False, message = '', actor = None, users = [],
53 53  
54 54 def _decorator(request, *args, **kwargs):
55 55 #Do something before the call
56   -
  56 +
57 57 response = view_function(request, *args, **kwargs)
58 58 action = Action.objects.filter(name = not_action)
59 59 resource = Resource.objects.filter(name = not_resource)
... ...
core/mixins.py
... ... @@ -41,24 +41,23 @@ class LogMixin(object):
41 41 class NotificationMixin(object):
42 42 message = ""
43 43 read = False
44   - not_action = ''
45   - not_resource = ''
  44 + action_name = ''
  45 + resource_name = ''
46 46  
47   - def createNotification(self, message='', actor=None, users = User.objects.all(), not_action = '', not_resource='', resource_link=''): #the default will be a broadcast
48   - action = Action.objects.filter(name = self.not_action)
49   - resource = Resource.objects.filter(name = not_resource)
50   - print(resource_link)
  47 + def createNotification(self, message='', actor=None, users = User.objects.all(), action_name = '', resource_name='', resource_link=''): #the default will be a broadcast
  48 + action = Action.objects.filter(name = action_name)
  49 + resource = Resource.objects.filter(name = resource_name)
  50 + print(message)
51 51 if action.exists():
52 52 action = action[0]
53 53 else:
54   - action = Action(name = self.not_action)
  54 + action = Action(name = self.action_name)
55 55 action.save()
56 56  
57 57 if resource.exists():
58 58 resource = resource[0]
59 59 else:
60   - resource = Resource(name = self.not_resource, url= resource_link)
61   - print(resource)
  60 + resource = Resource(name = self.resource_name, url= resource_link)
62 61 resource.save()
63 62  
64 63 action_resource = Action_Resource.objects.filter(action = action, resource = resource)
... ... @@ -77,4 +76,5 @@ class NotificationMixin(object):
77 76 def dispatch(self, request, *args, **kwargs):
78 77 """
79 78 Not quite sure how to do about it"""
  79 + print("testing IF IT REACHES HERE")
80 80 return super(NotificationMixin, self).dispatch(request, *args, **kwargs)
81 81 \ No newline at end of file
... ...
core/views.py
... ... @@ -92,8 +92,8 @@ def processNotification(self, notificationId):
92 92 notification = Notification.objects.get(id= notificationId)
93 93 notification.read = True
94 94 notification.save()
95   -
96   - return redirect(notification.action_resource.resource.link)
  95 + print(notification.action_resource)
  96 + return redirect(notification.action_resource.resource.url)
97 97  
98 98 # class LoginClass(LoginView):
99 99 # template_name='index.html'
... ...
courses/views.py
... ... @@ -15,6 +15,7 @@ from rolepermissions.verifications import has_object_permission
15 15 from .forms import CourseForm, UpdateCourseForm, CategoryForm, SubjectForm,TopicForm
16 16 from .models import Course, Subject, Category,Topic
17 17 from core.mixins import NotificationMixin
  18 +from users.models import User
18 19  
19 20 from datetime import date
20 21  
... ... @@ -30,7 +31,7 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView):
30 31 def get_context_data(self, **kwargs):
31 32 context = super(IndexView, self).get_context_data(**kwargs)
32 33 context['categories'] = Category.objects.all()
33   -
  34 + super.createNotification(users= User.obejcts.all(), message="testando a notificacao em login")
34 35 return context
35 36  
36 37 class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,generic.edit.CreateView):
... ...