diverse fixes und mysql
This commit is contained in:
@@ -3,8 +3,11 @@ from .model import ArticleSchema
|
||||
#import flask
|
||||
from datetime import datetime
|
||||
import json
|
||||
from src.sections.model import Section
|
||||
from src.organizations.model import Organization
|
||||
from src.database import db_session, read_json
|
||||
from src.controller import BaseController
|
||||
#from src.organizations.controller import controller as org_controller
|
||||
class ArtController(BaseController):
|
||||
__myclass__=Article
|
||||
__jsonid__='article'
|
||||
@@ -14,12 +17,14 @@ class ArtController(BaseController):
|
||||
pp=int(v["per_page"])
|
||||
else:
|
||||
pp=20
|
||||
except ValueError:
|
||||
pp=20
|
||||
try:
|
||||
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
|
||||
@@ -44,12 +49,22 @@ class ArtController(BaseController):
|
||||
return Article.query.filter(Article.section_id==section_id).order_by(Article.published_date.desc()).limit(lim).offset(off).all()
|
||||
|
||||
|
||||
def get_section_page(self,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_organization_page(self,organization_id, lim, off):
|
||||
sid=db_session.query(Section.id).filter(Section.organization_id==int(organization_id)).all()
|
||||
sid=map(lambda a:a[0], sid)
|
||||
articles=Article.query.filter(Article.section_id.in_(sid)).order_by(Article.published_date.desc()).limit(lim).offset(off).all()
|
||||
return articles
|
||||
#
|
||||
# return Article.query.filter(Article.section_id==section_id).order_by(Article.published_date.desc()).limit(lim).offset(off).all()
|
||||
|
||||
def section_count(self,section_id):
|
||||
return Article.query.filter(Article.section_id==section_id).count()
|
||||
|
||||
def organization_count(self,organization_id):
|
||||
sid=db_session.query(Section.id).filter(Section.organization_id==int(organization_id)).all()
|
||||
sid=map(lambda a:a[0], sid)
|
||||
return Article.query.filter(Article.section_id.in_(sid)).count()
|
||||
|
||||
def count(self):
|
||||
return Article.query.count()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user