Browse Source

add couchdb and marshmallow

pull/1/head
wes 7 years ago
parent
commit
1132fac75c
  1. 12
      build/comment.py
  2. 25
      build/posts.py
  3. 3
      build/requirements.txt
  4. 2
      build/scripts/tags.min.js
  5. 2
      build/templates/index.html
  6. 42
      build/templates/templates/index.html
  7. 12
      build/website.py
  8. 3
      fabfile.py
  9. 3
      requirements.txt
  10. 12
      src/comment.py
  11. 25
      src/posts.py
  12. 4
      src/tags/post.tag
  13. 2
      src/templates/index.html
  14. 12
      src/website.py

12
build/comment.py

@ -10,9 +10,9 @@ def comment(author, title, text):
testcomments = {
1 : dumps(
[
comment("Anonymous Coward", "Some comment?", "super duper awesome comment here"),
comment("Anonymous Coward 3", "Something? IDEK", "super duper worse comment here"),
comment("Anonymous Coward 2", "Some other comment?", "super duper dang terrible comment here")
])
}
[
comment("Anonymous Coward 0", "Some comment?", "super duper awesome comment here"),
comment("Anonymous Coward 1", "Something? IDEK", "super duper worse comment here"),
comment("Anonymous Coward 2", "Some other comment?", "super duper dang terrible comment here")
])
}

25
build/posts.py

@ -1 +1,24 @@
from functools import total_ordering
#! /usr/bin/python
import couchdb
from flask import jsonify
from flask_marshmallow import Marshmallow
class Posts:
def __init__(self, host=None, port=None):
if host is None:
host = "localhost"
if port is None:
port = "5984"
self.client = couchdb.Server("http://%s:%s" % (host, port))
self.db = self.client["blog"]
def savepost(self, title, content, author):
doc = {
"title" : title,
"content" : content,
"author" : author
}
return jsonify(self.db.save(doc))

3
build/requirements.txt

@ -1,10 +1,13 @@
appdirs==1.4.0
click==6.7
CouchDB==1.1
Flask==0.12
flask-appconfig==0.11.1
flask-marshmallow==0.7.0
itsdangerous==0.24
Jinja2==2.9.5
MarkupSafe==0.23
marshmallow==2.13.0
packaging==16.8
pyparsing==2.1.10
python-memcached==1.58

2
build/scripts/tags.min.js

