use db_session for articles and sections
This commit is contained in:
@@ -11,6 +11,7 @@ import json
|
||||
from src.database import db_session, read_json
|
||||
import flask
|
||||
|
||||
|
||||
#flask.json.JSONEncoder.default = lambda self,obj: ((ArticleSchema().dump(obj)[0]) if isinstance(obj, Article) else None)
|
||||
flask.json.JSONEncoder.default = lambda self,obj: ((obj.__json__()) if isinstance(obj, (Base, Article,CrawlUrl)) else None)
|
||||
from controller import controller
|
||||
@@ -38,7 +39,7 @@ def index():
|
||||
@article_pages.route("/<int:id>",methods=['PUT'])
|
||||
@article_pages.route("/<int:id>.json",methods=['PUT'])
|
||||
def update(id):
|
||||
article=Article.query.get(id)
|
||||
article=db_session.query(Article).get(id)
|
||||
clogger.info(request.data)
|
||||
a=request.get_json()
|
||||
article.text=a["text"]
|
||||
@@ -49,7 +50,7 @@ def update(id):
|
||||
@article_pages.route("/<int:id>",methods=['GET'])
|
||||
@article_pages.route("/<int:id>.json",methods=['GET'])
|
||||
def get(id):
|
||||
article=Article.query.get(id)
|
||||
article=db_session.query(Article).get(id)
|
||||
# clogger.info(article)
|
||||
# article=ArticleSchema().dump(article)[0]
|
||||
return jsonify(article=article)
|
||||
@@ -57,7 +58,7 @@ def get(id):
|
||||
@article_pages.route("/<int:id>",methods=['DELETE'])
|
||||
@article_pages.route("/<int:id>.json",methods=['DELETE'])
|
||||
def delete(id):
|
||||
article=Article.query.get(id)
|
||||
article=db_session.query(Article).get(id)
|
||||
# clogger.info(id)
|
||||
if article != None:
|
||||
db_session.delete(article)
|
||||
|
||||
Reference in New Issue
Block a user