Flash message styling, form styling, multiple static directories.

This commit is contained in:
Raoul Snyman 2010-01-17 01:19:42 +02:00
parent e117bd5e58
commit df8bd84520
15 changed files with 142 additions and 28 deletions

View File

@ -22,19 +22,28 @@ def load_environment(global_conf, app_conf):
# Pull out theme variable # Pull out theme variable
theme = Session.query(Variable).get(u'theme') theme = Session.query(Variable).get(u'theme')
if not theme: if theme:
theme_name = u'stargazer'
else:
theme_name = theme.value 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__))) root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
template_paths = []
static_paths = []
if theme_name:
theme_dir = os.path.join(app_conf[u'paths.themes'], theme_name) theme_dir = os.path.join(app_conf[u'paths.themes'], theme_name)
paths = dict(root=root, 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'), controllers=os.path.join(root, 'controllers'),
static_files=os.path.join(theme_dir, 'public'), static_files=static_paths,
templates=[os.path.join(theme_dir, 'templates'), templates=template_paths
os.path.join(root, 'templates')]) )
# Initialize config with the basic options # Initialize config with the basic options
config.init_app(global_conf, app_conf, package='scribeengine', paths=paths) config.init_app(global_conf, app_conf, package='scribeengine', paths=paths)

View File

@ -63,7 +63,8 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
if asbool(static_files): if asbool(static_files):
# Serve static files # Serve static files
static_app = StaticURLParser(config['pylons.paths']['static_files']) static_apps = [StaticURLParser(path)
app = Cascade([static_app, app]) for path in config['pylons.paths']['static_files']]
app = Cascade(static_apps + [app])
return app return app

View File

@ -94,7 +94,7 @@ class AdminController(BaseController):
if not user or user.password != password: if not user or user.password != password:
log.debug('Username or password are incorrect.') log.debug('Username or password are incorrect.')
h.flash.set_message(u'Your username or password are incorrect.', u'error') 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: elif user and user.password == password:
log.debug('Logged in successfully.') log.debug('Logged in successfully.')
redirect_url = str(session.get(u'redirect_url', u'/')) redirect_url = str(session.get(u'redirect_url', u'/'))
@ -109,7 +109,7 @@ class AdminController(BaseController):
del session[u'REMOTE_USER'] del session[u'REMOTE_USER']
session.save() session.save()
h.flash.set_message(u'There was a problem logging you in.', u'error') 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): def logout(self):
del session[u'REMOTE_USER'] del session[u'REMOTE_USER']

View File

@ -30,21 +30,23 @@ available to Controllers. This module is available to both as 'h'.
from routes import url_for from routes import url_for
from webhelpers.html import escape, HTML, literal, url_escape from webhelpers.html import escape, HTML, literal, url_escape
from webhelpers.date import distance_of_time_in_words from webhelpers.date import distance_of_time_in_words
from pylons import session
from pylons.controllers.util import redirect_to from pylons.controllers.util import redirect_to
class Flash(object): class Flash(object):
def set_message(self, message_text, message_type): def set_message(self, message_text, message_type, message_head=None):
session = self._get_session()
session[u'flash.text'] = message_text session[u'flash.text'] = message_text
session[u'flash.type'] = message_type session[u'flash.type'] = message_type
session[u'flash.head'] = message_head
session.save() session.save()
def has_message(self): def has_message(self):
session = self._get_session() return session.get(u'flash.text')
return u'flash.text' in session
def has_header(self):
return session.get(u'flash.head')
def get_message_text(self): def get_message_text(self):
session = self._get_session()
message_text = session.pop(u'flash.text', None) message_text = session.pop(u'flash.text', None)
if not message_text: if not message_text:
return None return None
@ -52,17 +54,12 @@ class Flash(object):
return message_text return message_text
def get_message_type(self): def get_message_type(self):
session = self._get_session()
message_type = session.pop(u'flash.type', None) message_type = session.pop(u'flash.type', None)
if not message_type: if not message_type:
return None return None
session.save() session.save()
return message_type return message_type
def _get_session(self):
from pylons import session
return session
def teaser(text, url): def teaser(text, url):
position = text.find(u'</p>') position = text.find(u'</p>')

View File

