本文整理汇总了Python中models.DBSession.add_all方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add_all方法的具体用法?Python DBSession.add_all怎么用?Python DBSession.add_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.DBSession
的用法示例。
在下文中一共展示了DBSession.add_all方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import add_all [as 别名]
def _init(self, stmtrs):
# BANKTRANLIST
tranlist = stmtrs.find('BANKTRANLIST')
if tranlist is not None:
self.transactions = TransactionList(self.account, tranlist)
DBSession.add_all(self.transactions)
# LEDGERBAL - mandatory
ledgerbal = stmtrs.find('LEDGERBAL')
self.ledgerbal = ledgerbal.instantiate(acctfrom=self.account)
DBSession.add(self.ledgerbal)
# AVAILBAL
availbal = stmtrs.find('AVAILBAL')
if availbal is not None:
self.availbal = availbal.instantiate(acctfrom=self.account)
DBSession.add(self.availbal)
ballist = stmtrs.find('BALLIST')
if ballist:
self.other_balances = [bal.instantiate() for bal in ballist]
DBSession.add_all(self.other_balances)
# Unsupported subaggregates
for tag in ('MKTGINFO', ):
child = stmtrs.find(tag)
if child:
stmtrs.remove
示例2: instantiate
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import add_all [as 别名]
def instantiate(self):
""" """
if not hasattr(self, '_root'):
raise ValueError('Must first call parse() to have data to instantiate')
# SECLIST - list of description of securities referenced by
# INVSTMT (investment account statement)
seclist = self.find('SECLISTMSGSRSV1/SECLIST')
if seclist is not None:
self.securities = [
sec.instantiate()
for sec in seclist
]
DBSession.add_all(self.securities)
# TRNRS - transaction response, which is the main section
# containing account statements
#
# N.B. This iteration method doesn't preserve the original
# ordering of the statements within the OFX response
for stmtClass in (BankStatement, CreditCardStatement, InvestmentStatement):
tagname = stmtClass._tagName
for trnrs in self.findall('*/%sTRNRS' % tagname):
# *STMTTRNRS may have no *STMTRS (in case of error).
# Don't blow up; skip silently.
stmtrs = trnrs.find('%sRS' % tagname)
if stmtrs is not None:
stmt = stmtClass(stmtrs)
self.statements.append(stmt)
示例3: process
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import add_all [as 别名]
def process(self):
# Process Twitter -> Weibo
self.__log('START_PROCESSING')
c_ = DBSession.query(Customer).all()
# obtain twitter handler
api = TwiboEngine.getTwitterHandler()
if not api:
self.__log('TWITTER_API_ERROR' )
return
for c in c_:
self.__log('START_PROCESSING_CUSTOMER', c.id )
# load tweets
t_ = TwiboEngine.getNewTweetsByUserId(api, c.tw_name)
t_set = list()
#w_set = list()
for t in t_:
new_t = Tweet(t, c.id)
self.__log('NEW_TWEET', c.id, str(t.id), t.text.encode('utf-8'))
t_set.append(new_t)
with transaction.manager:
DBSession.add_all(t_set)
#DBSession.add_all(w_set)
self.__log('NEW_TWEETS_LOADED', c.id)
# Login Weibo
if c.wi_account_name.strip() is not '' and c.wi_account_pwd.strip() is not '':
weibo_client = TwiboEngine.getWeiboHandler(c.wi_account_name, c.wi_account_pwd)
else:
weibo_client = None
if not weibo_client:
self.__log('WRONG_WEIBO_ACCOUNT', c.id, None,'NO WEIBO ACCOUNT for Customer '+str(c.tw_name)+', Auto Sync would be turned off')
if c.auto_sync:
c.auto_sync = False
DBSession.commit()
continue
w_set = list()
for t in c.tweets:
if not t.Weibo:
try:
w = weibo_client.statuses.update.post(status = TwitterParser.process(t.text).encode('utf-8'))
except weibo.APIError:
w = None
if w:
w_set.append(Weibo(w, t.id, c.id))
self.__log('NEW_WEIBO', c.id, str(w.id), w.text.encode('utf-8'))
else:
self.__log('WRONG_POST_WEIBO', c.id, str(t.id) )
with transaction.manager:
DBSession.add_all(w_set)
self.__log('WEIBO_SYNDICATED', c.id)
self.__log('END_PROCESSING_CUSTOMER', c.id )
self.__log('END_PROCESSING')
示例4: User
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import add_all [as 别名]
from models import Session, User, Photo, Friendship, Friendrequest, Base, engine, DBSession
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
user1 = User(name = "Ann", lastname ="Smith",login='An', password ='123',city='Ekb', age=20,avatar = 'http://localhost:6543/static/An.jpg')
user2 = User(name = "Sarah", lastname ="Bet",login='SB', password ='000',city='New York', age=17,avatar = 'http://localhost:6543/static/SB.jpg')
user3 = User(name = "John", lastname ="Worf",login='JJ', password ='90',city='London', age=21,avatar = 'http://localhost:6543/static/JJ.jpg')
photo1 = Photo(user_id = 1, path = 'http://localhost:6543/static/9.jpg')
photo2 = Photo(user_id = 1, path = 'http://localhost:6543/static/10.jpg')
photo3 = Photo(user_id = 2, path = 'http://localhost:6543/static/11.jpg')
fr = Friendrequest(user_from_id = 1, user_to_id = 3)
fs1 = Friendship(user_from_id = 1, user_to_id = 2, dialogLocPath = 'socialnetwork/static/2-1.txt',dialogPath ='http://localhost:6543/static/2-1.txt')
fs2 = Friendship(user_from_id = 2, user_to_id = 3, dialogLocPath = 'socialnetwork/static/2-3.txt',dialogPath ='http://localhost:6543/static/2-3.txt')
DBSession.add_all([user1,user2,user3,photo1,photo2,photo3,fr,fs1,fs2])
#print(DBSession.query(User).all())