Permalink
Browse files

new blog structre

  • Loading branch information...
1 parent f92be05 commit c08795c5ac6993a4d523899ef29817256f9778cc Benjamin Golub committed Aug 18, 2010
Showing with 26 additions and 19 deletions.
  1. +20 −13 blog.py
  2. +1 −1 templates/atom.xml
  3. +1 −1 templates/compose.html
  4. +1 −1 templates/delete.html
  5. +1 −1 templates/hide.html
  6. +1 −1 templates/modules/entry-small.html
  7. +1 −1 templates/modules/entry.html
View
33 blog.py
@@ -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})
@@ -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):
@@ -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
@@ -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):
@@ -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),
View
@@ -11,7 +11,7 @@
{% for entry in entries %}
<entry>
<id>tag:{{ handler.request.host }},{{ entry.published.strftime("%Y-%m-%d") }}:/e/{{ entry.slug }}</id>
@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>
View
@@ -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 %}
View
@@ -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() }}
View
@@ -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() }}
@@ -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;">
@@ -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">

0 comments on commit c08795c

Please sign in to comment.