Commit a18628bd4e9f1844019c5531a26a646df2d545c1

Authored by fbormann
1 parent 780ddd53

Finally, I have finished the issue, completed the cycle and added url support, l…

…ink now connects to another url and add read to True #41
amadeus/settings.py
@@ -92,8 +92,8 @@ DATABASES = { @@ -92,8 +92,8 @@ DATABASES = {
92 'default': { 92 'default': {
93 'ENGINE': 'django.db.backends.postgresql', 93 'ENGINE': 'django.db.backends.postgresql',
94 'NAME': 'amadeus', 94 'NAME': 'amadeus',
95 - 'USER': 'amadeus_admin',  
96 - 'PASSWORD': 'amadeus', 95 + 'USER': 'postgres',
  96 + 'PASSWORD': 'felipe',
97 'HOST': '127.0.0.1', 97 'HOST': '127.0.0.1',
98 'PORT': '5432', 98 'PORT': '5432',
99 } 99 }
@@ -38,7 +38,7 @@ class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin): @@ -38,7 +38,7 @@ class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin):
38 if self.request.is_ajax(): 38 if self.request.is_ajax():
39 self.template_name = "home_admin_content.html" 39 self.template_name = "home_admin_content.html"
40 40
41 - #super(AppIndex, self).createNotification("teste", not_resource="home", resource_link="users") 41 + super(AppIndex, self).createNotification("teste", not_resource="home", resource_link="/register")
42 42
43 notifications = Notification.objects.filter(user= self.request.user, read=False) 43 notifications = Notification.objects.filter(user= self.request.user, read=False)
44 context['notifications'] = notifications 44 context['notifications'] = notifications
core/mixins.py
@@ -47,7 +47,7 @@ class NotificationMixin(object): @@ -47,7 +47,7 @@ class NotificationMixin(object):
47 def createNotification(self, message='', actor=None, users = User.objects.all(), not_action = '', not_resource='', resource_link=''): #the default will be a broadcast 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) 48 action = Action.objects.filter(name = self.not_action)
49 resource = Resource.objects.filter(name = not_resource) 49 resource = Resource.objects.filter(name = not_resource)
50 - 50 + print(resource_link)
51 if action.exists(): 51 if action.exists():
52 action = action[0] 52 action = action[0]
53 else: 53 else:
@@ -58,6 +58,7 @@ class NotificationMixin(object): @@ -58,6 +58,7 @@ class NotificationMixin(object):
58 resource = resource[0] 58 resource = resource[0]
59 else: 59 else:
60 resource = Resource(name = self.not_resource, link= resource_link) 60 resource = Resource(name = self.not_resource, link= resource_link)
  61 + print(resource)
61 resource.save() 62 resource.save()
62 63
63 action_resource = Action_Resource.objects.filter(action = action, resource = resource) 64 action_resource = Action_Resource.objects.filter(action = action, resource = resource)
core/templates/base.html
@@ -53,13 +53,13 @@ @@ -53,13 +53,13 @@
53 <div class="navbar-collapse collapse navbar-responsive-collapse"> 53 <div class="navbar-collapse collapse navbar-responsive-collapse">
54 <ul class="nav navbar-nav navbar-right notifications"> 54 <ul class="nav navbar-nav navbar-right notifications">
55 <li class="" data-toggle="tooltip" data-placement="bottom" title data-original-title="notifications"> 55 <li class="" data-toggle="tooltip" data-placement="bottom" title data-original-title="notifications">
56 - <a href="../user/profile_user.html" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bell-o" aria-hidden="true"></i></a> 56 + <a class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bell-o" aria-hidden="true"></i></a>
57 <ul class="dropdown-menu"> 57 <ul class="dropdown-menu">
58 <li class="dropdown-header">Notifications</li> 58 <li class="dropdown-header">Notifications</li>
59 {% for notification in notifications %} 59 {% for notification in notifications %}
60 {% if notification.actor %} <!-- if the notification has a user--> 60 {% if notification.actor %} <!-- if the notification has a user-->
61 <li> 61 <li>
62 - <a href="{{ notification.action_resource.resource.link }}"><div class="list-group-item"> 62 + <a href="{% url 'core:notification_read' notification.id %}"><div class="list-group-item">
63 <div class="row-picture"> 63 <div class="row-picture">
64 <img class="circle" src="http://lorempixel.com/56/56/people/1" alt="icon"> 64 <img class="circle" src="http://lorempixel.com/56/56/people/1" alt="icon">
65 <div class="least-content pull-right">{{ notification.datetime }}</div> 65 <div class="least-content pull-right">{{ notification.datetime }}</div>
@@ -72,7 +72,7 @@ @@ -72,7 +72,7 @@
72 </li> 72 </li>
73 {% else %} 73 {% else %}
74 <li> 74 <li>
75 - <a href="{{ notification.action_resource.resource.link }}"> 75 + <a href="{% url 'core:notification_read' notification.id %}">
76 <div class="list-group-item"> 76 <div class="list-group-item">
77 <div class="row-action-primary"> 77 <div class="row-action-primary">
78 <i class="material-icons">folder</i> 78 <i class="material-icons">folder</i>
@@ -9,4 +9,5 @@ urlpatterns = [ @@ -9,4 +9,5 @@ urlpatterns = [
9 url(r'^register/$', views.RegisterUser.as_view(), name='register'), 9 url(r'^register/$', views.RegisterUser.as_view(), name='register'),
10 url(r'^remember_password/$', views.remember_password, name='remember_password'), 10 url(r'^remember_password/$', views.remember_password, name='remember_password'),
11 url(r'^logout/$', auth_views.logout, {'next_page': 'core:home'}, name='logout'), 11 url(r'^logout/$', auth_views.logout, {'next_page': 'core:home'}, name='logout'),
  12 + url(r'^notification/([0-9]+)/$', views.processNotification, name='notification_read')
12 ] 13 ]
@@ -10,7 +10,7 @@ from django.http import HttpResponse @@ -10,7 +10,7 @@ from django.http import HttpResponse
10 from django.core.mail import send_mail,BadHeaderError 10 from django.core.mail import send_mail,BadHeaderError
11 from django.conf import settings 11 from django.conf import settings
12 from core.mixins import NotificationMixin 12 from core.mixins import NotificationMixin
13 - 13 +from .models import Notification
14 from rolepermissions.shortcuts import assign_role 14 from rolepermissions.shortcuts import assign_role
15 15
16 from .forms import RegisterUserForm 16 from .forms import RegisterUserForm
@@ -87,6 +87,14 @@ def login(request): @@ -87,6 +87,14 @@ def login(request):
87 return render(request,"index.html",context) 87 return render(request,"index.html",context)
88 88
89 89
  90 +
  91 +def processNotification(self, notificationId):
  92 + notification = Notification.objects.get(id= notificationId)
  93 + notification.read = True
  94 + notification.save()
  95 +
  96 + return redirect(notification.action_resource.resource.link)
  97 +
90 # class LoginClass(LoginView): 98 # class LoginClass(LoginView):
91 # template_name='index.html' 99 # template_name='index.html'
92 # 100 #