use db_session for articles and sections
This commit is contained in:
@@ -34,11 +34,6 @@ class FullSectionSchema(Schema):
|
||||
updated_at = fields.DateTime()
|
||||
created_at = fields.DateTime()
|
||||
|
||||
# @post_load
|
||||
# def make_section(self, data):
|
||||
# return Section.deserialize(data)
|
||||
|
||||
|
||||
|
||||
class Section(Base):
|
||||
__tablename__ = 'sections'
|
||||
@@ -78,7 +73,7 @@ class Section(Base):
|
||||
|
||||
@classmethod
|
||||
def find_or_create(cls, fname):
|
||||
s=Section.query.filter(Section.foreign_name==fname).first()
|
||||
s=db_session.query(Section).filter(Section.foreign_name==fname).first()
|
||||
if s is None:
|
||||
s=Section(fname)
|
||||
db_session.add(s)
|
||||
|
||||
@@ -15,7 +15,7 @@ import flask
|
||||
@section_pages.route("")
|
||||
@section_pages.route(".json")
|
||||
def index():
|
||||
sections=Section.query.all()
|
||||
sections=controller.get_all()
|
||||
return jsonify(sections=sections)
|
||||
|
||||
|
||||
@@ -29,9 +29,7 @@ def update(id):
|
||||
@section_pages.route("/<int:id>",methods=['GET'])
|
||||
@section_pages.route("/<int:id>.json",methods=['GET'])
|
||||
def get(id):
|
||||
section=Section.query.get(id)
|
||||
clogger.info(section)
|
||||
# section=SectionSchema().dump(section)[0]
|
||||
section=controller.get(id)
|
||||
return jsonify(section=section)
|
||||
|
||||
|
||||
@@ -39,7 +37,7 @@ def get(id):
|
||||
@section_pages.route("/<int:id>/articles.json",methods=['GET'])
|
||||
def get_articles(id):
|
||||
v=request.values
|
||||
pp,o=article_controller.pagination_params(v) # extract per_page and offset from params
|
||||
pp,o=article_controller.pagination_params(v)
|
||||
articles=article_controller.get_section_page(id,pp,o)
|
||||
|
||||
resp = jsonify(articles=articles)
|
||||
|
||||
Reference in New Issue
Block a user