Merge branch 'master' of https://github.com/yamanq/smearcar-db
This commit is contained in:
commit
f676a6f905
@ -1,7 +1,7 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import render_template, jsonify, request
|
from flask import render_template, jsonify, request
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
import time
|
import datetime
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
|
||||||
@ -36,8 +36,8 @@ class Update(db.Model):
|
|||||||
author = db.Column(db.String(30), nullable=False)
|
author = db.Column(db.String(30), nullable=False)
|
||||||
title = db.Column(db.String(100), nullable=False)
|
title = db.Column(db.String(100), nullable=False)
|
||||||
content = db.Column(db.Text, nullable=False)
|
content = db.Column(db.Text, nullable=False)
|
||||||
date = db.Column(db.BigInteger, nullable=False,
|
date = db.Column(db.DateTime, nullable=False,
|
||||||
default=int(time.time()*1000))
|
default=datetime.datetime.now())
|
||||||
|
|
||||||
|
|
||||||
class Editor(db.Model):
|
class Editor(db.Model):
|
||||||
@ -214,11 +214,11 @@ def updates():
|
|||||||
update.content = received['content']
|
update.content = received['content']
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify([{"author": update.name,
|
return jsonify([{"author": update.author,
|
||||||
"id": update.id,
|
"id": update.id,
|
||||||
"title": update.title,
|
"title": update.title,
|
||||||
"content": update.content,
|
"content": update.content,
|
||||||
"date": update.date}
|
"date": update.date.strftime("%m/%d/%Y | %A, %B %d, %Y")}
|
||||||
for update in Update.query.all()])
|
for update in Update.query.all()])
|
||||||
|
|
||||||
# Manipulate Editor
|
# Manipulate Editor
|
||||||
|
|||||||
@ -327,41 +327,36 @@ document.onclick = function(event) {
|
|||||||
|
|
||||||
|
|
||||||
function homeCards() {
|
function homeCards() {
|
||||||
// GET posts from server
|
// TODO GET posts from server
|
||||||
var week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
||||||
var month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
$.ajax({
|
||||||
var examplePost = [
|
url: serverURL + '/updates',
|
||||||
{
|
type: 'GET'
|
||||||
author: "Kenneth Jao",
|
})
|
||||||
title: "Test Post!",
|
.then(
|
||||||
content: "This is test post! <a target='_blank' href='https://google.com'>Link</a> This link should work.<br> Newlines work.",
|
function success(incoming) {
|
||||||
date: new Date(2018, 0, 26, 4, 51)
|
var postList = incoming;
|
||||||
}
|
|
||||||
];
|
|
||||||
var home = document.getElementById("home");
|
var home = document.getElementById("home");
|
||||||
for(var i = 0; i < examplePost.length; i++) {
|
for(var i = 0; i < postList.length; i++) {
|
||||||
var div = document.createElement("div");
|
var div = document.createElement("div");
|
||||||
div.className = "card";
|
div.className = "card";
|
||||||
var h2 = document.createElement("h2");
|
var h2 = document.createElement("h2");
|
||||||
h2.textContent = examplePost[i].title;
|
h2.textContent = postList[i].title;
|
||||||
div.appendChild(h2);
|
div.appendChild(h2);
|
||||||
var h3 = document.createElement("h3");
|
var h3 = document.createElement("h3");
|
||||||
var dt = examplePost[i].date;
|
h3.textContent = postList[i].date;
|
||||||
var smallDate = (function() {
|
|
||||||
var m = (dt.getMonth()+1).toString();
|
|
||||||
var d = (dt.getDay()+1).toString();
|
|
||||||
m = (m.length === 1) ? "0" + m : m;
|
|
||||||
d = (d.length === 1) ? "0" + d : d;
|
|
||||||
return m+"/"+d+"/"+dt.getFullYear().toString();
|
|
||||||
})();
|
|
||||||
var fullDate = week[dt.getDay()] + ", " + month[dt.getMonth()] + " " + dt.getDate().toString() + ", " + dt.getFullYear().toString();
|
|
||||||
h3.textContent = smallDate + " | " + fullDate;
|
|
||||||
div.appendChild(h3);
|
div.appendChild(h3);
|
||||||
var p = document.createElement("p");
|
var p = document.createElement("p");
|
||||||
p.innerHTML = examplePost[i].content;
|
p.innerHTML = postList[i].content;
|
||||||
div.appendChild(p);
|
div.appendChild(p);
|
||||||
home.appendChild(div);
|
home.appendChild(div);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
function error(e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function chartOptions(graphData) {
|
function chartOptions(graphData) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user