From 7aad33e7b30e9f70d859cb006aae331dab3a38c6 Mon Sep 17 00:00:00 2001 From: wes <378351+nisstyre56@users.noreply.github.com> Date: Thu, 8 Feb 2018 02:15:10 -0500 Subject: [PATCH] clean up and add docstrings --- src/posts.py | 30 ++++++++++++++++++++++++++++-- src/website.py | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/posts.py b/src/posts.py index 4439b0a..b170ee9 100644 --- a/src/posts.py +++ b/src/posts.py @@ -35,7 +35,16 @@ class Posts: self.iterpost = self.postIterator("blogPosts/blog-posts") - def savepost(self, title="", content="", author="", categories=[], _id=False, draft=True): + def savepost(self, + title="", + content="", + author="", + categories=[], + _id=False, + draft=True): + """ + Save a post + """ if _id: doc = self.db[_id] doc["title"] = title @@ -58,7 +67,14 @@ class Posts: print("post was saved %s" % doc) return jsonify(self.db.save(doc)) - def getpost(self, _id, json=True, convert=True, unpublished=False): + def getpost(self, + _id, + json=True, + convert=True, + unpublished=False): + """ + Get a post by id + """ if unpublished: results = self.db.iterview("blogPosts/unpublished", 1, include_docs=True, startkey=_id) else: @@ -71,10 +87,14 @@ class Posts: return jsonify(post) if json else post def getinitial(self): + """ + Get the initial post to start from + """ results = list(self.db.iterview("blogPosts/blog-posts", 2, include_docs=True)) posts = [result.doc for result in results] + # if there are no posts, return a defaultdict instead if len(posts) == 0: return defaultdict(str) @@ -85,6 +105,9 @@ class Posts: return post def postIterator(self, viewname): + """ + Post pagination + """ def inner(endkey=False, startkey=False): if startkey and not endkey: results = self.db.iterview(viewname, 2, include_docs=True, startkey=startkey) @@ -117,6 +140,9 @@ class Posts: return inner def allposts(self): + """ + Gets all of the post IDs in the database. May be inefficient. + """ result = self.db.iterview("blogPosts/unpublished", 10, include_docs=True) posts = [] diff --git a/src/website.py b/src/website.py index d75fc96..ed9b5bb 100755 --- a/src/website.py +++ b/src/website.py @@ -202,6 +202,7 @@ def NeverWhere(configfile=None): return posts.getbycategory(category) # XXX get the id of every post + # Needs to be fixed @app.route("/blog/allposts") def allposts(): return posts.allposts()