56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
from flask import Blueprint, jsonify, render_template, abort, redirect, url_for, request
|
|
section_pages = Blueprint('sections', __name__)
|
|
from .model import Section
|
|
from .model import SectionSchema
|
|
#import flask
|
|
from datetime import datetime
|
|
import json
|
|
from src import clogger
|
|
import src.articles.controller as article_controller
|
|
from src.database import db_session, read_json
|
|
import flask
|
|
|
|
@section_pages.route("/")
|
|
@section_pages.route("")
|
|
@section_pages.route(".json")
|
|
def index():
|
|
sections=Section.query.all()
|
|
return jsonify(sections=sections)
|
|
|
|
|
|
@section_pages.route("/<int:id>",methods=['PUT'])
|
|
@section_pages.route("/<int:id>.json",methods=['PUT'])
|
|
def update(id):
|
|
section=Section.query.get(id)
|
|
clogger.info(request.data)
|
|
a=request.get_json()
|
|
section.text=a["text"]
|
|
db_session.commit()
|
|
return jsonify(section=section)
|
|
|
|
|
|
@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]
|
|
return jsonify(section=section)
|
|
|
|
|
|
@section_pages.route("/<int:id>/articles",methods=['GET'])
|
|
@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
|
|
articles=article_controller.get_section_page(id,pp,o)
|
|
|
|
resp = jsonify(articles=articles)
|
|
resp.headers['Pagination-Limit']=pp
|
|
resp.headers['Pagination-Offset']=o
|
|
resp.headers['Pagination-TotalCount']=controller.count()
|
|
return resp
|
|
|
|
|
|
|