loaddump_Articles
This commit is contained in:
@@ -4,7 +4,7 @@ from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from src.database import Base
|
||||
from src.database import db_session
|
||||
from marshmallow import Schema, fields
|
||||
from marshmallow import Schema, fields, post_load
|
||||
from src.sections.model import Section
|
||||
|
||||
#import json
|
||||
@@ -72,7 +72,14 @@ class Article(Base):
|
||||
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 sections(self):
|
||||
# sects=db_session.query(Article.section).distinct().all()
|
||||
@@ -124,6 +131,29 @@ 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):
|
||||
id=fields.Integer()
|
||||
text=fields.String()
|
||||
|
||||
Reference in New Issue
Block a user