From df8bd845203f60f19a626fbdfaf41ee9f4a802c8 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 17 Jan 2010 01:19:42 +0200 Subject: [PATCH] Flash message styling, form styling, multiple static directories. --- scribeengine/config/environment.py | 29 ++++++++---- scribeengine/config/middleware.py | 5 +- scribeengine/controllers/admin.py | 4 +- scribeengine/lib/helpers.py | 17 +++---- scribeengine/public/styles/style.css | 55 ++++++++++++++++++++++ scribeengine/templates/admin/login.mako | 3 +- scribeengine/templates/admin/register.mako | 1 + scribeengine/templates/blog/index.mako | 1 + scribeengine/templates/blog/teaser.mako | 1 + scribeengine/templates/blog/view.mako | 1 + scribeengine/templates/errors.mako | 2 +- scribeengine/templates/flash.mako | 8 ++++ scribeengine/templates/post/edit.mako | 1 + scribeengine/templates/post/new.mako | 5 +- themes/stargazer/public/styles/style.css | 37 +++++++++++++++ 15 files changed, 142 insertions(+), 28 deletions(-) create mode 100644 scribeengine/templates/flash.mako diff --git a/scribeengine/config/environment.py b/scribeengine/config/environment.py index ca27317..ef1d3a7 100644 --- a/scribeengine/config/environment.py +++ b/scribeengine/config/environment.py @@ -22,19 +22,28 @@ def load_environment(global_conf, app_conf): # Pull out theme variable theme = Session.query(Variable).get(u'theme') - if not theme: - theme_name = u'stargazer' - else: + if theme: theme_name = theme.value + else: + theme_name = None - # Pylons paths + # Set up Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - theme_dir = os.path.join(app_conf[u'paths.themes'], theme_name) - paths = dict(root=root, - controllers=os.path.join(root, 'controllers'), - static_files=os.path.join(theme_dir, 'public'), - templates=[os.path.join(theme_dir, 'templates'), - os.path.join(root, 'templates')]) + template_paths = [] + static_paths = [] + if theme_name: + theme_dir = os.path.join(app_conf[u'paths.themes'], theme_name) + template_paths.append(os.path.join(theme_dir, 'templates')) + static_paths.append(os.path.join(theme_dir, 'public')) + template_paths.append(os.path.join(root, 'templates')) + static_paths.append(os.path.join(root, 'public')) + + paths = dict( + root=root, + controllers=os.path.join(root, 'controllers'), + static_files=static_paths, + templates=template_paths + ) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='scribeengine', paths=paths) diff --git a/scribeengine/config/middleware.py b/scribeengine/config/middleware.py index b8aa7ee..93956cb 100644 --- a/scribeengine/config/middleware.py +++ b/scribeengine/config/middleware.py @@ -63,7 +63,8 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf): if asbool(static_files): # Serve static files - static_app = StaticURLParser(config['pylons.paths']['static_files']) - app = Cascade([static_app, app]) + static_apps = [StaticURLParser(path) + for path in config['pylons.paths']['static_files']] + app = Cascade(static_apps + [app]) return app diff --git a/scribeengine/controllers/admin.py b/scribeengine/controllers/admin.py index 7b99cf1..8d1148f 100644 --- a/scribeengine/controllers/admin.py +++ b/scribeengine/controllers/admin.py @@ -94,7 +94,7 @@ class AdminController(BaseController): if not user or user.password != password: log.debug('Username or password are incorrect.') h.flash.set_message(u'Your username or password are incorrect.', u'error') - h.redirect_to('/login') + h.redirect_to('/admin/login') elif user and user.password == password: log.debug('Logged in successfully.') redirect_url = str(session.get(u'redirect_url', u'/')) @@ -109,7 +109,7 @@ class AdminController(BaseController): del session[u'REMOTE_USER'] session.save() h.flash.set_message(u'There was a problem logging you in.', u'error') - h.redirect_to('/login') + h.redirect_to('/admin/login') def logout(self): del session[u'REMOTE_USER'] diff --git a/scribeengine/lib/helpers.py b/scribeengine/lib/helpers.py index 026daf8..5b0a7f5 100644 --- a/scribeengine/lib/helpers.py +++ b/scribeengine/lib/helpers.py @@ -30,21 +30,23 @@ available to Controllers. This module is available to both as 'h'. from routes import url_for from webhelpers.html import escape, HTML, literal, url_escape from webhelpers.date import distance_of_time_in_words +from pylons import session from pylons.controllers.util import redirect_to class Flash(object): - def set_message(self, message_text, message_type): - session = self._get_session() + def set_message(self, message_text, message_type, message_head=None): session[u'flash.text'] = message_text session[u'flash.type'] = message_type + session[u'flash.head'] = message_head session.save() def has_message(self): - session = self._get_session() - return u'flash.text' in session + return session.get(u'flash.text') + + def has_header(self): + return session.get(u'flash.head') def get_message_text(self): - session = self._get_session() message_text = session.pop(u'flash.text', None) if not message_text: return None @@ -52,17 +54,12 @@ class Flash(object): return message_text def get_message_type(self): - session = self._get_session() message_type = session.pop(u'flash.type', None) if not message_type: return None session.save() return message_type - def _get_session(self): - from pylons import session - return session - def teaser(text, url): position = text.find(u'

