def is_published(self):
return self.status == "published"
- # Tags
-
- def get_tags(self):
- if not hasattr(self, "__tags"):
- res = self.db.query("SELECT tag FROM planet_tags \
- WHERE post_id = %s ORDER BY tag", self.id)
- self.__tags = []
- for row in res:
- self.__tags.append(row.tag)
-
- return self.__tags
-
- def set_tags(self, tags):
- # Delete all existing tags.
- self.db.execute("DELETE FROM planet_tags WHERE post_id = %s", self.id)
-
- self.db.executemany("INSERT INTO planet_tags(post_id, tag) VALUES(%s, %s)",
- ((self.id, tag) for tag in tags))
-
- # Update cache.
- self.__tags = tags
- self.__tags.sort()
-
- tags = property(get_tags, set_tags)
-
class Planet(Object):
def get_authors(self):
return slug
- def create(self, title, markdown, author, status="published", tags=None, published=None):
+ def create(self, title, markdown, author, status="published", published=None):
slug = self._generate_slug(title)
markup = self.render(markdown)
published = datetime.datetime.utcnow()
id = self.db.execute("INSERT INTO planet(author_id, slug, title, status, \
- markdown, markup, published) VALUES(%s, %s, %s, %s, %s, %s, %s)",
+ markdown, markup, published) VALUES(%s, %s, %s, %s, %s, %s, %s) RETURNING id",
author.uid, slug, title, status, markdown, markup, published)
- entry = self.get_entry_by_id(id)
-
- if tags:
- entry.tags = tags
-
- return entry
+ if id:
+ return self.get_entry_by_id(id)
def update_entry(self, entry):
self.db.execute("UPDATE planet SET title = %s, markdown = %s WHERE id = %s",
def post(self):
title = self.get_argument("title")
markdown = self.get_argument("markdown")
- tags = self.get_argument("tags", "")
status = self.get_argument("status", "draft")
assert status in ("draft", "published")
author = self.accounts.find(self.current_user)
entry = self.planet.create(title=title, markdown=markdown,
- author=author, status=status, tags=tags.split())
+ author=author, status=status)
self.redirect("/planet")
entry.title = self.get_argument("title")
entry.markdown = self.get_argument("markdown")
- entry.tags = self.get_argument("tags", "").split()
entry.status = self.get_argument("status", "draft")