Browse Source

work towards editing properly

pull/1/head
wes 7 years ago
parent
commit
c321c22152
  1. 5
      src/posts.py
  2. 16
      src/scripts/editor.tag
  3. 4
      src/website.py

5
src/posts.py

@ -15,12 +15,15 @@ class Posts:
self.db = self.client["blog"]
def savepost(self, title="", content="", author=""):
def savepost(self, title="", content="", author="", _id=False):
doc = {
"title" : title,
"content" : content,
"author" : author
}
if _id:
doc["_id"] = _id
return jsonify(self.db.save(doc))
def getposts(self, limit, start):

16
src/scripts/editor.tag

@ -7,11 +7,16 @@
<p>
{title} by {author}, id = {_id}
</p>
<button onclick={loadPost(this._id)}>Load it</button>
<button
class="btn btn-primary"
onclick={loadPost(this._id)}>
Load it
</button>
</li>
</ul>
<span>title</span><input ref="title">
<span>author</span><input ref="author"></input>
<span>Editing post {_id}</span>
<textarea onfocus={clearplaceholder}
onblur={checkplaceholder}
oninput={echo}
@ -46,6 +51,8 @@ this.querystring = querystring;
this.converter = new showdown.Converter();
this.converted = "<h3>Nothing here yet</h3>";
this._id = false;
this.placeholderText = "Write a post!"
this.placeholder = this.placeholderText;
this.focused = false;
@ -87,6 +94,10 @@ submit() {
"csrf_token" : this.opts.csrf_token
});
if (this._id) {
post["_id"] = this._id;
}
var headers = {
"headers" : {
"Content-Type" : "application/x-www-form-urlencoded",
@ -111,6 +122,9 @@ loadPost(_id) {
axios.get(`/blog/getpost/${_id}`)
.then(function(resp) {
self.refs.textarea.value = resp.data.content;
self.refs.title.value = resp.data.title;
self.refs.author.value = resp.data.author;
self._id = _id;
self.focused = true;
self.update();
self.echo();

4
src/website.py

@ -121,9 +121,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)
postid = request.form.get("_id", False)
post = {"author" : author, "title" : title, "content" : content }
post = {"author" : author, "title" : title, "content" : content, "_id" : postid }
return posts.savepost(**post)

Loading…
Cancel
Save