Files
fachschaften/articles/controller.py
Andreas Stephanides dc835e9788 count fix 2
2017-01-26 16:28:39 +01:00

51 lines
1.4 KiB
Python

from .model import Article
from .model import ArticleSchema
#import flask
from datetime import datetime
import json
from src.database import db_session, read_json
def pagination_params(v):
try:
if v.has_key("per_page"):
pp=int(v["per_page"])
else:
pp=20
if v.has_key("page"):
o=(int(v["page"])-1) *pp
else:
o=0
except ValueError:
pp=20
o=0
if not (isinstance(pp,int) and pp>0 and pp<10000):
pp=20
if not (isinstance(o,int) and o>=0 and o<100000):
o=0
return (pp, o)
def get_all():
return Article.query.order_by(Article.published_date.desc()).all()
def search(s):
return Article.query.filter(Article.title.like("%"+s+"%")).order_by(Article.published_date.desc()).limit(20).all()
def get_all_page(lim, off):
return Article.query.order_by(Article.published_date.desc()).limit(lim).offset(off).all()
def get_section_page(section_id, lim, off):
return Article.query.filter(Article.section_id==section_id).order_by(Article.published_date.desc()).limit(lim).offset(off).all()
def get_section_page(section_id, lim, off):
return Article.query.filter(Article.section_id==section_id).order_by(Article.published_date.desc()).limit(lim).offset(off).all()
def section_count(section_id):
return Article.query.filter(Article.section_id==section_id).count()
def count():
return Article.query.count()