Skip to content

Commit

Permalink
new blog structre
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Golub committed Aug 18, 2010
1 parent f92be05 commit c08795c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
33 changes: 20 additions & 13 deletions blog.py
Expand Up @@ -78,7 +78,7 @@ def render(self, template_name, **kwargs):
"published": entry.published.isoformat(),
"updated": entry.updated.isoformat(),
"tags": entry.tags,
"link": "http://" + self.request.host + "/e/" + entry.slug,
"link": "http://" + self.request.host + "/" + entry.slug,
} for entry in kwargs["entries"]]
self.set_header("Content-Type", "text/javascript")
self.write({"entries": json_entries})
Expand Down Expand Up @@ -219,7 +219,7 @@ def post(self):
entry.put()
if not key and not entry.hidden:
self.ping()
self.redirect("/e/" + entry.slug)
self.redirect("/" + entry.slug)


class DeleteHandler(BaseHandler):
Expand Down Expand Up @@ -265,19 +265,15 @@ def post(self):
self.redirect("/")


class EntryHandler(BaseHandler):
class OldEntryHandler(BaseHandler):
@tornado.web.removeslash
def get(self, slug):
entry = db.Query(Entry).filter("slug =", slug).get()
if not entry:
raise tornado.web.HTTPError(404)
self.render("entry.html", entry=entry, entries=[entry])
self.redirect("/" + slug)

@tornado.web.removeslash
def head(self, slug):
entry = db.Query(Entry).filter("slug =", slug).get()
if not entry:
raise tornado.web.HTTPError(404)

return self.get(slug)


class TagHandler(BaseHandler):
@tornado.web.removeslash
Expand All @@ -287,13 +283,24 @@ def get(self, tag):


class CatchAllHandler(BaseHandler):
def __init__(self, *args, **kwargs):
BaseHandler.__init__(self, *args, **kwargs)
self.entry = None
slug = self.request.path[1:]
if slug:
self.entry = db.Query(Entry).filter("slug =", slug).get()

@tornado.web.removeslash
def get(self):
if self.entry:
return self.render("entry.html", entry=self.entry,
entries=[self.entry])
self.set_status(404)
self.render("404.html")

def head(self):
self.set_status(404)
if not self.entry:
self.set_status(404)


class EntryModule(tornado.web.UIModule):
Expand Down Expand Up @@ -367,7 +374,7 @@ def render(self):
(r"/archive/?", ArchiveHandler),
(r"/compose", ComposeHandler),
(r"/delete", DeleteHandler),
(r"/e/([\w-]+)/?", EntryHandler),
(r"/e/([\w-]+)/?", OldEntryHandler),
(r"/feed/?", tornado.web.RedirectHandler, {"url": "/?format=atom"}),
(r"/hide", HideHandler),
(r"/t/([\w-]+)/?", TagHandler),
Expand Down
2 changes: 1 addition & 1 deletion templates/atom.xml
Expand Up @@ -11,7 +11,7 @@
{% for entry in entries %}
<entry>
<id>tag:{{ handler.request.host }},{{ entry.published.strftime("%Y-%m-%d") }}:/e/{{ entry.slug }}</id>

This comment has been minimized.

Copy link
@bgolub

bgolub Aug 22, 2010

Owner

Never ever change ID tags; these can keep the /e/ in it

<link href="http://{{ handler.request.host + "/e/" + entry.slug }}" rel="alternate" type="text/html"/>
<link href="http://{{ handler.request.host + "/" + entry.slug }}" rel="alternate" type="text/html"/>
<title type="text">{{ escape(entry.title) }}</title>
<updated>{{ entry.updated.strftime(date_format) }}</updated>
<published>{{ entry.published.strftime(date_format) }}</published>
Expand Down
2 changes: 1 addition & 1 deletion templates/compose.html
Expand Up @@ -21,7 +21,7 @@
</div>
<div>
<input type="submit" class="submit" value="{{ _("Save changes") if entry else _("Publish") }}"/>
<a href="{{ "/e/" + entry.slug if entry else "/" }}">{{ _("Cancel") }}</a>
<a href="{{ "/" + entry.slug if entry else "/" }}">{{ _("Cancel") }}</a>
</div>
</form>
{% end %}
2 changes: 1 addition & 1 deletion templates/delete.html
Expand Up @@ -2,7 +2,7 @@

{% block content %}
<p>
{{ _("Are you sure you want to delete <a href=\"%(link)s\">%(title)s</a>?") % {"link": "/e/" + entry.slug, "title": escape(entry.title)} }}
{{ _("Are you sure you want to delete <a href=\"%(link)s\">%(title)s</a>?") % {"link": "/" + entry.slug, "title": escape(entry.title)} }}
</p>
<form action="{{ request.path }}" method="post">
{{ xsrf_form_html() }}
Expand Down
2 changes: 1 addition & 1 deletion templates/hide.html
Expand Up @@ -2,7 +2,7 @@

{% block content %}
<p>
{{ _("Are you sure you want to %(verb)s <a href=\"%(link)s\">%(title)s</a>?") % {"link": "/e/" + entry.slug, "title": escape(entry.title), "verb": _("un-hide") if entry.hidden else _("hide") } }}
{{ _("Are you sure you want to %(verb)s <a href=\"%(link)s\">%(title)s</a>?") % {"link": "/" + entry.slug, "title": escape(entry.title), "verb": _("un-hide") if entry.hidden else _("hide") } }}
</p>
<form action="{{ request.path }}" method="post">
{{ xsrf_form_html() }}
Expand Down
2 changes: 1 addition & 1 deletion templates/modules/entry-small.html
@@ -1,6 +1,6 @@
<div>
<div>
<a href="/e/{{ entry.slug }}">{{ escape(entry.title) }}</a>
<a href="/{{ entry.slug }}">{{ escape(entry.title) }}</a>
</div>
{% if show_date %}
<div style="color: gray; font-size: 10pt;">
Expand Down
2 changes: 1 addition & 1 deletion templates/modules/entry.html
Expand Up @@ -2,7 +2,7 @@
<h1><a href="/e/{{ entry.slug }}">{{ escape(entry.title) }}</a></h1>
{% if show_share %}
<div style="float: right; height: 18px;">
<iframe src="http://www.facebook.com/plugins/like.php?href={{ url_escape('http://' + request.host + '/e/' + entry.slug) }}&amp;show_faces=false" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; float:right;"></iframe>
<iframe src="http://www.facebook.com/plugins/like.php?href={{ url_escape('http://' + request.host + '/' + entry.slug) }}&amp;show_faces=false" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; float:right;"></iframe>
</div>
{% end %}
<div class="date">
Expand Down

0 comments on commit c08795c

Please sign in to comment.