From ed90db29fef6d4370802020766241402bda83bcb Mon Sep 17 00:00:00 2001 From: Zambom Date: Fri, 27 Jan 2017 18:58:45 -0200 Subject: [PATCH] Adding notifications count badge --- amadeus/context_processors.py | 12 ++++++++++++ amadeus/settings.py | 3 ++- amadeus/static/css/base/amadeus.css | 39 +++++++++++++++++++++++---------------- amadeus/static/css/themes/green.css | 29 +++++++++++++++++++++++++++++ amadeus/templates/base.html | 18 ++++++++++++++---- categories/templatetags/category_counters.py | 14 ++++++++++++++ notifications/cron.py | 2 +- subjects/templates/subjects/badge.html | 3 +++ subjects/templates/subjects/list.html | 14 +++++++++----- subjects/templates/subjects/subject_card.html | 11 +++++++---- subjects/templatetags/subject_counter.py | 13 ++++++++++++- 11 files changed, 126 insertions(+), 32 deletions(-) create mode 100644 categories/templatetags/category_counters.py create mode 100644 subjects/templates/subjects/badge.html diff --git a/amadeus/context_processors.py b/amadeus/context_processors.py index ec6916a..b0e6349 100644 --- a/amadeus/context_processors.py +++ b/amadeus/context_processors.py @@ -1,4 +1,7 @@ +from datetime import datetime + from themes.models import Themes +from notifications.models import Notification def theme(request): context = {} @@ -7,4 +10,13 @@ def theme(request): context['theme'] = theme + return context + +def notifies(request): + context = {} + + notifications = Notification.objects.filter(creation_date = datetime.now()).count() + + context['notifications_count'] = notifications + return context \ No newline at end of file diff --git a/amadeus/settings.py b/amadeus/settings.py index a3b18bf..62302a1 100644 --- a/amadeus/settings.py +++ b/amadeus/settings.py @@ -103,6 +103,7 @@ TEMPLATES = [ 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'amadeus.context_processors.theme', + 'amadeus.context_processors.notifies', ], }, }, @@ -171,7 +172,7 @@ STATICFILES_DIRS = [ ] CRON_CLASSES = [ - 'notifications.cron.Test' + 'notifications.cron.Notify' ] #SECURITY diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index f450bfe..7b3b322 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -30,36 +30,28 @@ a:focus { .users-cloud .small a { font-size: 1.25em; - color: #2E8B57; } .users-cloud .big a { font-size: 2.25em; - color: #6B8E23; } .users-cloud .medium a { font-size: 1.75em; - color: #66CDAA; } .users-cloud .tiny a { font-size: 0.75em; - color: #654321; } .users-cloud a { text-decoration: none; } -#search-results-title{ - color: #BDBDBD; -} - .div-users-cloud{ - height: 100%; - margin-left: -10px; - width: 100%; + height: 100%; + margin-left: -10px; + width: 100%; } .my-subjects-title { @@ -590,11 +582,6 @@ a:focus { .subscribe-subject { border:none; } - -.no-subscribe-btn{ - background-color: #BDBDBD !important; - color: #F5F5F5 !important; -} /* subjects app ends */ /* Themes */ @@ -827,4 +814,24 @@ a.add-row { .add_resource ul { width: 100%; +} + +.action_icon { + position: relative; +} + +li.item .notify_badge { + top: 0px; + right: 0px; +} + +.notify_badge { + position: absolute; + right: 4px; + top: -5px; + width: 1.9rem; + line-height: 1.9rem; + font-size: 0.9rem; + border-radius: 50%; + padding: 0px; } \ No newline at end of file diff --git a/amadeus/static/css/themes/green.css b/amadeus/static/css/themes/green.css index d45cf47..18fa676 100644 --- a/amadeus/static/css/themes/green.css +++ b/amadeus/static/css/themes/green.css @@ -397,6 +397,35 @@ a.add-row { background-color: initial !important; } +.notify_badge { + background-color: #FF0000 !important; +} + +#search-results-title{ + color: #BDBDBD; +} + +.users-cloud .small a { + color: #2E8B57; +} + +.users-cloud .big a { + color: #6B8E23; +} + +.users-cloud .medium a { + color: #66CDAA; +} + +.users-cloud .tiny a { + color: #654321; +} + +.no-subscribe-btn{ + background-color: #BDBDBD !important; + color: #F5F5F5 !important; +} + @media(max-width: 768px) { .navbar .navbar-nav .dropdown .dropdown-menu li > a { color: #333333 !important; diff --git a/amadeus/templates/base.html b/amadeus/templates/base.html index 2b9a2b7..73ed2a2 100644 --- a/amadeus/templates/base.html +++ b/amadeus/templates/base.html @@ -160,8 +160,13 @@
  • -
  • - +
  • + + + {% if notifications_count > 0 %} + {% if notifications_count > 99 %} +99 {% else %} {{ notifications_count }} {% endif %} + {% endif %} +
  • @@ -204,8 +209,13 @@
  • -
  • - +
  • + + + {% if notifications_count > 0 %} + {% if notifications_count > 99 %} +99 {% else %} {{ notifications_count }} {% endif %} + {% endif %} +
  • diff --git a/categories/templatetags/category_counters.py b/categories/templatetags/category_counters.py new file mode 100644 index 0000000..44e516d --- /dev/null +++ b/categories/templatetags/category_counters.py @@ -0,0 +1,14 @@ +from django import template +from datetime import datetime + +from notifications.models import Notification + +register = template.Library() + +@register.inclusion_tag('subjects/badge.html') +def notifies_cat_number(category): + context = {} + + context['number'] = Notification.objects.filter(task__resource__topic__subject__category = category, creation_date = datetime.now()).count() + + return context \ No newline at end of file diff --git a/notifications/cron.py b/notifications/cron.py index 82389fb..5b72fcb 100644 --- a/notifications/cron.py +++ b/notifications/cron.py @@ -3,7 +3,7 @@ from django_cron import CronJobBase, Schedule from .utils import set_notifications -class Test(CronJobBase): +class Notify(CronJobBase): RUN_EVERY_MINS = 1 # every minute schedule = Schedule(run_every_mins=RUN_EVERY_MINS) diff --git a/subjects/templates/subjects/badge.html b/subjects/templates/subjects/badge.html new file mode 100644 index 0000000..7f5d86c --- /dev/null +++ b/subjects/templates/subjects/badge.html @@ -0,0 +1,3 @@ +{% if number > 0 %} + {% if number > 99 %} +99 {% else %} {{ number }} {% endif %} +{% endif %} \ No newline at end of file diff --git a/subjects/templates/subjects/list.html b/subjects/templates/subjects/list.html index 07e1533..f147820 100644 --- a/subjects/templates/subjects/list.html +++ b/subjects/templates/subjects/list.html @@ -1,7 +1,7 @@ {% extends 'categories/home.html' %} {% load static i18n pagination %} -{% load django_bootstrap_breadcrumbs subject_counter %} +{% load django_bootstrap_breadcrumbs subject_counter category_counters %} {% block javascript%} {{ block.super }} @@ -79,10 +79,14 @@
  • {% endif %} - - - - + + + + + {% notifies_cat_number category %} + + + diff --git a/subjects/templates/subjects/subject_card.html b/subjects/templates/subjects/subject_card.html index 06e3564..9413f24 100644 --- a/subjects/templates/subjects/subject_card.html +++ b/subjects/templates/subjects/subject_card.html @@ -36,10 +36,13 @@ - - - - + + + + {% notifies_number subject %} + + + diff --git a/subjects/templatetags/subject_counter.py b/subjects/templatetags/subject_counter.py index 379ac7f..0b9ac1d 100644 --- a/subjects/templatetags/subject_counter.py +++ b/subjects/templatetags/subject_counter.py @@ -1,5 +1,9 @@ -from django import template import datetime +from django import template +from django.db.models import Q + +from notifications.models import Notification + register = template.Library() @register.filter(name = 'subject_count') @@ -15,6 +19,13 @@ def subject_count(category, user): return total +@register.inclusion_tag('subjects/badge.html') +def notifies_number(subject): + context = {} + + context['number'] = Notification.objects.filter(task__resource__topic__subject = subject, creation_date = datetime.datetime.now()).count() + + return context @register.filter(name = 'aftertoday') def after_today(date): -- libgit2 0.21.2