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
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__)))
template_paths = []
static_paths = []
if 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'),
static_files=os.path.join(theme_dir, 'public'),
templates=[os.path.join(theme_dir, 'templates'),
os.path.join(root, 'templates')])
static_files=static_paths,
templates=template_paths
)
# Initialize config with the basic options
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):
# 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

View File

@ -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']

View File

@ -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'</p>')

View File

@ -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;
}

View File

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

View File

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

View File

@ -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) %>
<div class="post">

View File

@ -1,4 +1,5 @@
<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>
<div class="entry">
${h.literal(post.body)}

View File

@ -1,5 +1,6 @@
<%inherit file="/base.mako"/>
<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>
<div class="info">Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}</div>
<div class="entry">

View File

@ -8,7 +8,7 @@
</ul>
</div>
% else:
<div id="form-errors" clsas="hidden">
<div id="form-errors" class="hidden">
<p>The following errors occurred:</p>
<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"/>
<div class="post">
<h2 class="title">Edit Post: ${c.post.title}</h2>
<%include file="/flash.mako"/>
<%include file="/errors.mako"/>
<form id="post-new" action="${h.url_for('/post/edit/%s' % str(c.post.id))}" method="post">
<fieldset>

View File

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

View File

@ -324,3 +324,40 @@ fieldset {
.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;
}