From 0aef7656b8f94207954316ff2f453aea0f0a0b3c Mon Sep 17 00:00:00 2001 From: Skia Date: Sat, 7 Jan 2017 15:07:28 +0100 Subject: [PATCH] Add quick notifications prototype --- core/static/core/js/script.js | 3 +++ core/static/core/style.css | 9 +++++++++ core/templates/core/base.jinja | 6 ++++++ core/views/__init__.py | 28 ++++++++++++++++++++++++++++ sith/settings.py | 7 +++++++ 5 files changed, 53 insertions(+) diff --git a/core/static/core/js/script.js b/core/static/core/js/script.js index 714e2d12..c30264bf 100644 --- a/core/static/core/js/script.js +++ b/core/static/core/js/script.js @@ -35,6 +35,9 @@ $( function() { popup.html('
'); popup.dialog({title: $(this).text()}).dialog( "open" ); }); + $("#quick_notif li").click(function () { + $(this).hide(); + }) } ); function display_notif() { diff --git a/core/static/core/style.css b/core/static/core/style.css index c1a753f5..d5aef3de 100644 --- a/core/static/core/style.css +++ b/core/static/core/style.css @@ -122,6 +122,15 @@ nav a:hover { } /*--------------------------------CONTENT------------------------------*/ +#quick_notif { + width: 90%; + margin: 0px auto; + list-style-type: none; + background: lightblue; +} +#quick_notif li { + padding: 10px; +} #content { width: 88%; margin: 0px auto; diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index ae77cd85..72a2ab83 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -100,6 +100,12 @@ {% endif %} {% endblock %} + +
{% if list_of_tabs %}
diff --git a/core/views/__init__.py b/core/views/__init__.py index c682ec71..da9e09a2 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -147,6 +147,34 @@ class TabedViewMixin(View): kwargs['list_of_tabs'] = self.get_list_of_tabs() return kwargs +class QuickNotifMixin(): + quick_notif_list = [] + def get_success_url(self): + ret = super(QuickNotifMixin, self).get_success_url() + try: + if '?' in ret: + ret += '&' + self.quick_notif_url_arg + else: + ret += '?' + self.quick_notif_url_arg + except: pass + return ret + + def get_context_data(self, **kwargs): + """Add quick notifications to context""" + kwargs = super(QuickNotifMixin, self).get_context_data(**kwargs) + kwargs['quick_notifs'] = [] + print(self.quick_notif_list) + for n in self.quick_notif_list: + kwargs['quick_notifs'].append(settings.SITH_QUICK_NOTIF[n]) + self.quick_notif_list = [] # In some cases, the class can stay instanciated, so we need to reset the list + for k,v in settings.SITH_QUICK_NOTIF.items(): + for gk in self.request.GET.keys(): + if k == gk: + kwargs['quick_notifs'].append(v) + print(self.quick_notif_list) + return kwargs + + from .user import * from .page import * from .files import * diff --git a/sith/settings.py b/sith/settings.py index e2afe980..11dbdb9c 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -466,6 +466,13 @@ SITH_NOTIFICATIONS = [ ('GENERIC', _("You have a notification")), ] +SITH_QUICK_NOTIF = { + 'qn_success': _("Success!"), + 'qn_fail': _("Fail!"), + 'qn_weekmail_new_article': _("You successfully posted an article in the Weekmail"), + 'qn_weekmail_article_edit': _("You successfully edited an article in the Weekmail"), + } + try: from .settings_custom import * print("Custom settings imported")