Reworked all urls to come from h.url_for binding. Allows every easy change in url layout or db config
This commit is contained in:
parent
b56cd48dec
commit
aa8e663588
@ -43,9 +43,9 @@ def make_map():
|
|||||||
|
|
||||||
# CUSTOM ROUTES HERE
|
# CUSTOM ROUTES HERE
|
||||||
|
|
||||||
map.connect('/archive/{year}', controller='blog', action='archive')
|
map.connect('/archive/{year}', controller='blog', action='archive',month=None,day=None,url=None)
|
||||||
map.connect('/archive/{year}/{month}', controller='blog', action='archive')
|
map.connect('/archive/{year}/{month}', controller='blog', action='archive',day=None,url=None)
|
||||||
map.connect('/archive/{year}/{month}/{day}', controller='blog', action='archive')
|
map.connect('/archive/{year}/{month}/{day}', controller='blog', action='archive',url=None)
|
||||||
map.connect('/archive/{year}/{month}/{day}/{url}', controller='blog', action='view')
|
map.connect('/archive/{year}/{month}/{day}/{url}', controller='blog', action='view')
|
||||||
|
|
||||||
map.connect('/{controller}/{action}')
|
map.connect('/{controller}/{action}')
|
||||||
|
@ -88,5 +88,5 @@ class BlogController(BaseController):
|
|||||||
Session.add(post)
|
Session.add(post)
|
||||||
Session.commit()
|
Session.commit()
|
||||||
h.flash.set_message(u'Successfully submitted your comment.', u'success')
|
h.flash.set_message(u'Successfully submitted your comment.', u'success')
|
||||||
h.redirect_to(h.full_url(post))
|
h.redirect_to(h.url_for_post(post))
|
||||||
|
|
||||||
|
@ -78,10 +78,15 @@ def teaser(text, url):
|
|||||||
text = text[:position]
|
text = text[:position]
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def full_url(post):
|
def url_for_post(post):
|
||||||
return '/archive/%s/%s/%s/%s' % (str(post.created.strftime('%Y')), \
|
#TODO: this is hard coded.
|
||||||
str(post.created.strftime('%m')), \
|
return url_for(
|
||||||
str(post.created.strftime('%d')), \
|
controller='blog',
|
||||||
str(post.url))
|
action='view',
|
||||||
|
year=post.created.strftime('%Y'),
|
||||||
|
month=post.created.strftime('%m'),
|
||||||
|
day=post.created.strftime('%d'),
|
||||||
|
url=post.url
|
||||||
|
)
|
||||||
|
|
||||||
flash = Flash()
|
flash = Flash()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<h2 class="title">Log in</h2>
|
<h2 class="title">Log in</h2>
|
||||||
<%include file="/flash.mako"/>
|
<%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(controller='admin', action='login')}" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<label for="login-email">E-mail:</label>
|
<label for="login-email">E-mail:</label>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<h2 class="title">Register</h2>
|
<h2 class="title">Register</h2>
|
||||||
<%include file="/flash.mako"/>
|
<%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(controller='admin', action='register')}" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<label for="register-nick">Nick:</label>
|
<label for="register-nick">Nick:</label>
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
<li><a href="${page.url}">${page.name}</a></li>
|
<li><a href="${page.url}">${page.name}</a></li>
|
||||||
% endfor
|
% endfor
|
||||||
% if c.current_user:
|
% if c.current_user:
|
||||||
<li><a href="${h.url_for('/admin/logout')}">Logout</a></li>
|
<li><a href="${h.url_for(controller='admin',action='logout')}">Logout</a></li>
|
||||||
% else:
|
% else:
|
||||||
<li><a href="${h.url_for('/admin/login')}">Login</a></li>
|
<li><a href="${h.url_for(controller='admin',action='login')}">Login</a></li>
|
||||||
% endif
|
% endif
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,19 +2,19 @@
|
|||||||
<%include file="/flash.mako"/>
|
<%include file="/flash.mako"/>
|
||||||
% for post in c.posts:
|
% for post in c.posts:
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<h2 class="title"><a href="${h.full_url(post)}">${post.title}</a></h2>
|
<h2 class="title"><a href="${h.url_for_post(post)}">${post.title}</a></h2>
|
||||||
<div class="entry">
|
<div class="entry">
|
||||||
${h.literal(h.teaser(post.body, h.full_url(post)))}
|
${h.literal(h.teaser(post.body, h.url_for_post(post)))}
|
||||||
</div>
|
</div>
|
||||||
<p class="meta">
|
<p class="meta">
|
||||||
<span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span>
|
<span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span>
|
||||||
<a href="${h.full_url(post)}" class="read-more">Read more</a>
|
<a href="${h.url_for_post(post)}" class="read-more">Read more</a>
|
||||||
% if len(post.comments) == 0:
|
% if len(post.comments) == 0:
|
||||||
<a href="${h.full_url(post)}#comments" class="comments">No comments</a>
|
<a href="${h.url_for_post(post)}#comments" class="comments">No comments</a>
|
||||||
% elif len(post.comments) == 1:
|
% elif len(post.comments) == 1:
|
||||||
<a href="${h.full_url(post)}#comments" class="comments">1 comment</a>
|
<a href="${h.url_for_post(post)}#comments" class="comments">1 comment</a>
|
||||||
% else:
|
% else:
|
||||||
<a href="${h.full_url(post)}#comments" class="comments">${len(post.comments)} comments</a>
|
<a href="${h.url_for_post(post)}#comments" class="comments">${len(post.comments)} comments</a>
|
||||||
% endif
|
% endif
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<div class="post">
|
<div class="post">
|
||||||
<%include file="/flash.mako"/>
|
<%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_post(post)}">${post.title}</a></h2>
|
||||||
<div class="entry">
|
<div class="entry">
|
||||||
${h.literal(post.body)}
|
${h.literal(post.body)}
|
||||||
</div>
|
</div>
|
||||||
<p class="meta"><span class="byline">Posted by ${post.user.first_name} on ${post.created.strftime('%B %d, %Y')}</span> <a href="${h.url_for(year=post.created.strftime('%Y'), month=post.created.strftime('%m'), day=post.created.strftime('%d'), url=post.url)}#comments" class="comments">18 comments</a></p>
|
<p class="meta"><span class="byline">Posted by ${post.user.first_name} on ${post.created.strftime('%B %d, %Y')}</span> <a href="${h.url_for_post(post)}#comments" class="comments">18 comments</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -38,10 +38,10 @@
|
|||||||
% if c.post.comment_status == u'open':
|
% if c.post.comment_status == u'open':
|
||||||
<h3 id="respond">Leave a Reply</h3>
|
<h3 id="respond">Leave a Reply</h3>
|
||||||
% if not c.current_user:
|
% if not c.current_user:
|
||||||
<p>You must be <a href="${h.url_for('/admin/login')}">logged in</a> to post a comment.</p>
|
<p>You must be <a href="${h.url_for(controller='admin', action='login')}">logged in</a> to post a comment.</p>
|
||||||
% else:
|
% else:
|
||||||
<form action="${h.url_for('/blog/comment/%s' % c.post.id)}" method="post" id="commentform">
|
<form action="${h.url_for(controller='blog',action='comment', id= c.post.id)}" method="post" id="commentform">
|
||||||
<p class="user-details">Logged in as <em>${c.current_user.nick}</em>. <a href="/logout" title="Log out of this account">Logout »</a></p>
|
<p class="user-details">Logged in as <em>${c.current_user.nick}</em>. <a href="${h.url_for(controller='admin',action='logout')}" title="Log out of this account">Logout »</a></p>
|
||||||
<p><input type="text" name="title" class="form-text" value="RE: ${c.post.title}" /></p>
|
<p><input type="text" name="title" class="form-text" value="RE: ${c.post.title}" /></p>
|
||||||
<p><textarea name="body" class="form-textarea" cols="80" rows="10" tabindex="4"></textarea></p>
|
<p><textarea name="body" class="form-textarea" cols="80" rows="10" tabindex="4"></textarea></p>
|
||||||
<p>
|
<p>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<h2 class="title">Edit Post: ${c.post.title}</h2>
|
<h2 class="title">Edit Post: ${c.post.title}</h2>
|
||||||
<%include file="/flash.mako"/>
|
<%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(controller='post',action='edit', id=c.post.id)}" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<!-- <label for="post-title">Title:</label> -->
|
<!-- <label for="post-title">Title:</label> -->
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<h2>Categories</h2>
|
<h2>Categories</h2>
|
||||||
<ul>
|
<ul>
|
||||||
% for category in c.categories:
|
% for category in c.categories:
|
||||||
<li><a href="${h.url_for('/category/%s' % str(category.url))}" title="${category.name}">${category.name}</a> (${len(category.posts)}) </li>
|
<li><a href="${h.url_for(controller='category', action=category.url)}" title="${category.name}">${category.name}</a> (${len(category.posts)}) </li>
|
||||||
% endfor
|
% endfor
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
Reference in New Issue
Block a user