organizations&organizationtypes
This commit is contained in:
@@ -10,34 +10,70 @@ import flask
|
||||
|
||||
#from src.articles import Article
|
||||
|
||||
class OrganizationtypeCompSchema(Schema):
|
||||
id =fields.Integer()
|
||||
name=fields.String()
|
||||
|
||||
class OrganizationCompSchema(Schema):
|
||||
id =fields.Integer()
|
||||
name=fields.String()
|
||||
organizationtype=fields.Nested(OrganizationtypeCompSchema)
|
||||
|
||||
class FullSectionSchema(Schema):
|
||||
id=fields.Integer()
|
||||
url =fields.String(allow_none=True )
|
||||
crawlurl =fields.Integer(required=False,allow_none=True )
|
||||
#published_date=fields.DateTime()
|
||||
#date=fields.DateTime(allow_none=True)
|
||||
name=fields.String(required=False,allow_none=True )
|
||||
title=fields.String(dump_only=True)
|
||||
foreign_name=fields.String()
|
||||
group=fields.String(required=False,allow_none=True )
|
||||
organization=fields.Nested(OrganizationCompSchema)
|
||||
updated_at = fields.DateTime()
|
||||
created_at = fields.DateTime()
|
||||
|
||||
# @post_load
|
||||
# def make_section(self, data):
|
||||
# return Section.deserialize(data)
|
||||
|
||||
|
||||
|
||||
class Section(Base):
|
||||
__tablename__ = 'sections'
|
||||
id = Column(Integer, primary_key=True)
|
||||
# id = Column(Integer, primary_key=True)
|
||||
url = Column(String(250))
|
||||
crawlurl = Column(Integer)
|
||||
foreign_name = Column(String(250),unique=True)
|
||||
name=Column(String(250))
|
||||
group = Column(String(250))
|
||||
organization_id=Column(Integer, ForeignKey('organizations.id'))
|
||||
organization=relationship("Organization")
|
||||
articles=relationship("Article", back_populates="section")
|
||||
|
||||
def __json__(self):
|
||||
return SectionSchema().dump(self)[0]
|
||||
__schema__=FullSectionSchema
|
||||
__whiteattrs__=["name", "organization_id", "url"]
|
||||
__jsonattrs__ = ["name", "organization_id", "foreign_name", "title", "url", "name", "id", "organization.name", "organization.organizationtype.name", "updated_at"]
|
||||
# def __json__(self):
|
||||
# return SectionSchema().dump(self)[0]
|
||||
def __init__(self, url=None,fname=None):
|
||||
self.url=url
|
||||
self.foreign_name=fname
|
||||
|
||||
# def dict(self):
|
||||
# SectionSchema.dump(self)[0]
|
||||
|
||||
def title(self):
|
||||
t=self.name
|
||||
if t == None or t.strip()=="":
|
||||
t=self.foreign_name
|
||||
return t
|
||||
@classmethod
|
||||
def deserialize(cls,data):
|
||||
a=Section()
|
||||
for c in Section.__table__.columns:
|
||||
if data.has_key(c.key):
|
||||
setattr(a, c.key,data[c.key])
|
||||
return a
|
||||
# @classmethod
|
||||
# def deserialize(cls,data):
|
||||
# a=Section()
|
||||
# for c in Section.__table__.columns:
|
||||
# if data.has_key(c.key):
|
||||
# setattr(a, c.key,data[c.key])
|
||||
# return a
|
||||
|
||||
@classmethod
|
||||
def find_or_create(cls, fname):
|
||||
@@ -51,19 +87,6 @@ class Section(Base):
|
||||
db_session.commit()
|
||||
return s
|
||||
|
||||
class FullSectionSchema(Schema):
|
||||
id=fields.Integer()
|
||||
url =fields.String()
|
||||
crawlurl =fields.Integer()
|
||||
#published_date=fields.DateTime()
|
||||
#date=fields.DateTime(allow_none=True)
|
||||
name=fields.String()
|
||||
foreign_name=fields.String()
|
||||
group=fields.String()
|
||||
@post_load
|
||||
def make_section(self, data):
|
||||
return Article.deserialize(data)
|
||||
|
||||
|
||||
|
||||
class ArticleCompSchema(Schema):
|
||||
@@ -80,8 +103,8 @@ class ArticleCompSchema(Schema):
|
||||
section_id=fields.Integer()
|
||||
|
||||
#from src.articles.model import ArticleCompSchema
|
||||
class SectionSchema(Schema):
|
||||
id=fields.Integer()
|
||||
foreign_name=fields.String()
|
||||
name=fields.String()
|
||||
#class SectionSchema(Schema):
|
||||
# id=fields.Integer()
|
||||
# foreign_name=fields.String()
|
||||
# name=fields.String()
|
||||
# articles=fields.Nested(ArticleCompSchema,many=True)
|
||||
|
||||
Reference in New Issue
Block a user