organizations&organizationtypes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import json
|
||||
from src.articles.model import Article, FullArticleSchema
|
||||
from src.sections.model import Section, FullSectionSchema
|
||||
from src.database import db_session
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
@@ -9,10 +10,10 @@ if len(sys.argv) <= 1:
|
||||
|
||||
|
||||
def load_article(a):
|
||||
return FullArticleSchema().load(a[0]).data
|
||||
return Article.deserialize(a[0])
|
||||
|
||||
def load_section(s):
|
||||
return FullSectionSchema().load(s[0]).data
|
||||
return Section.deserialize(s[0])
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +24,7 @@ articles=None
|
||||
sections=None
|
||||
organizations=None
|
||||
|
||||
if isinstace(data,dict):
|
||||
if isinstance(data,dict):
|
||||
if data.has_key("articles"):
|
||||
articles=data["articles"]
|
||||
if data.has_key("sections"):
|
||||
@@ -34,7 +35,8 @@ else:
|
||||
|
||||
|
||||
articles= map (load_article, articles)
|
||||
sections=map(load_section,sections)
|
||||
if sections is not None:
|
||||
sections=map(load_section, sections)
|
||||
|
||||
for a in articles:
|
||||
try:
|
||||
@@ -44,14 +46,15 @@ for a in articles:
|
||||
db_session.rollback()
|
||||
finally:
|
||||
db_session.rollback()
|
||||
if sections is not None:
|
||||
for s in sections:
|
||||
if not isinstance(s,Section):
|
||||
print type(s)
|
||||
try:
|
||||
db_session.add(s)
|
||||
db_session.commit()
|
||||
except IntegrityError:
|
||||
db_session.rollback()
|
||||
|
||||
for s in sections:
|
||||
try:
|
||||
db_session.add(s)
|
||||
db_session.commit()
|
||||
except IntegrityError:
|
||||
db_session.rollback()
|
||||
finally:
|
||||
db_session.rollback()
|
||||
|
||||
file.close()
|
||||
|
||||
Reference in New Issue
Block a user