Browse Source

basic post deleting semi-working

pull/1/head
wes 7 years ago
parent
commit
88f707e9db
  1. 11
      src/posts.py
  2. 30
      src/scripts/editor.tag
  3. 7
      src/scripts/zipper.js
  4. 2
      src/website.py

11
src/posts.py

@ -1,6 +1,8 @@
#! /usr/bin/python
import couchdb
from couchdb.http import ResourceConflict, ResourceNotFound
from flask import jsonify
from flask_marshmallow import Marshmallow
@ -51,4 +53,11 @@ class Posts:
return jsonify(self.db[_id])
def delete(self, _id):
return self.db[_id].delete()
doc = self.db[_id]
try:
self.db.delete(doc)
return jsonify(True)
except (ResourceNotFound, ResourceConflict) as e:
print(e)
return jsonify(False)

30
src/scripts/editor.tag

@ -24,7 +24,17 @@
>
Next
</button>
<p>
<span>title</span><input ref="title">
<span>author</span><input ref="author"></input>
<span>Editing post {this.currentPost()._id}</span>
<p>
<button
class="btn btn-primary"
onclick={deletePost(this.currentPost()._id)}
>
Delete Post
</button>
<button
class="btn btn-primary"
onclick={newPost}
@ -32,11 +42,6 @@
New Post
</button>
</p>
<p>
<span>title</span><input ref="title">
<span>author</span><input ref="author"></input>
<span>Editing post {this.currentPost()._id}</span>
<textarea onfocus={clearplaceholder}
onblur={checkplaceholder}
oninput={echo}
@ -161,6 +166,7 @@ submit() {
/* Refresh the current list of posts */
self._id = resp.data[0];
self.listPosts();
console.log(self.currentPosts);
})
.catch(function(err) {
console.log(err);
@ -187,6 +193,20 @@ loadPost(_id) {
};
}
deletePost(_id) {
return function() {
axios.get(`/blog/deletepost/${self.currentPost()._id}`)
.then(function(resp) {
self.update({"currentPosts" : Z.empty});
self.newPost();
self.listPosts();
})
.catch(function(err) {
console.log(err);
})
};
}
listPosts() {
axios.get("/blog/allposts")
.then(function(resp) {

7
src/scripts/zipper.js

@ -47,6 +47,10 @@ function extend(z, xs) {
return Zipper(z.left, z.right.concat(xs));
}
function removeCurrent(z) {
return Zipper(z.left, z.right.shift());
}
var empty = fromList([]);
export default {
@ -56,5 +60,6 @@ export default {
"goLeft" : goLeft,
"empty" : empty,
"fromList" : fromList,
"extend" : extend
"extend" : extend,
"removeCurrent" : removeCurrent
};

2
src/website.py

@ -101,7 +101,7 @@ def NeverWhere(configfile=None):
def getpost(_id):
return posts.getpost(_id)
@app.route("/blog/del/<_id>")
@app.route("/blog/deletepost/<_id>")
@login_required
def delete(_id):
return posts.delete(_id)

Loading…
Cancel
Save