Permalink
Browse files

hidden entries

  • Loading branch information...
1 parent 5914c61 commit 4c2e0ae38547cfa62c758979995924cb9294e279 Benjamin Golub committed Jan 31, 2010
Showing with 43 additions and 4 deletions.
  1. +28 −4 blog.py
  2. +2 −0 index.yaml
  3. +12 −0 templates/hide.html
  4. +1 −0 templates/modules/entry.html
View
@@ -40,6 +40,7 @@ class Entry(db.Model):
published = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
tags = db.ListProperty(db.Category)
+ hidden = db.BooleanProperty(default=False)
class BaseHandler(tornado.web.RequestHandler):
@@ -138,7 +139,7 @@ def head(self, *args):
class HomeHandler(BaseHandler):
def get(self):
- entries = db.Query(Entry).order("-published").fetch(limit=5)
+ entries = db.Query(Entry).filter("hidden =", False).order("-published").fetch(limit=5)
self.recent_entries = entries
self.render("home.html", entries=entries)
@@ -152,7 +153,7 @@ def get(self):
class ArchiveHandler(BaseHandler):
@tornado.web.removeslash
def get(self):
- entries = db.Query(Entry).order("-published")
+ entries = db.Query(Entry).filter("hidden =", False).order("-published")
self.recent_entries = entries[:5]
self.render("archive.html", entries=entries)
@@ -223,6 +224,28 @@ def post(self):
self.redirect("/")
+class HideHandler(BaseHandler):
+ @administrator
+ def get(self):
+ key = self.get_argument("key")
+ try:
+ entry = Entry.get(key)
+ except db.BadKeyError:
+ raise tornado.web.HTTPError(404)
+ self.render("hide.html", entry=entry)
+
+ @administrator
+ def post(self):
+ key = self.get_argument("key")
+ try:
+ entry = Entry.get(key)
+ except db.BadKeyError:
+ raise tornado.web.HTTPError(404)
+ entry.hidden = True
+ entry.put()
+ self.redirect("/")
+
+
class EntryHandler(BaseHandler):
@tornado.web.removeslash
def get(self, slug):
@@ -240,7 +263,7 @@ def head(self, slug):
class TagHandler(BaseHandler):
@tornado.web.removeslash
def get(self, tag):
- entries = db.Query(Entry).filter("tags =", tag).order("-published")
+ entries = db.Query(Entry).filter("hidden =", False).filter("tags =", tag).order("-published")
self.render("tag.html", entries=entries, tag=tag)
@@ -281,7 +304,7 @@ def render(self, entry, show_date=False):
class RecentEntriesModule(tornado.web.UIModule):
def render(self):
entries = getattr(self.handler, "recent_entries",
- db.Query(Entry).order("-published").fetch(limit=5))
+ db.Query(Entry).filter("hidden =", False).order("-published").fetch(limit=5))
return self.render_string("modules/recententries.html", entries=entries)
@@ -306,6 +329,7 @@ def render(self):
(r"/delete", DeleteHandler),
(r"/e/([\w-]+)/?", EntryHandler),
(r"/feed/?", tornado.web.RedirectHandler, {"url": "/?format=atom"}),
+ (r"/hide", HideHandler),
(r"/t/([\w-]+)/?", TagHandler),
(r".*", CatchAllHandler),
], **settings)
View
@@ -2,11 +2,13 @@ indexes:
- kind: Entry
properties:
+ - name: hidden
- name: published
direction: desc
- kind: Entry
properties:
+ - name: hidden
- name: tags
- name: published
direction: desc
View
@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+
+{% block content %}
+ <p>
+ {{ _("Are you sure you want to hide <a href=\"%(link)s\">%(title)s</a>?") % {"link": "/e/" + entry.slug, "title": escape(entry.title)} }}
+ </p>
+ <form action="{{ request.path }}" method="post">
+ {{ xsrf_form_html() }}
+ <input type="hidden" name="key" value="{{ str(entry.key()) }}"/>
+ <input type="submit" class="submit" value="{{ _("Hide") }}"/>
+ </form>
+{% end %}
@@ -24,6 +24,7 @@
<div style="margin-top: 5px;">
<a href="/compose?key={{ str(entry.key()) }}">{{ _("Edit") }}</a>
<a href="/delete?key={{ str(entry.key()) }}">{{ _("Delete") }}</a>
+ <a href="/hide?key={{ str(entry.key()) }}">{{ _("Hide") }}</a>
</div>
{% end %}
</div>

0 comments on commit 4c2e0ae

Please sign in to comment.