Browse Source

updating works now

pull/1/head
wes 7 years ago
parent
commit
87aa15a945
  1. 16
      src/posts.py
  2. 10
      src/scripts/editor.tag

16
src/posts.py

@ -16,13 +16,17 @@ class Posts:
self.db = self.client["blog"]
def savepost(self, title="", content="", author="", _id=False):
doc = {
"title" : title,
"content" : content,
"author" : author
}
if _id:
doc["_id"] = _id
doc = self.db[_id]
doc["title"] = title
doc["content"] = content
doc["author"] = author
else:
doc = {
"title" : title,
"content" : content,
"author" : author
}
return jsonify(self.db.save(doc))

10
src/scripts/editor.tag

@ -5,7 +5,7 @@
<ul>
<li each={this.currentPosts}>
<p>
{title} by {author}, id = {_id}
{title} by {author}
</p>
<button
class="btn btn-primary"
@ -87,17 +87,19 @@ echo(ev) {
}
submit() {
var post = self.querystring.stringify({
var post = {
"title" : this.refs.title.value,
"author" : this.refs.author.value,
"content" : this.refs.textarea.value,
"csrf_token" : this.opts.csrf_token
});
};
if (this._id) {
post["_id"] = this._id;
}
var postQuery = self.querystring.stringify(post);
var headers = {
"headers" : {
"Content-Type" : "application/x-www-form-urlencoded",
@ -105,7 +107,7 @@ submit() {
}
};
axios.post("/blog/insert/", post, headers)
axios.post("/blog/insert/", postQuery, headers)
.then(function(resp) {
console.log(resp);
})

Loading…
Cancel
Save