@ -79,7 +79,7 @@ this.on("mount",
});
riot.tag2('post', '<div class="postnav centered"> <button class="{⁗btn btn-primary ⁗ + (this.pid <= 1 ? ⁗disabled⁗ : ⁗ ⁗) + this.prevloading}" onclick="{prev}">Go Back</button> <button class="{⁗btn btn-primary ⁗ + (this.nomore ? ⁗disabled⁗ : ⁗ ⁗) + this.nextloading}" onclick="{next}">Go Forward</button> </div> <h4 class="post centered" if="{nomore}"> No More Posts! </h4> <div if="{!(loading || nomore)}" class="post centered"> <h4>{opts.title}</h4> <h5>By {opts.creator}</h5> <p class="post-content centered text-break">{content}</p> <div class="divider"></div> <comments pid="{pid}"> </comments> </div>', '', '', function(opts) {
riot.tag2('post', '<div class="postnav centered"> <button class="{⁗btn btn-primary ⁗ + (this.pid <= 1 ? ⁗disabled⁗ : ⁗ ⁗) + this.prevloading}" onclick="{prev}">Last One</button> <button class="{⁗btn btn-primary ⁗ + (this.nomore ? ⁗disabled⁗ : ⁗ ⁗) + this.nextloading}" onclick="{next}">Next One</button> </div> <h4 class="post centered" if="{nomore}"> No More Posts! </h4> <div if="{!(loading || nomore)}" class="post centered"> <h4>{opts.title}</h4> <h5>By {opts.creator}</h5> <p class="post-content centered text-break">{content}</p> <div class="divider"></div> <comments pid="{pid}"> </comments> </div>', '', '', function(opts) {
var self = this;
this.loading = false;

2
build/templates/index.html

@ -2,7 +2,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<header class="text-center nav navbar">
<section class="centered page-top navbar-section">
<h1 class="blog-title">blog</h1>
<h1 class="blog-title">nowhere</h1>
</section>
</header>
{% endblock %}

42
build/templates/templates/index.html

@ -1,42 +0,0 @@
{% block head %}
<meta name="viewport" content="width=device-width, initial-scale=1">
<header class="text-center nav navbar">
<section class="centered page-top navbar-section">
<h1 class="blog-title">blog</h1>
</section>
</header>
{% endblock %}
<html>
<body>
{% block content %}
<posts>
<post></post>
</posts>
<editor>
</editor>
{% endblock %}
<footer class="footer">
</footer>
{% block styles %}
<link rel="stylesheet" href="/blog/styles/spectre.min.css">
<link rel="stylesheet" href="/blog/styles/riotblog.min.css">
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.22.1/ramda.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/riot/2.6.7/riot+compiler.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/riot-route/3.0.2/route.min.js"></script>
<script type="text/javascript" src="/blog/scripts/tags.min.js"></script>
<script type="text/javascript" src="/blog/scripts/riotblog.min.js"></script>
{% endblock %}
</body>
</html>

12
build/website.py

@ -2,6 +2,7 @@
from functools import partial
from flask import abort, Flask, render_template, flash, request, send_from_directory
from werkzeug.local import Local, LocalProxy, LocalManager
from flask_appconfig import AppConfig
from urllib.parse import unquote
@ -14,6 +15,9 @@ from werkzeug.contrib.cache import MemcachedCache
cache = MemcachedCache(['127.0.0.1:11211'])
import os
from posts import Posts
posts = Posts()
def cacheit(key, thunk):
"""
@ -33,6 +37,8 @@ def NeverWhere(configfile=None):
app = Flask(__name__)
app.config["TEMPLATES_AUTO_RELOAD"] = True
app.config["COUCHDB_SERVER"] = "http://localhost:5984"
app.config["COUCHDB_DATABASE"] = "blog"
#def favicon():
#return send_from_directory("/srv/http/goal/favicon.ico",
#'favicon.ico', mimetype='image/vnd.microsoft.icon')
@ -68,9 +74,9 @@ def NeverWhere(configfile=None):
print(e)
return dumps([])
@app.route("/blog/insert/<pid>")
def insert(pid):
print("inserting new post")
@app.route("/blog/insert/")
def insert():
return posts.savepost(**request.args)
@app.route("/<path:path>")
def page_not_found(path):

3
fabfile.py

@ -80,6 +80,8 @@ def update():
@task
def locbuild():
local("mkdir -p build/{scripts,styles}")
local("cp requirements.txt ./build/requirements.txt")
buildLocalVenv()
buildTags()
buildScss()
minifyJS()
@ -91,4 +93,3 @@ def locbuild():
local("sudo systemctl daemon-reload")
local("sudo systemctl enable blog.service")
local("sudo systemctl restart blog.service")
local("sudo systemctl restart nginx")

3
requirements.txt

@ -1,10 +1,13 @@
appdirs==1.4.0
click==6.7
CouchDB==1.1
Flask==0.12
flask-appconfig==0.11.1
flask-marshmallow==0.7.0
itsdangerous==0.24
Jinja2==2.9.5
MarkupSafe==0.23
marshmallow==2.13.0
packaging==16.8
pyparsing==2.1.10
python-memcached==1.58

12
src/comment.py

@ -10,9 +10,9 @@ def comment(author, title, text):
testcomments = {
1 : dumps(
[
comment("Anonymous Coward", "Some comment?", "super duper awesome comment here"),
comment("Anonymous Coward 3", "Something? IDEK", "super duper worse comment here"),
comment("Anonymous Coward 2", "Some other comment?", "super duper dang terrible comment here")
])
}
[
comment("Anonymous Coward 0", "Some comment?", "super duper awesome comment here"),
comment("Anonymous Coward 1", "Something? IDEK", "super duper worse comment here"),
comment("Anonymous Coward 2", "Some other comment?", "super duper dang terrible comment here")
])
}

25
src/posts.py

@ -1 +1,24 @@
from functools import total_ordering
#! /usr/bin/python
import couchdb
from flask import jsonify
from flask_marshmallow import Marshmallow
class Posts:
def __init__(self, host=None, port=None):
if host is None:
host = "localhost"
if port is None:
port = "5984"
self.client = couchdb.Server("http://%s:%s" % (host, port))
self.db = self.client["blog"]
def savepost(self, title, content, author):
doc = {
"title" : title,
"content" : content,
"author" : author
}
return jsonify(self.db.save(doc))

4
src/tags/post.tag

@ -1,7 +1,7 @@
<post>
<div class="postnav centered">
<button class={"btn btn-primary " + (this.pid <= 1 ? "disabled" : " ") + this.prevloading} onclick={prev}>Go Back</button>
<button class={"btn btn-primary " + (this.nomore ? "disabled" : " ") + this.nextloading} onclick={next}>Go Forward</button>
<button class={"btn btn-primary " + (this.pid <= 1 ? "disabled" : " ") + this.prevloading} onclick={prev}>Last One</button>
<button class={"btn btn-primary " + (this.nomore ? "disabled" : " ") + this.nextloading} onclick={next}>Next One</button>
</div>
<h4 class="post centered" if={nomore}>

2
src/templates/index.html

@ -2,7 +2,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<header class="text-center nav navbar">
<section class="centered page-top navbar-section">
<h1 class="blog-title">blog</h1>
<h1 class="blog-title">nowhere</h1>
</section>
</header>
{% endblock %}

12
src/website.py

@ -2,6 +2,7 @@
from functools import partial
from flask import abort, Flask, render_template, flash, request, send_from_directory
from werkzeug.local import Local, LocalProxy, LocalManager
from flask_appconfig import AppConfig
from urllib.parse import unquote
@ -14,6 +15,9 @@ from werkzeug.contrib.cache import MemcachedCache
cache = MemcachedCache(['127.0.0.1:11211'])
import os
from posts import Posts
posts = Posts()
def cacheit(key, thunk):
"""
@ -33,6 +37,8 @@ def NeverWhere(configfile=None):
app = Flask(__name__)
app.config["TEMPLATES_AUTO_RELOAD"] = True
app.config["COUCHDB_SERVER"] = "http://localhost:5984"
app.config["COUCHDB_DATABASE"] = "blog"
#def favicon():
#return send_from_directory("/srv/http/goal/favicon.ico",
#'favicon.ico', mimetype='image/vnd.microsoft.icon')
@ -68,9 +74,9 @@ def NeverWhere(configfile=None):
print(e)
return dumps([])
@app.route("/blog/insert/<pid>")
def insert(pid):
print("inserting new post")
@app.route("/blog/insert/")
def insert():
return posts.savepost(**request.args)
@app.route("/<path:path>")
def page_not_found(path):

Loading…
Cancel
Save