Browse Source

updating works now

pull/1/head
wes 8 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"] self.db = self.client["blog"]
def savepost(self, title="", content="", author="", _id=False): def savepost(self, title="", content="", author="", _id=False):
doc = {
"title" : title,
"content" : content,
"author" : author
}
if _id: 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)) return jsonify(self.db.save(doc))

10
src/scripts/editor.tag

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

Loading…
Cancel
Save