organizations&organizationtypes
This commit is contained in:
@@ -4,47 +4,54 @@ from .model import ArticleSchema
|
||||
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:
|
||||
from src.controller import BaseController
|
||||
class ArtController(BaseController):
|
||||
__myclass__=Article
|
||||
__jsonid__='article'
|
||||
def pagination_params(self,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
|
||||
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)
|
||||
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
|
||||
p1=(pp,o)
|
||||
return p1
|
||||
|
||||
def search(self,s):
|
||||
return Article.query.filter(Article.title.like("%"+s+"%")).order_by(Article.published_date.desc()).limit(20).all()
|
||||
|
||||
|
||||
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_all(self):
|
||||
return Article.query.order_by(Article.published_date.desc()).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_all_page(self,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(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 section_count(section_id):
|
||||
return Article.query.filter(Article.section_id==section_id).count()
|
||||
|
||||
def count():
|
||||
return Article.query.count()
|
||||
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()
|
||||
|
||||
|
||||
controller=ArtController()
|
||||
|
||||
@@ -6,8 +6,6 @@ from .model import ArticleSchema
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
#flask.json.JSONEncoder.default = lambda self,obj: (obj.isoformat() if isinstance(obj, datetime) else None)
|
||||
#flask.json.JSONEncoder.default = lambda self,obj: ((obj.dict()) if isinstance(obj, Article) else None)
|
||||
from src import clogger
|
||||
import json
|
||||
from src.database import db_session, read_json
|
||||
@@ -15,7 +13,7 @@ import flask
|
||||
|
||||
#flask.json.JSONEncoder.default = lambda self,obj: ((ArticleSchema().dump(obj)[0]) if isinstance(obj, Article) else None)
|
||||
flask.json.JSONEncoder.default = lambda self,obj: ((obj.__json__()) if isinstance(obj, (Base, Article,CrawlUrl)) else None)
|
||||
import controller
|
||||
from controller import controller
|
||||
@article_pages.route("/")
|
||||
@article_pages.route("")
|
||||
@article_pages.route(".json")
|
||||
@@ -57,7 +55,7 @@ def get(id):
|
||||
@article_pages.route("/<int:id>.json",methods=['DELETE'])
|
||||
def delete(id):
|
||||
article=Article.query.get(id)
|
||||
clogger.info(id)
|
||||
# clogger.info(id)
|
||||
if article != None:
|
||||
db_session.delete(article)
|
||||
db_session.commit()
|
||||
|
||||
Reference in New Issue
Block a user