') diff --git a/scribeengine/public/styles/style.css b/scribeengine/public/styles/style.css index b1a42b2..b18b9e3 100644 --- a/scribeengine/public/styles/style.css +++ b/scribeengine/public/styles/style.css @@ -302,6 +302,15 @@ fieldset { padding: 0; } +.form-text, +.form-password, +.form-textarea { + padding: 3px 5px; + background-color: #1f1f1f; + border: 1px solid #454545; + color: #fff; +} + .form-text { font-size: 1.5em; padding: 4px 6px; @@ -313,6 +322,52 @@ fieldset { width: 605px; } +.form-button { + margin-bottom: 10px; + padding: 3px 5px; + background: #1F1F1F url(../images/img06.gif) no-repeat center center; + border: 1px solid #454545; + font: bold 1.2em "Trebuchet MS", Arial, Helvetica, sans-serif; + color: #FFFFFF; +} + .form-item { margin-bottom: 1em; } + +/* Message areas */ + +#form-errors { + background-color: #300; + border: 1px solid #900; + margin-top: 1.8em; + padding: 0.3em 0.5em; +} + +#message { + margin-top: 1.8em; + /*padding: 0.3em 0.5em;*/ +} + +#message p { + margin: 0; + padding: 0.5em 0.7em; +} + +#message.error { + background-color: #300; + border: 1px solid #900; + color: #fff; +} + +#message.success { + background-color: #030; + border: 1px solid #090; + color: #fff; +} + +/* Miscellaneous Styles */ + +.hidden { + display: none; +} diff --git a/scribeengine/templates/admin/login.mako b/scribeengine/templates/admin/login.mako index c0e7af8..44fb607 100644 --- a/scribeengine/templates/admin/login.mako +++ b/scribeengine/templates/admin/login.mako @@ -1,6 +1,7 @@ <%inherit file="/base.mako"/>

Log in

+ <%include file="/flash.mako"/> <%include file="/errors.mako"/>
@@ -13,7 +14,7 @@
- +
diff --git a/scribeengine/templates/admin/register.mako b/scribeengine/templates/admin/register.mako index 0ba3a11..c80cab7 100644 --- a/scribeengine/templates/admin/register.mako +++ b/scribeengine/templates/admin/register.mako @@ -1,6 +1,7 @@ <%inherit file="/base.mako"/>

Register

+ <%include file="/flash.mako"/> <%include file="/errors.mako"/>
diff --git a/scribeengine/templates/blog/index.mako b/scribeengine/templates/blog/index.mako index 3287432..7c57bbe 100644 --- a/scribeengine/templates/blog/index.mako +++ b/scribeengine/templates/blog/index.mako @@ -1,4 +1,5 @@ <%inherit file="/base.mako"/> + <%include file="/flash.mako"/> % for post in c.posts: <% post.full_url = u'/archive/%s/%s/%s/%s' % (post.created.strftime('%Y'), post.created.strftime('%m'), post.created.strftime('%d'), post.url) %>
diff --git a/scribeengine/templates/blog/teaser.mako b/scribeengine/templates/blog/teaser.mako index 23ada47..92dda42 100644 --- a/scribeengine/templates/blog/teaser.mako +++ b/scribeengine/templates/blog/teaser.mako @@ -1,4 +1,5 @@
+ <%include file="/flash.mako"/>

${post.title}

${h.literal(post.body)} diff --git a/scribeengine/templates/blog/view.mako b/scribeengine/templates/blog/view.mako index 5445b19..c8b5332 100644 --- a/scribeengine/templates/blog/view.mako +++ b/scribeengine/templates/blog/view.mako @@ -1,5 +1,6 @@ <%inherit file="/base.mako"/>
+ <%include file="/flash.mako"/>

${c.post.title}

Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}
diff --git a/scribeengine/templates/errors.mako b/scribeengine/templates/errors.mako index 0d1f878..fda78c9 100644 --- a/scribeengine/templates/errors.mako +++ b/scribeengine/templates/errors.mako @@ -8,7 +8,7 @@
% else: -
+