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