@ -302,6 +302,15 @@ fieldset {
padding: 0; padding: 0;
} }
.form-text,
.form-password,
.form-textarea {
padding: 3px 5px;
background-color: #1f1f1f;
border: 1px solid #454545;
color: #fff;
}
.form-text { .form-text {
font-size: 1.5em; font-size: 1.5em;
padding: 4px 6px; padding: 4px 6px;
@ -313,6 +322,52 @@ fieldset {
width: 605px; 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 { .form-item {
margin-bottom: 1em; 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;
}

View File

@ -1,6 +1,7 @@
<%inherit file="/base.mako"/> <%inherit file="/base.mako"/>
<div class="post"> <div class="post">
<h2 class="title">Log in</h2> <h2 class="title">Log in</h2>
<%include file="/flash.mako"/>
<%include file="/errors.mako"/> <%include file="/errors.mako"/>
<form id="post-new" action="${h.url_for('/admin/login')}" method="post"> <form id="post-new" action="${h.url_for('/admin/login')}" method="post">
<fieldset> <fieldset>
@ -13,7 +14,7 @@
<input type="password" name="password" id="login-password" class="form-text" /> <input type="password" name="password" id="login-password" class="form-text" />
</div> </div>
<div class="form-item"> <div class="form-item">
<input type="submit" name="action" value="Login"/> <input type="submit" name="action" value="Login" class="form-button"/>
</div> </div>
</fieldset> </fieldset>
</form> </form>

View File

@ -1,6 +1,7 @@
<%inherit file="/base.mako"/> <%inherit file="/base.mako"/>
<div class="post"> <div class="post">
<h2 class="title">Register</h2> <h2 class="title">Register</h2>
<%include file="/flash.mako"/>
<%include file="/errors.mako"/> <%include file="/errors.mako"/>
<form id="post-new" action="${h.url_for('/admin/register')}" method="post"> <form id="post-new" action="${h.url_for('/admin/register')}" method="post">
<fieldset> <fieldset>

View File

@ -1,4 +1,5 @@
<%inherit file="/base.mako"/> <%inherit file="/base.mako"/>
<%include file="/flash.mako"/>
% for post in c.posts: % 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) %> <% post.full_url = u'/archive/%s/%s/%s/%s' % (post.created.strftime('%Y'), post.created.strftime('%m'), post.created.strftime('%d'), post.url) %>
<div class="post"> <div class="post">

View File

@ -1,4 +1,5 @@
<div class="post"> <div class="post">
<%include file="/flash.mako"/>
<h2 class="title"><a href="${h.url_for(year=post.created.strftime('%Y'), month=post.created.strftime('%m'), day=post.created.strftime('%d'), url=post.url)}">${post.title}</a></h2> <h2 class="title"><a href="${h.url_for(year=post.created.strftime('%Y'), month=post.created.strftime('%m'), day=post.created.strftime('%d'), url=post.url)}">${post.title}</a></h2>
<div class="entry"> <div class="entry">
${h.literal(post.body)} ${h.literal(post.body)}

View File

@ -1,5 +1,6 @@
<%inherit file="/base.mako"/> <%inherit file="/base.mako"/>
<div class="post"> <div class="post">
<%include file="/flash.mako"/>
<h2 class="title"><a href="${h.url_for(year=c.post.created.strftime('%Y'), month=c.post.created.strftime('%m'), day=c.post.created.strftime('%d'), url=c.post.url)}">${c.post.title}</a></h2> <h2 class="title"><a href="${h.url_for(year=c.post.created.strftime('%Y'), month=c.post.created.strftime('%m'), day=c.post.created.strftime('%d'), url=c.post.url)}">${c.post.title}</a></h2>
<div class="info">Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}</div> <div class="info">Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}</div>
<div class="entry"> <div class="entry">

View File

@ -8,7 +8,7 @@
</ul> </ul>
</div> </div>
% else: % else:
<div id="form-errors" clsas="hidden"> <div id="form-errors" class="hidden">
<p>The following errors occurred:</p> <p>The following errors occurred:</p>
<ul> <ul>
</ul> </ul>

View File

@ -0,0 +1,8 @@
% if h.flash.has_message():
<div id="message" class="${h.flash.get_message_type()}">
% if h.flash.has_header():
<p><strong>${h.flash.get_message_head()}</strong></p>
% endif
<p>${h.flash.get_message_text()}</p>
</div>
% endif

View File

@ -1,6 +1,7 @@
<%inherit file="/base.mako"/> <%inherit file="/base.mako"/>
<div class="post"> <div class="post">
<h2 class="title">Edit Post: ${c.post.title}</h2> <h2 class="title">Edit Post: ${c.post.title}</h2>
<%include file="/flash.mako"/>
<%include file="/errors.mako"/> <%include file="/errors.mako"/>
<form id="post-new" action="${h.url_for('/post/edit/%s' % str(c.post.id))}" method="post"> <form id="post-new" action="${h.url_for('/post/edit/%s' % str(c.post.id))}" method="post">
<fieldset> <fieldset>

View File

@ -1,6 +1,7 @@
<%inherit file="/base.mako"/> <%inherit file="/base.mako"/>
<div class="post"> <div class="post">
<h2 class="title">New Post</h2> <h2 class="title">New Post</h2>
<%include file="/flash.mako"/>
<%include file="/errors.mako"/> <%include file="/errors.mako"/>
<form id="post-new" action="${h.url_for('/post/edit')}" method="post"> <form id="post-new" action="${h.url_for('/post/edit')}" method="post">
<fieldset> <fieldset>
@ -13,8 +14,8 @@
<textarea name="body" id="post-body" class="form-textarea"></textarea> <textarea name="body" id="post-body" class="form-textarea"></textarea>
</div> </div>
<div class="form-item"> <div class="form-item">
<input type="submit" name="action" value="Save Draft"/> <input type="submit" name="action" value="Save Draft" class="form-button"/>
<input type="submit" name="action" value="Save &amp; Publish"/> <input type="submit" name="action" value="Save &amp; Publish" class="form-button"/>
</div> </div>
</fieldset> </fieldset>
</form> </form>

View File

@ -324,3 +324,40 @@ fieldset {
.form-item { .form-item {
margin-bottom: 1em; 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;
}