diff --git a/core/context_processors.py b/core/context_processors.py index cd4dcf8..9c6daaa 100644 --- a/core/context_processors.py +++ b/core/context_processors.py @@ -5,6 +5,6 @@ def notifications(request): context['notifications'] = None if request.user.is_authenticated: return { - 'notifications': Notification.objects.filter(user= request.user, read=False).order_by('-datetime') + 'notifications': Notification.objects.filter(user= request.user, read=False).order_by('-datetime')[0:5] } return context diff --git a/core/static/js/base/amadeus.js b/core/static/js/base/amadeus.js index 6baf3b0..2f407e5 100644 --- a/core/static/js/base/amadeus.js +++ b/core/static/js/base/amadeus.js @@ -126,4 +126,14 @@ function validarCpfSemAlert(campo,nome,idElementoMensagemErro){ return true; } return retorno; -} \ No newline at end of file +} + +/* +This functions get the next 5 notifications from the user given a "step"(an amount) of previous notifications +*/ +function getNotifications(step){ + $.get('/getNotifications', + {'steps':step, 'amount': 5}, function(data){ + console.log(data); + }); +} diff --git a/core/static/js/base/header.js b/core/static/js/base/header.js index 9375087..fbf2635 100644 --- a/core/static/js/base/header.js +++ b/core/static/js/base/header.js @@ -6,8 +6,8 @@ $(document).ready(function(){ /* */ -function loadNotifications(step){ - $.ajax('/loadNotifications',{ +function getNotifications(step){ + $.ajax('/getNotifications',{ steps: step, amount: 5, sucess: function(response){ diff --git a/core/templates/base.html b/core/templates/base.html index 819160f..df40728 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -64,7 +64,7 @@ {% include "notifications.html" %}
  • - +

    See More

    diff --git a/core/templates/notifications.html b/core/templates/notifications.html index c691d8c..7a643fd 100644 --- a/core/templates/notifications.html +++ b/core/templates/notifications.html @@ -1,31 +1,31 @@ {% for notification in notifications %} - {% if notification.actor %} -
  • -
    -
    - icon -
    {{ notification.datetime }}
    -
    -
    -

    {{ notification.message }}

    -
    -
    -
    -
  • - {% else %} -
  • - -
    -
    - folder -
    -
    + {% if notification.actor %} +
  • +
    +
    + icon +
    {{ notification.datetime }}
    +
    +
    +

    {{ notification.message }}

    +
    +
    +
    +
  • + {% else %} +
  • + +
    +
    + folder +
    +
    -
    {{ notification.datetime }}
    +
    {{ notification.datetime }}
    -

    {{ notification.message }}

    -
    -
    -
  • - {% endif %} - {% endfor %} \ No newline at end of file +

    {{ notification.message }}

    + + + + {% endif %} +{% endfor %} \ No newline at end of file diff --git a/core/urls.py b/core/urls.py index 35de1eb..032c1f7 100644 --- a/core/urls.py +++ b/core/urls.py @@ -9,5 +9,6 @@ urlpatterns = [ url(r'^register/$', views.RegisterUser.as_view(), name='register'), url(r'^remember_password/$', views.remember_password, name='remember_password'), url(r'^logout/$', auth_views.logout, {'next_page': 'core:home'}, name='logout'), - url(r'^notification/([0-9]+)/$', views.processNotification, name='notification_read') + url(r'^notification/([0-9]+)/$', views.processNotification, name='notification_read'), + url(r'^getNotifications/$', views.getNotifications, name='getNotifications'), ] diff --git a/core/views.py b/core/views.py index f3e27c7..a6ff906 100644 --- a/core/views.py +++ b/core/views.py @@ -5,6 +5,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from .decorators import log_decorator from django.contrib import messages from django.shortcuts import render, redirect +from django.template.loader import render_to_string from django.views.generic import CreateView, UpdateView from django.http import HttpResponse, JsonResponse from django.core.mail import send_mail,BadHeaderError @@ -97,13 +98,23 @@ def processNotification(self, notificationId): -def getNotifications(self, amount, step=0): - if self.request.is_ajax and self.request.user.is_authenticated: - notifications = Notification.objects.filter(user= self.request.user, read=False).orderby('-datetime')[step:amount] + +def getNotifications(request): + context = {} + if request.user.is_authenticated: + + steps = int(request.GET['steps']) + amount = int(request.GET['amount']) + notifications = Notification.objects.filter(user= request.user, read=False).order_by('-datetime')[steps:steps+amount] + context['notifications'] = notifications else: #go to login page - return response('teste') + return HttpResponse('teste') - return JsonResponse(notifications) + + html = render_to_string("notifications.html", context) + print(html) + return HttpResponse(html) + -- libgit2 0.21.2