From d23923a248bcd46d942c582632634b6b3f8169f0 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 18 Nov 2011 23:42:31 +0100 Subject: [PATCH] If the demo application is activated, an announcement now appears on the login page to inform visitors on how to use the demo. --- auth/views.py | 4 +- demo/__init__.py | 8 +++ demo/templates/demo/login_announcement.html | 13 +++++ doc/plugin_api.rst | 13 ++++- extensions/stats/grapher.py | 2 +- lib/events.py | 4 +- static/css/login.css | 58 ++++++++++++++------- templates/registration/login.html | 8 +-- 8 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 demo/templates/demo/login_announcement.html diff --git a/auth/views.py b/auth/views.py index fc424e48b..6a08f5d7d 100755 --- a/auth/views.py +++ b/auth/views.py @@ -39,9 +39,11 @@ def dologin(request): error = _("Your username and password didn't match. Please try again.") else: form = LoginForm() + next = request.GET.has_key("next") and request.GET["next"] or None return render_to_response("registration/login.html", { - "form" : form, "error" : error, "next" : next + "form" : form, "error" : error, "next" : next, + "annoucements" : events.raiseQueryEvent("GetAnnouncement", target="loginpage") }, context_instance=RequestContext(request)) def dologout(request): diff --git a/demo/__init__.py b/demo/__init__.py index 24e439289..c6fcc4bad 100755 --- a/demo/__init__.py +++ b/demo/__init__.py @@ -2,6 +2,7 @@ from django.conf import settings from django.core.urlresolvers import reverse from django.utils.translation import ugettext_noop as _ +from django.template.loader import render_to_string from modoboa.lib import events from modoboa.lib.webutils import static_url @@ -28,5 +29,12 @@ def menu(**kwargs): } ] +def announcement(**kwargs): + if kwargs["target"] == "loginpage": + txt = render_to_string("demo/login_announcement.html") + return [txt] + return "" + if 'modoboa.demo' in settings.INSTALLED_APPS: events.register("UserMenuDisplay", menu) + events.register("GetAnnouncement", announcement) diff --git a/demo/templates/demo/login_announcement.html b/demo/templates/demo/login_announcement.html new file mode 100644 index 000000000..7513ab318 --- /dev/null +++ b/demo/templates/demo/login_announcement.html @@ -0,0 +1,13 @@ +{% load i18n %} +{% blocktrans %} +

Welcome to the online demo!

+

Warning: the demo's concent is resetted every two hours.

+

To try the demo, the following users are available (username/password):

+ +

Please report any issue of give any suggestion to + the mailing list.

+{% endblocktrans %} diff --git a/doc/plugin_api.rst b/doc/plugin_api.rst index 50e5f9533..ba48a4036 100644 --- a/doc/plugin_api.rst +++ b/doc/plugin_api.rst @@ -126,7 +126,7 @@ that corresponds to the ``Request`` object used inside the associated view function. UserLogout -__________ +---------- Raised when a user logs out. This event provides a ``request`` argument that corresponds to the ``Request`` object used inside the associated @@ -245,6 +245,17 @@ ExtDisabled Raised just after an extension has been disabled. The Extension object is available inside the ``ext`` keyword argument. +GetAnnouncement +--------------- + +Some places in the interface let plugins add their own announcement +(ie. message). A keyword argument ``target`` is provided to registered +callbacks and indicates the place where the announcement will appear: + +* ``loginpage`` : corresponds to the login page + +Callbacks listening to this event must return a list of string. + Parameters ========== diff --git a/extensions/stats/grapher.py b/extensions/stats/grapher.py index ad52da760..2dfd5d3e7 100644 --- a/extensions/stats/grapher.py +++ b/extensions/stats/grapher.py @@ -3,7 +3,7 @@ import os import time import datetime -import rrdtool +#import rrdtool from django.utils.translation import ugettext as _ from modoboa.lib import parameters diff --git a/lib/events.py b/lib/events.py index 460e35276..631486e26 100644 --- a/lib/events.py +++ b/lib/events.py @@ -22,7 +22,9 @@ events = ["CreateDomain", "ExtDisabled", "UserLogin", - "UserLogout"] + "UserLogout", + + "GetAnnouncement"] callbacks = {} diff --git a/static/css/login.css b/static/css/login.css index 798736283..70fd8145c 100644 --- a/static/css/login.css +++ b/static/css/login.css @@ -7,26 +7,10 @@ html, body { } #loginbox { - margin: 100px auto; - width: 610px; - padding-bottom: 15px; - background: white; - - border: 5px solid #333; - /*-moz-box-shadow: 0 10px 30px #222;*/ - -webkit-box-shadow: 0 10px 30px #222; - -moz-border-radius: 10px; - -webkit-border-radius: 5px; -} - -#loginbox h2 { - margin: 30px 10px 0 10px; - font-size: small; -} - -#loginbox h3 { - font-size: small; - text-align: center; + margin: 100px auto 10px auto; + padding: 0 0 15px 0; + font-size: 1em; + width: 630px; } #logo { @@ -46,6 +30,40 @@ html, body { width: 300px; } +.roundedbox { + margin: 10px auto; + padding: 10px; + width: 610px; + background: white; + font-size: 1.1em; + + border: 5px solid #333; + border-radius: 10px; +} + +.roundedbox h1 { + padding: 0; + margin: 0; + font-size: 1.2em; + text-align: center; +} + +.roundedbox h2 { + margin: 30px 10px 0 10px; + font-size: small; +} + +.roundedbox h3 { + font-size: small; + text-align: center; +} + +.roundedbox a, a:visited { + font-weight: bold; + color: black; + text-decoration: none; +} + .spacer { clear: both; } diff --git a/templates/registration/login.html b/templates/registration/login.html index ed8034ab9..08af52fbc 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -16,7 +16,7 @@ -
+
+ {% for annoucement in annoucements %} +
{{ annoucement|safe }}
+ {% endfor %}