Project for the UPV to develop an app like BlaBlaCar but only for UPV people.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

notifications view

+116
+1
upvcarshare/config/settings/base.py
··· 122 122 'django.template.context_processors.tz', 123 123 'django.contrib.messages.context_processors.messages', 124 124 'django.template.context_processors.request', 125 + 'notifications.context_processors.notifications', 125 126 ], 126 127 'loaders': [ 127 128 'django.template.loaders.filesystem.Loader',
+1
upvcarshare/config/urls.py
··· 14 14 url(r"^", include("pages.urls", namespace="pages")), 15 15 url(r"^users/", include("users.urls", namespace="users")), 16 16 url(r"^journeys/", include("journeys.urls", namespace="journeys")), 17 + url(r"^notifications/", include("notifications.urls", namespace="notifications")), 17 18 ] 18 19 19 20 # Admin URLs
+14
upvcarshare/notifications/context_processors.py
··· 1 + # -*- coding: utf-8 -*- 2 + from __future__ import unicode_literals, print_function, absolute_import 3 + 4 + from notifications.models import Notification 5 + 6 + 7 + def notifications(request): 8 + """Adds to the context the number or unread notifications.""" 9 + unread_notifications = 0 10 + if request.user.is_authenticated(): 11 + unread_notifications = Notification.objects.unread(user=request.user).count() 12 + return { 13 + "unread_notifications": unread_notifications, 14 + }
+3
upvcarshare/notifications/manager.py
··· 19 19 20 20 class NotificationManager(models.Manager): 21 21 22 + def unread(self, user): 23 + return self.filter(user=user, read=False) 24 + 22 25 def create_from_method_call(self, verb, function, args, kwargs): 23 26 """Creates a notification from a decorator call. 24 27 :param verb:
+11
upvcarshare/notifications/urls.py
··· 1 + # -*- coding: utf-8 -*- 2 + from __future__ import unicode_literals, print_function, absolute_import 3 + 4 + from django.conf.urls import url 5 + 6 + from notifications.views import NotificationListView, ReadNotificationsView 7 + 8 + urlpatterns = [ 9 + url(r"read/$", ReadNotificationsView.as_view(), name="read"), 10 + url(r"$", NotificationListView.as_view(), name="list"), 11 + ]
+31
upvcarshare/notifications/views.py
··· 1 + # -*- coding: utf-8 -*- 2 + from __future__ import unicode_literals, print_function, absolute_import 3 + 4 + from braces.views import LoginRequiredMixin 5 + from django.shortcuts import render, redirect 6 + from django.views.generic import View 7 + 8 + from notifications.models import Notification 9 + 10 + 11 + class NotificationListView(LoginRequiredMixin, View): 12 + """View to list all the notifications of the user.""" 13 + template_name = "notifications/list.html" 14 + 15 + def get(self, request): 16 + notifications = Notification.objects.filter(user=request.user) 17 + data = { 18 + "notifications": notifications 19 + } 20 + return render(request, self.template_name, data) 21 + 22 + 23 + class ReadNotificationsView(LoginRequiredMixin, View): 24 + """Sets all notifications as read.""" 25 + 26 + @staticmethod 27 + def post(request): 28 + notifications = Notification.objects.filter(user=request.user, read=False) 29 + notifications.update(read=True) 30 + return redirect("notifications:list") 31 +
+11
upvcarshare/static/src/sass/notifications.scss
··· 1 + // Styles for notifications 2 + @import "colors"; 3 + 4 + .notification { 5 + padding: 10px; 6 + border-bottom: 1px dotted $upv-grey; 7 + margin-bottom: 5px; 8 + &-unread { 9 + background-color: #eee; 10 + } 11 + }
+1
upvcarshare/static/src/sass/project.scss
··· 13 13 @import "patches"; 14 14 @import "journeys"; 15 15 @import "colors"; 16 + @import "notifications"; 16 17 17 18 html, body{ 18 19 height:100%;
+11
upvcarshare/templates/header.html
··· 23 23 <div class="container section-navbar"> 24 24 <nav class="navbar navbar-full navbar-dark bg-upv-dark-grey"> 25 25 {# <a class="navbar-brand" href="{% url "home" %}">{% trans "Compartir Coche en la UPV" %}</a>#} 26 + 26 27 {% if request.user.is_authenticated %} 28 + <ul class="nav navbar-nav pull-xs-left"> 29 + <li class="nav-item"> 30 + <a class="nav-link" href="{% url "notifications:list" %}"> 31 + {% trans "Notificaciones" %} 32 + {% if unread_notifications > 0 %} 33 + <span class="label label-pill label-danger">{{ unread_notifications }}</span> 34 + {% endif %} 35 + </a> 36 + </li> 37 + </ul> 27 38 <ul class="nav navbar-nav pull-xs-right"> 28 39 <li class="nav-item"> 29 40 <a class="nav-link" href="{% url "journeys:recommended" %}">{% trans "Buscador" %}</a>
+32
upvcarshare/templates/notifications/list.html
··· 1 + {% extends "header.html" %} 2 + {% load i18n %} 3 + 4 + {% block section_title %} 5 + <div class="row"> 6 + <div class="col-sm-12"> 7 + <h2>{% trans "Notificationes" %}</h2> 8 + </div> 9 + </div> 10 + {% endblock section_title %} 11 + 12 + {% block content %} 13 + <div class="row"> 14 + <div class="col-xs-12"> 15 + <form action="{% url "notifications:read" %}" method="post"> 16 + {% csrf_token %} 17 + <button type="submit" class="btn btn-primary">{% trans "Marcar como leidas"%}</button> 18 + </form> 19 + <hr /> 20 + </div> 21 + </div> 22 + {% for notification in notifications %} 23 + <div class="notification {% if not notification.read %}notification-unread{% endif %}"> 24 + <div class="row"> 25 + <div class="col-xs-12"> 26 + <p class="lead">{{ notification.text }}</p> 27 + <p class="text-muted">{{ notification.created }}</p> 28 + </div> 29 + </div> 30 + </div> 31 + {% endfor %} 32 + {% endblock content %}