online fixes for ruby
This commit is contained in:
@@ -98,7 +98,7 @@ def home():
|
||||
app.register_blueprint(article_pages, url_prefix='/articles')
|
||||
app.register_blueprint(section_pages, url_prefix='/sections')
|
||||
app.register_blueprint(compiler_pages, url_prefix='/compiler')
|
||||
app.register_blueprint(organization_pages, url_prefix='/organizations')
|
||||
#pp.register_blueprint(organization_pages, url_prefix='/organizations')
|
||||
app.register_blueprint(organization_pages, url_prefix='/organizations')
|
||||
app.register_blueprint(organizationtype_pages, url_prefix='/organizationtypes')
|
||||
|
||||
|
||||
@@ -44,13 +44,13 @@ 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(section_id, lim, off):
|
||||
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):
|
||||
def section_count(self,section_id):
|
||||
return Article.query.filter(Article.section_id==section_id).count()
|
||||
|
||||
def count():
|
||||
def count(self):
|
||||
return Article.query.count()
|
||||
|
||||
|
||||
|
||||
@@ -41,6 +41,32 @@ def calc_fingerprint_h(a):
|
||||
h.update(unicode(pp))
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
|
||||
class FullArticleSchema(Schema):
|
||||
id=fields.Integer()
|
||||
parent_id=fields.Integer(allow_none=True)
|
||||
url =fields.String()
|
||||
is_primary=fields.Boolean(allow_none=True)
|
||||
fingerprint=fields.String()
|
||||
hash=fields.String(allow_none=True)
|
||||
last_fetched=fields.DateTime(allow_none=True)
|
||||
first_fetched=fields.DateTime(allow_none=True)
|
||||
published_date=fields.DateTime()
|
||||
date=fields.DateTime(allow_none=True)
|
||||
text=fields.String()
|
||||
title=fields.String()
|
||||
author=fields.String(allow_none=True)
|
||||
section_id=fields.Integer()
|
||||
sourcetype =fields.String()
|
||||
image =fields.String(allow_none=True)
|
||||
# @post_load
|
||||
# def make_article(self, data):
|
||||
# return Article.deserialize(data)
|
||||
|
||||
|
||||
|
||||
|
||||
class Article(Base):
|
||||
__tablename__ = 'articles'
|
||||
id = Column(Integer, primary_key=True)
|
||||
@@ -60,7 +86,10 @@ class Article(Base):
|
||||
section_id=Column(Integer, ForeignKey('sections.id'))
|
||||
sourcetype = Column(String(250))
|
||||
image=Column(String(250))
|
||||
|
||||
__schema__=FullArticleSchema
|
||||
__jsonid__='article'
|
||||
__whiteattrs__= []
|
||||
__jsonattrs__=None
|
||||
def __init__(self, url=None,title=None, published_date=None):
|
||||
self.url=url
|
||||
self.title=title
|
||||
@@ -69,16 +98,16 @@ class Article(Base):
|
||||
def __json__(self):
|
||||
return ArticleSchema().dump(self)[0]
|
||||
|
||||
def dict(self):
|
||||
return {"id": str(int(self.id)), "title": self.title, "text": self.text, "author": self.author, "section":self.section, "sourcetype": self.sourcetype, "last_fetched": self.last_fetched, "first_fetched": self.first_fetched, "published_date": self.published_date, "date": self.date,"image": self.image, "url": self.url}
|
||||
# def dict(self):
|
||||
# return {"id": str(int(self.id)), "title": self.title, "text": self.text, "author": self.author, "section":self.section, "sourcetype": self.sourcetype, "last_fetched": self.last_fetched, "first_fetched": self.first_fetched, "published_date": self.published_date, "date": self.date,"image": self.image, "url": self.url}
|
||||
|
||||
@classmethod
|
||||
def deserialize(cls,data):
|
||||
a=Article()
|
||||
for c in Article.__table__.columns:
|
||||
if data.has_key(c.key):
|
||||
setattr(a, c.key,data[c.key])
|
||||
return a
|
||||
# @classmethod
|
||||
# def deserialize(cls,data):
|
||||
# a=Article()
|
||||
# for c in Article.__table__.columns:
|
||||
# if data.has_key(c.key):
|
||||
# setattr(a, c.key,data[c.key])
|
||||
# return a
|
||||
|
||||
# @classmethod
|
||||
# def sections(self):
|
||||
@@ -131,26 +160,6 @@ class Article(Base):
|
||||
|
||||
#json.JSONEncoder.default = lambda self,obj: ((ArticleSchema().dump(obj)[0]) if isinstance(obj, Article) else None)
|
||||
|
||||
class FullArticleSchema(Schema):
|
||||
id=fields.Integer()
|
||||
parent_id=fields.Integer(allow_none=True)
|
||||
url =fields.String()
|
||||
is_primary=fields.Boolean(allow_none=True)
|
||||
fingerprint=fields.String()
|
||||
hash=fields.String(allow_none=True)
|
||||
last_fetched=fields.DateTime(allow_none=True)
|
||||
first_fetched=fields.DateTime(allow_none=True)
|
||||
published_date=fields.DateTime()
|
||||
date=fields.DateTime(allow_none=True)
|
||||
text=fields.String()
|
||||
title=fields.String()
|
||||
author=fields.String(allow_none=True)
|
||||
section_id=fields.Integer()
|
||||
sourcetype =fields.String()
|
||||
image =fields.String(allow_none=True)
|
||||
@post_load
|
||||
def make_article(self, data):
|
||||
return Article.deserialize(data)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ def fbfeedelement(h):
|
||||
return art
|
||||
|
||||
|
||||
def fbfeed(url, raw):
|
||||
def fbfeed(url, raw, params={}):
|
||||
js = json.loads(raw)
|
||||
arts=[]
|
||||
u=urlparse.urlparse(url)
|
||||
|
||||
@@ -11,9 +11,10 @@ class BaseController():
|
||||
def create(self,request):
|
||||
d=read_json(request)
|
||||
clogger.info(d)
|
||||
clogger.info(d[self.__jsonid__])
|
||||
if d.has_key(self.__jsonid__):
|
||||
d= d[self.__jsonid__]
|
||||
o=self.__myclass__()
|
||||
success, errors=o.update(d[self.__jsonid__])
|
||||
success, errors=o.update(d)
|
||||
if success:
|
||||
db_session.add(o)
|
||||
try:
|
||||
|
||||
@@ -70,4 +70,8 @@ def delete(id):
|
||||
@organization_pages.route(".json",methods=['POST'])
|
||||
def create():
|
||||
organization,errors=controller.create(request)
|
||||
return jsonify(organization=organization,errors=errors)
|
||||
if len(errors)>0:
|
||||
http_code=422
|
||||
else:
|
||||
http_code=200
|
||||
return jsonify(organization=organization,errors=errors), http_code
|
||||
|
||||
9
sections/controller.py
Normal file
9
sections/controller.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from src.controller import BaseController
|
||||
from model import Section
|
||||
from src.database import db_session
|
||||
class SecController(BaseController):
|
||||
__myclass__=Section
|
||||
__jsonid__='section'
|
||||
|
||||
controller=SecController()
|
||||
|
||||
@@ -7,6 +7,7 @@ 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
|
||||
|
||||
@@ -21,12 +22,8 @@ def index():
|
||||
@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=read_json(request)
|
||||
section.update(a["section"])
|
||||
db_session.commit()
|
||||
return jsonify(section=section)
|
||||
section,errors=controller.update(id,request)
|
||||
return jsonify(section=section, errors=errors)
|
||||
|
||||
|
||||
@section_pages.route("/<int:id>",methods=['GET'])
|
||||
|
||||
Reference in New Issue
Block a user