Browse Source

actually pull posts from database

pull/1/head
wes 7 years ago
parent
commit
ed15a8b100
  1. 20
      src/comment.py
  2. 6
      src/posts.py
  3. 42
      src/scripts/post.tag
  4. 1
      src/scripts/riotblog.js
  5. 2
      src/templates/index.html
  6. 21
      src/website.py

20
src/comment.py

@ -1,13 +1,11 @@
from json import dumps
from random import randint
from time import time
from uuid import uuid4
def comment(author, title, text, t):
def comment(author, title, text, t, uid):
return {
"time" : t,
"id" : randint(1,2**32-1),
"id" : uid,
"title" : title,
"author" : author,
"text" : text
@ -17,14 +15,14 @@ def comment(author, title, text, t):
testcomments = {
1 : dumps(
[
comment("Person 1", "Two", "A Comment here", 1),
comment("Person 2", "One", "Some other comment", 2),
comment("Person 3", "Three", "My opinion is correct", 3)
comment("Person 1", "Two", "A Comment here", 1, str(uuid4())),
comment("Person 2", "One", "Some other comment", 2, str(uuid4())),
comment("Person 3", "Three", "My opinion is correct", 3, str(uuid4()))
]),
2 : dumps(
[
comment("Person 1", "Two", "A cool terrible Comment here", 1),
comment("Person 2", "One", "Some other awful comment", 2),
comment("Person 3", "Three", "My opinion is not correct", 3)
comment("Person 1", "Two", "A cool terrible Comment here", 1, str(uuid4())),
comment("Person 2", "One", "Some other awful comment", 2, str(uuid4())),
comment("Person 3", "Three", "My opinion is not correct", 3, str(uuid4()))
])
}

6
src/posts.py

@ -3,6 +3,7 @@
import couchdb
from flask import jsonify
from flask_marshmallow import Marshmallow
#from comment import comment
class Posts:
def __init__(self, host=None, port=None):
@ -23,8 +24,9 @@ class Posts:
}
return jsonify(self.db.save(doc))
def getposts(self, start, end):
return jsonify([])
def getposts(self, limit, start):
result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True, limit=limit, skip=start)
return jsonify(list(result))
def getcomments(self, postID):
return jsonify([])

42
src/scripts/post.tag

@ -4,13 +4,13 @@
<button class={"btn btn-primary " + (this.nomore ? "disabled" : " ") + this.nextloading} onclick={this.next}>Next One</button>
</div>
<h4 class="post centered" if={nomore}>
<h4 class="post centered" if={this.nomore}>
No More Posts!
</h4>
<div if={!(this.loading || this.nomore)} class="post centered">
<h4>{ opts.title }</h4>
<h5>Posted by { opts.creator }</h5>
<h4>{ this.title }</h4>
<h5>Posted by { this.author }</h5>
<p class="post-content centered text-break">
{ this.content }
</p>
@ -28,13 +28,16 @@ import { default as R } from 'ramda';
var self = this;
this.loading = false;
this.prevloading = "";
this.nextloading = "";
self.author = "";
self.title = "";
self.content = "";
self.loading = false;
self.prevloading = "";
self.nextloading = "";
this.nomore = false
this.pid = 1;
this.content = "";
self.nomore = false;
self.pid = 1;
self.content = "";
prev(ev) {
ev.preventDefault();
@ -68,7 +71,7 @@ next(ev) {
setPost(pid) {
this.update();
this.loading = true;
fetch(`/blog/switchpost/${pid}`)
fetch(`/blog/switchpost/${pid-1}`)
.then((resp) => resp.text())
.then(
(body) => {
@ -78,7 +81,24 @@ setPost(pid) {
self.update()
}
else {
self.content = body;
var postcontent = JSON.parse(body);
console.log(postcontent);
if (postcontent.length == 0) {
self.loading = false;
self.prevloading = "";
self.nextloading = "";
self.author = "";
self.content = "";
self.title = "No more posts!";
self.nomore = true;
self.update();
route(`/${pid}`);
return;
}
self.author = postcontent[0].doc.author[0];
self.content = postcontent[0].doc.content[0];
self.title = postcontent[0].doc.title[0];
self.update();
route(`/${pid}`);
}

1
src/scripts/riotblog.js

@ -4,7 +4,6 @@ import './comment.tag';
import './bbutton.tag';
import './post.tag';
import './posts.tag';
import "./decision.tag";
riot.mount("post",
{

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 title</h1>
<h1 class="blog-title">w00t</h1>
</section>
</header>

21
src/website.py

@ -1,7 +1,7 @@
#! /usr/bin/python3
from functools import partial
from flask import abort, Flask, render_template, flash, request, send_from_directory
from flask import abort, Flask, render_template, flash, request, send_from_directory, jsonify
from werkzeug.local import Local, LocalProxy, LocalManager
from flask_appconfig import AppConfig
@ -17,7 +17,7 @@ cache = MemcachedCache(['127.0.0.1:11211'])
import os
from posts import Posts
#posts = Posts()
posts = Posts()
def cacheit(key, thunk):
"""
@ -62,15 +62,6 @@ def NeverWhere(configfile=None):
def send_style(filename):
return send_from_directory("/srv/http/riotblog/styles", filename)
@app.route("/blog/switchpost/<pid>")
def switchPost(pid):
posts = {
"1" : "post 1",
"2" : "post 2"
}
return posts.get(pid, "false")
@app.route("/blog/comments/<pid>")
def comments(pid):
try:
@ -83,6 +74,14 @@ def NeverWhere(configfile=None):
def insert():
return posts.savepost(**request.args)
@app.route("/blog/switchpost/<pid>")
def getposts(pid):
try:
index = int(pid)
except ValueError:
index = 0
return posts.getposts(index+1, index)
@app.route("/<path:path>")
def page_not_found(path):
return "Oops, couldn't find that :/"

Loading…
Cancel
Save