online fixes for ruby

This commit is contained in:
uwsgi
2017-02-11 12:48:30 +01:00
parent 621e1ca1ad
commit 49ac42b9a5
8 changed files with 65 additions and 45 deletions

View File

@@ -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,27 +160,7 @@ 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)
class ArticleSchema(Schema):