Browse Source

endpoint to retrieve current post IDs along with titles and authors

pull/1/head
wes 7 years ago
parent
commit
bbb51688c1
  1. 13
      src/posts.py
  2. 14
      src/scripts/editor.tag
  3. 2
      src/templates/write.html
  4. 7
      src/website.py

13
src/posts.py

@ -26,3 +26,16 @@ class Posts:
def getposts(self, limit, start):
result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True, limit=limit, skip=start)
return jsonify(list(result))
def allposts(self):
result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True)
posts = []
for item in result:
posts.append({
"_id" : item.doc["_id"],
"title" : item.doc["title"],
"author" : item.doc["author"]
})
return jsonify(posts)

14
src/scripts/editor.tag

@ -24,7 +24,6 @@
<div class="column col-6">
<raw content="{this.converted}"></raw>
</div>
</div>
</div>
<script>
@ -97,5 +96,18 @@ submit() {
console.log("Submitting the post");
console.log(post);
}
listPosts() {
axios.get("/blog/allposts")
.then(function(resp) {
console.log(resp);
})
.catch(function(err) {
console.log(err);
})
}
self.listPosts();
</script>
</editor>

2
src/templates/write.html

@ -26,8 +26,8 @@
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="/blog/scripts/riotblog.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript" src="/blog/scripts/riotblog.min.js"></script>
{% endblock %}
</body>

7
src/website.py

@ -93,6 +93,10 @@ def NeverWhere(configfile=None):
index = 0
return posts.getposts(index+1, index)
@app.route("/blog/allposts")
def allposts():
return posts.allposts()
# editor routes
@app.route("/blog/editor/", methods=("GET", "POST"))
@ -113,8 +117,9 @@ def NeverWhere(configfile=None):
author = request.form.get("author", "no author")
title = request.form.get("title", "no title")
content = request.form.get("content", "no content")
postid = request.form.get("postid", False)
post = {"author" : author, "title" : title, "content" : content}
post = {"author" : author, "title" : title, "content" : content }
return posts.savepost(**post)

Loading…
Cancel
Save