本文整理汇总了Python中app.model.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.model.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReagentRegistration
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def testReagentRegistration(self):
"""Authenticated users can register reagents"""
numBeforeDbLots = len(DBSession.query(ReagentLot).all())
self.doRegistration('reagents', 'app/tests/data/molregtest.sdf')
self.checkGridPostReg('reagents')
numAfterDbLots = len(DBSession.query(ReagentLot).all())
ok_(numAfterDbLots == numBeforeDbLots + 2, 'Failed to register 2 new lots')
示例2: testReagentMolStereoReg
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def testReagentMolStereoReg(self):
"""Different stereoisomers can be registered as individual molecules"""
numBeforeDbMols = len(DBSession.query(ReagentMol).all())
self.doRegistration('reagents', 'app/tests/data/stereo_test.sdf')
self.checkGridPostReg('reagents')
numAfterDbMols = len(DBSession.query(ReagentMol).all())
# We register 11 molecules, but only 10 distinct lots. One of the molecules is present twice
# in the sd file. That molecule is drawn as enantiomers but without the chiral flag set, so that
# the molecules are treated as being relative stereochemistry and consequently the same.
# So: We should only see 10 new lots here.
log.debug('num after db mols is ' + str(numAfterDbMols))
ok_(numAfterDbMols == numBeforeDbMols + 10, 'Failed to register 10 new stereo mols')
示例3: test_concat
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def test_concat(self):
user = DBSession.query(User).filter(User.id == "d09b9111-70a0-43c0-9373-aba10f2af592").all()[0]
# balanceQuery = DBSession.query(func.sum(Transaction.amount).label("balance")).with_parent(user).\
# filter(Transaction.date > datetime.utcnow())
tags = DBSession.query(Tag).with_parent(user).filter(Tag.type == Tag.TYPE_INCOME)
balances = []
# for tag in tags:
balance = DBSession.query(Transaction.id, func.sum(Transaction.amount).label("balance")).with_parent(user)
balances = DBSession.query(Tag.name, balance.c.balance). \
filter(Transaction.incomeTagGroup.has(TagGroup.tags.any(Tag.id == balance)))
balances.append(balances)
print(balances)
示例4: getContacts
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def getContacts():
users = DBSession.query(User).all()
retVal = [dict(id=_InnectusUser.user_id,value=_InnectusUser.user_name)]
for user in users:
retVal.append(dict(id=user.user_id,value=user.user_name))
return retVal
示例5: test_user
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def test_user(self):
db = DBSession()
user = db.query(User) \
.filter(User.password == User.encryptPassword('root'), User.email == r'[email protected]') \
.one()
self.assertIsNotNone(user)
示例6: gridUpdate
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def gridUpdate(self, modelObjects, row):
o=modelObjects[Group]
dbgroup = DBSession.query(Group).get(int(o.group_id))
if dbgroup.group_name =='admin':
raise ClientException("You can't change the " + dbgroup.group_name + " group's information.")
d=DBSession().merge(o)
return d,
示例7: loadFeedDict
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def loadFeedDict(cls, feeds):
for feed in feeds:
guid = feed["id"]
try:
message = DBSession.query(Message).filter(Message.guid == guid).one()
if _compareTime(message.updated.timetuple(),feed["updated_parsed"]) < 0:
message.update(title=feed["title"],
link=feed["link"],
updated=feed["updated"],
text=feed["summary"])
userMessages = DBSession.query(UserMessage).filter(UserMessage.message == message.message_id).all()
for userMessage in userMessages:
userMessage.new = True
except NoResultFound:
message = Message(text=feed["summary"], guid=feed["id"], **feed)
DBSession.add(message)
DBSession.flush()
cls.sendMessageToAllUsers(message)
示例8: test_deref
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def test_deref(self):
trans = DBSession.query(Transaction).options(
subqueryload(Transaction.incomeTagGroup).subqueryload(TagGroup.tags),
subqueryload(Transaction.expenseTagGroup).subqueryload(TagGroup.tags)
).options(defer('_user_id'))
tran = trans.first()
print(tran)
print(json.dumps({'fsd': tran.incomeTagGroup.tags[0]}))
示例9: getUserMessagesById
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def getUserMessagesById(cls, userId, newOnly = False):
messages = []
userMessages = DBSession.query(UserMessage).filter(UserMessage.user == userId)
if newOnly:
userMessages = userMessages.filter(UserMessage._new == 1)
userMessages = userMessages.all()
for userMessage in userMessages:
messages.append(userMessage.toDict())
return messages
示例10: sendMessageToUser
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def sendMessageToUser(cls, message, userId):
if str(userId) == "#":
user = _InnectusUser
_sendMessageViaMail(message, user)
else:
user = DBSession.query(User).filter(User.user_id == userId).one()
#_sendMessageViaMail(message, user)
userMessage = cls(user, message)
DBSession.add(userMessage)
示例11: _setMol
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def _setMol(self,molId,mol,smiles,chirality='A'):
molDb=DBSession.query(self.ModelClass).get(int(molId))
try:
molDb.mol_struct = mol.encode('utf-8')
molDb.chirality=chirality
transaction.commit()
except IntegrityError,e:
transaction.abort()
log.exception(e)
raise Exception("Unique field has been violated")
示例12: test_some
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def test_some(self):
# fields = exclude_fields(Transaction, [Transaction.user, Transaction._user_id, Transaction.expenseTagGroup_id, Transaction.incomeTagGroup_id, Transaction.expenseTagGroup, Transaction.incomeTagGroup])
transactions = DBSession.query(Transaction).options(
subqueryload(Transaction.incomeTagGroup).subqueryload(TagGroup.tags),
subqueryload(Transaction.expenseTagGroup).subqueryload(TagGroup.tags)
).all()
transaction_json = jsonify.encode(dict(transactions=transactions))
parsed = json.loads(transaction_json)
print(json.dumps(parsed, indent=2, sort_keys=True), len(transactions))
示例13: toDict
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def toDict(self):
mainMessage = DBSession.query(Message).filter(Message.message_id == self.message).one()
author = mainMessage.author
return dict(isNew=self.new,
id=self.id,
title=mainMessage.title,
text=mainMessage.text,
link=mainMessage.link,
updated=mainMessage.updated,
priority=mainMessage.priority,
author=dict(display_name=author.display_name,
email_address=author.email_address,
user_id=author.user_id))
示例14: test_tag
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def test_tag(self):
db = DBSession()
res = db.query(func.sum(Transaction.amount).label("balance"))
print(res.one().balance)
print(res.filter(Transaction.amount < 0).one().balance)
print(res.filter(Transaction.amount > 0).one().balance)
res = db.query(Transaction) \
.filter(Transaction.expenseTagGroup.has(TagGroup.tags.any(Tag.name.in_(["traveling", "grocery"])))) \
.filter(Transaction.incomeTagGroup.has(TagGroup.tags.any(Tag.name.in_(["cash"]))))
print("\n\nAll transactions with expense tags [traveling or grocery] and income tag [cash]\n")
for r in res.all():
print(r)
print("\n\nAll expenses per tag\n")
for tag in db.query(Tag).filter(Tag.type == Tag.TYPE_EXPENSE):
print(tag.name)
for transactions in [group.expenses.all() for group in tag.groups]:
for transaction in transactions:
print(transaction)
示例15: setUp
# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def setUp(self):
super(TestStructureSearch,self).setUp()
org=DBSession.query(ReagentVendor).first()
for name, smiles in self.smilesToReg.items():
mol = ReagentMol(toMolFromSmiles(smiles))
mol.mol_name = name
submitter = User.by_user_name('chemadmin')
lot = ReagentLot()
lot.lot_submitter_id = submitter.user_id
lot.lot_source_org_id = org.vendor_id
mol.addLot(lot, 0)
DBSession.add(mol)
DBSession.flush()