Browse Source

handle case where there are zero posts

pull/1/head
wes 7 years ago
parent
commit
a0d79491fc
  1. 17
      src/posts.py
  2. 2
      src/scripts/app.tag
  3. 2
      src/website.py

17
src/posts.py

@ -2,7 +2,9 @@
import couchdb import couchdb
import mistune import mistune
from json import dumps from json import dumps
from collections import defaultdict
from werkzeug.local import Local, LocalProxy, LocalManager from werkzeug.local import Local, LocalProxy, LocalManager
from couchdb.http import ResourceConflict, ResourceNotFound from couchdb.http import ResourceConflict, ResourceNotFound
@ -21,7 +23,7 @@ markdown = LocalProxy(get_mistune)
class Posts: class Posts:
def __init__(self, user, password, name, host=None, port=None): def __init__(self, user, password, name, host=None, port=None):
if host is None: if host is None:
host = "localhost" host = "127.0.0.1"
if port is None: if port is None:
port = "5984" port = "5984"
@ -71,7 +73,12 @@ class Posts:
def getinitial(self): def getinitial(self):
results = list(self.db.iterview("blogPosts/blog-posts", 2, include_docs=True)) results = list(self.db.iterview("blogPosts/blog-posts", 2, include_docs=True))
post = [result.doc for result in results][0] posts = [result.doc for result in results]
if len(posts) == 0:
return defaultdict(str)
post = posts[0]
post["content"] = markdown(post["content"]) post["content"] = markdown(post["content"])
@ -184,10 +191,12 @@ class Posts:
results = self.db.list( results = self.db.list(
"blogPosts/categories", "blogPosts/categories",
"blogPosts/format", "blogPosts/format",
**args)[1].get("results", []) **args)
if len(results) == 0:
return jsonify([])
posts = [] posts = []
for categories, post in results: for categories, post in results[1].get("results", []):
post["content"] = markdown(post["content"]) post["content"] = markdown(post["content"])
posts.append([categories, post]) posts.append([categories, post])
return jsonify(posts) if json else posts return jsonify(posts) if json else posts

2
src/scripts/app.tag

@ -245,7 +245,7 @@ menuOff(ev) {
} }
self.titles = { self.titles = {
"browse" : "Wes's Blog", "browse" : "Wesley Kerfoot",
"projects" : "Software", "projects" : "Software",
"links" : "Links", "links" : "Links",
"about" : "About Me" "about" : "About Me"

2
src/website.py

@ -27,7 +27,7 @@ page_titles = {
"about" : "About Me", "about" : "About Me",
"projects" : "Software", "projects" : "Software",
"links" : "Links", "links" : "Links",
"browse" : "Wes's Blog" "browse" : "Wesley Kerfoot"
} }
def cacheit(key, thunk): def cacheit(key, thunk):

Loading…
Cancel
Save