implemented add post - todo create paragraphs

This commit is contained in:
Malar Kannan
2017-08-09 13:53:19 +05:30
parent a54d94f6ad
commit 3fec54ae75
21 changed files with 1497 additions and 588 deletions

View File

@@ -5,7 +5,7 @@ Licence: GPLv3
"""
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__,static_url_path='',static_folder='build')
@@ -16,5 +16,4 @@ app.config.from_object('app.configuration.DevelopmentConfig')
#app.config.from_object('configuration.TestingConfig')
db = SQLAlchemy(app) #flask-sqlalchemy
from app import views, models

View File

@@ -11,10 +11,11 @@ class Config(object):
DEBUG = False
TESTING = False
DATABASE_URI = 'sqlite:///application.db'
SQLALCHEMY_DATABASE_URI = 'sqlite:///application.db'
BOOTSTRAP_FONTAWESOME = True
SECRET_KEY = "MINHACHAVESECRETA"
SECRET_KEY = "BLOGAPPSECRETYO"
CSRF_ENABLED = True
SQLALCHEMY_TRACK_MODIFICATIONS = False
#Get your reCaptche key on: https://www.google.com/recaptcha/admin/create
#RECAPTCHA_PUBLIC_KEY = "6LffFNwSAAAAAFcWVy__EnOCsNZcG2fVHFjTBvRP"
#RECAPTCHA_PRIVATE_KEY = "6LffFNwSAAAAAO7UURCGI7qQ811SOSZlgU69rvv7"
@@ -23,6 +24,7 @@ class ProductionConfig(Config):
DATABASE_URI = 'mysql://user@localhost/foo'
class DevelopmentConfig(Config):
SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
DEBUG = True
class TestingConfig(Config):

View File

@@ -1,18 +0,0 @@
# -*- encoding: utf-8 -*-
"""
Python Aplication Template
Licence: GPLv3
"""
from flask.ext.wtf import Form, TextField, TextAreaField, DateTimeField, PasswordField
from flask.ext.wtf import Required
class ExampleForm(Form):
title = TextField(u'Título', validators = [Required()])
content = TextAreaField(u'Conteúdo')
date = DateTimeField(u'Data', format='%d/%m/%Y %H:%M')
#recaptcha = RecaptchaField(u'Recaptcha')
class LoginForm(Form):
user = TextField(u'Usuário', validators = [Required()])
password = PasswordField(u'Senha', validators = [Required()])

View File

@@ -9,31 +9,46 @@ from app import db
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(80))
body = db.Column(db.Text)
pub_date = db.Column(db.DateTime)
content = db.Column(db.Text)
# pub_date = db.Column(db.DateTime)
category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
category = db.relationship('Category',
backref=db.backref('posts', lazy='dynamic'))
def __init__(self, title, body, category, pub_date=None):
def __init__(self, title,content, pub_date=None):
self.title = title
self.body = body
if pub_date is None:
pub_date = datetime.utcnow()
self.pub_date = pub_date
self.category = category
self.content = content
# if pub_date is None:
# pub_date = datetime.utcnow()
# self.pub_date = pub_date
# paragraphs = text.split('\n\n')
# self.paragraphs = paragraphs
def __repr__(self):
return '<Post %r>' % self.title
class Category(db.Model):
class Paragraph(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50))
body = db.Column(db.Text)
def __init__(self, name):
self.name = name
post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
def __init__(self, body,post_id):
self.body = body
self.post_id = post_id
def __repr__(self):
return '<Category %r>' % self.name
return '<Post %r>' % self.title
class Comment(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50))
message = db.Column(db.String(140))
paragraph_id = db.Column(db.Integer, db.ForeignKey('paragraph.id'))
db.relationship('Paragraph',backref=db.backref('comments', lazy='dynamic'))
def __init__(self, name,message):
self.name = name
self.message = message
def __repr__(self):
return '<Comment %r>' % self.name
db.create_all()

View File

@@ -4,19 +4,31 @@ Python Aplication Template
Licence: GPLv3
"""
from flask import url_for, redirect, render_template, flash, g, session
from app import app
from flask import request
from flask_restless import APIManager
from app import app,db
from models import Post,Paragraph,Comment
# Create the Flask-Restless API manager.
manager = APIManager(app, flask_sqlalchemy_db=db)
# Create API endpoints, which will be available at /api/<tablename> by
# default. Allowed HTTP methods can be specified as well.
manager.create_api(Post, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Paragraph, methods=['GET'])
manager.create_api(Comment, methods=['GET','POST'])
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/api/addpost',methods=['POST'])
def addpost():
return 'Post Added'
@app.route('/api/listposts')
def listposts():
return 'Post Added'
#
# @app.route('/api/addpost',methods=['POST'])
# def addpost():
# return 'Post Added'
#
# @app.route('/api/listposts')
# def listposts():
# return 'Post Added'
# ====================