def post(self):
        form = BlogCategoryForm(self.request.POST)

        if form.validate():
            title = form.data["title"]
            slug = title.lower().replace(" ", "-")
            category = BlogCategory(title = title, slug = slug)
            category.put()

        self.redirect_to('admin-blog-categories')
    def get(self):
        categories = BlogCategory.all()

        return {
            "admin_section": "admin-blog-categories",
            "categories": categories,
        }
    def get(self, category = None):
        cur_category = None
        categories = BlogCategory.all()

        if category:
            cur_category = BlogCategory.all().filter("slug =", category).get()
            posts = BlogPost.all().filter("category =", cur_category).order("-date_created")
        else:
            posts = BlogPost.all().order("-date_created")
            cur_category = None

        return {
            "section": "blog",
            "posts": posts,
            "cur_category": cur_category,
            "categories": categories,
        }
    def post(self, category_id):
        form = BlogCategoryForm(self.request.POST)
        category = BlogCategory.get(long(category_id))

        if form.validate():
            slug = form.data["title"].lower().replace(" ", "-")
            form.populate_obj(category)
            category.put()

        return {
            "result": {
               "id": category.key().id(),
               "title": category.title,
               "slug": category.slug,
           }
        }