本文整理汇总了Python中app.model.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user
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)
示例2: gridInsert
def gridInsert(self, modelObjects,row):
rack = modelObjects[Rack]
dbRack = None
vial = modelObjects[Vial]
if rack.rack_barcode:
dbRack = Rack.byBarcode(rack.rack_barcode)
if dbRack is None:
dbRack = Rack()
dbRack.rack_barcode = rack.rack_barcode
if vial.well:
dbRack.rack_type_id = vial.well.rack_type_id
DBSession().add(dbRack)
DBSession().flush()
mol=modelObjects[Mol]
mol=mergeMol(mol)
lot=modelObjects[Lot]
if lot.lot_id is None:
mol.addLot(lot, 0)
else:
lot=DBSession().merge(lot)
lot.vials.append(vial)
if dbRack:
vial.vial_rack_id = dbRack.rack_id
vial.vial_lot_aliquot_no = len(lot.vials)
if lot.lot_submitter_id == None:
lot.lot_submitter_id = request.identity['user'].user_id
if hasattr(mol,'mol_reg_id') and not row.has_key('verify'):
if mol.mol_reg_id is None:
mol.setAltId(row['prefix'])
DBSession().flush()
return mol, lot, vial, dbRack
示例3: gridData
def gridData(self):
columns=self.rptCfg.uicolumns
idName=self.rptCfg.getId()
results = []
reqs = DBSession().query(Request).select_from(outerjoin(Request,RequestItem))
childrenDisp = []
dispense = reqs.filter(RequestItem.request_item_dispense_date == None).order_by(Request.request_id).all()
for row in dispense:
# if row.hasOpenItems() or len(row.items)==0:
rowData = []
for col in columns:
val = getattr(row,col.id,None)
if isinstance(val,datetime):
val = val.strftime('%m/%d/%Y')
rowData.append(val)
childrenDisp.append({'id':row.__dict__[idName], 'data':rowData})
childrenComplete = []
complete = reqs.filter(RequestItem.request_item_dispense_date > (datetime.now()-timedelta(days=1))).order_by(Request.request_id).all()
for row in complete:
if not row.hasOpenItems():
rowData = []
for col in columns:
val = getattr(row,col.id,None)
if isinstance(val,datetime):
val = val.strftime('%m/%d/%Y')
rowData.append(val)
childrenComplete.append({'id':row.__dict__[idName], 'data':rowData})
results.append(dict(id='open',data=['Open Requests'],children=childrenDisp))
results.append(dict(id='closed',data=['Recently Closed'],children=childrenComplete))
results.append(dict(id='search',data=['Search']))
return results
示例4: testReagentRegistration
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')
示例5: testClone
def testClone(self):
r=DBSession().query(Rxn).first()
ok_(r)
newr=r.clone()
ok_(newr)
DBSession().add(newr)
transaction.commit()
示例6: setAltId
def setAltId(self,value):
try:
regConfig = DBSession().query(MolRegConfig).get(value)
self.mol_reg_id = regConfig.getRegId()
except Exception,e:
log.exception(e)
raise Exception("Configure your registry id prefix first using the 'Configure' link.")
示例7: clear
def clear(self,parentId):
retVal={}
try:
parent = DBSession().query(ReagentLotLocation).get(parentId)
parent.lots=[]
except Exception,e:
log.exception(e)
retVal={'error':'Parent not found'}
示例8: gridUpdate
def gridUpdate(self, modelObjects,row):
rpt=Report(self.rptCfg)
pkCol=rpt._rptCfg._columns[rpt.getIdName()]
modelClass=pkCol.modelClass
id=getattr(modelObjects[modelClass], rpt.getIdName())
fileRow=DBSession().query(FileRow).get(id)
fileRow.pickle(rpt.convertToUI(*modelObjects.values()))
return None
示例9: checkOutLot
def checkOutLot(self,barcode,userId,pbarId=None):
retVal = {}
try:
lot = DBSession().query(ReagentLot).filter(ReagentLot.lot_barcode==barcode.strip()).one() #@UndefinedVariable : lot_barcode comes from SQLAlchemy reflection
lot.lot_current_user_id = int(userId)
retVal = {'success': "Successfully checked out " + lot.lot_barcode}
except Exception,e:
log.debug(e)
retVal = {'error': 'barcode ' + barcode + ' not found in inventory'}
示例10: sendMessageToUser
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: disposeLot
def disposeLot(self,barcode,userId,pbarId=None):
retVal = {}
try:
lot = DBSession().query(ReagentLot).filter(ReagentLot.lot_barcode==barcode.strip()).one() #@UndefinedVariable : lot_barcode comes from SQLAlchemy reflection
lot.lot_is_disposed = 'Y'
lot.lot_current_user_id = None
retVal = {'success': 'Marked as disposed ' + lot.lot_barcode}
except Exception,e:
log.debug(e)
retVal = {'error': 'barcode ' + barcode + ' not found in inventory'}
示例12: link
def link(self,parentId,childBarcode):
retVal={'success': 'Successfully linked reagent'}
try:
child = DBSession().query(ReagentLot).filter(ReagentLot.lot_barcode==childBarcode).one()
child.loc = DBSession().query(ReagentLotLocation).get(parentId)
child.aud_modified_date = datetime.datetime.now()
child.lot_current_user_id = None
except Exception,e:
log.exception(e)
retVal={'error':"Could not find barcode " + childBarcode}
示例13: gridDelete
def gridDelete(self,modelObjects):
req = DBSession().query(Request).get(modelObjects[Request].request_id)
if len(req.items) == 0:
DBSession().delete(req)
elif req.hasOpenItems() and not req.hasClosedItems():
for i in req.items:
DBSession().delete(i)
DBSession().delete(req)
else:
raise ClientException("Can't delete a request with completed items")
示例14: gridUpdate
def gridUpdate(self, modelObjects,row):
request = modelObjects[Request]
requestItem = modelObjects[RequestItem]
mol = modelObjects[Mol]
mols = DBSession().query(Mol).filter(Mol.mol_reg_id==mol.mol_reg_id).all()
if len(mols)==0:
raise ClientException(mol.mol_reg_id + " was not found in the database")
mol = mols[0]
item = DBSession().merge(requestItem)
item.mol = mol
return mol,item,request
示例15: setUp
def setUp(self):
'''
Need a row of data in the login audit table
'''
super(TestUserAdministration, self).setUp()
aud = AuditLogin(dict(REMOTE_ADDR='127.0.0.1'), dict(user_name='chemadmin'))
result = AuditLoginResult.get('LOGIN_SUCCESS')
aud.login_result = result
log.debug(aud in DBSession())
DBSession.add(aud)
transaction.commit()