51 lines
1.5 KiB
Python
51 lines
1.5 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
|
|
from src.articles import controller as article_controller
|
|
from src.sections.controller import controller
|
|
from src.database import db_session, read_json
|
|
import flask
|
|
|
|
@section_pages.route("/")
|
|
@section_pages.route("")
|
|
@section_pages.route(".json")
|
|
def index():
|
|
sections=controller.get_all()
|
|
return jsonify(sections=sections)
|
|
|
|
|
|
@section_pages.route("/<int:id>",methods=['PUT'])
|
|
@section_pages.route("/<int:id>.json",methods=['PUT'])
|
|
def update(id):
|
|
section,errors=controller.update(id,request)
|
|
return jsonify(section=section, errors=errors)
|
|
|
|
|
|
@section_pages.route("/<int:id>",methods=['GET'])
|
|
@section_pages.route("/<int:id>.json",methods=['GET'])
|
|
def get(id):
|
|
section=controller.get(id)
|
|
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)
|
|
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']=article_controller.section_count(id)
|
|
return resp
|
|
|
|
|
|
|