本文整理汇总了Python中model.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_by_key
def get_by_key(cls, key):
session = DBSession()
if py_ver == 2:
the_key = (key or b'').encode('utf-8')
else:
the_key = str(key or b'', 'utf-8')
return session.query(cls).filter(cls.key==the_key).first()
开发者ID:fy0,项目名称:fpage,代码行数:7,代码来源:user.py
示例2: init_db
def init_db(path='eta.db'):
"""Initialze database
"""
engine = create_engine("sqlite:///%s" % path)
Base.metadata.create_all(engine)
DBSession.configure(bind=engine)
log.info("Initialized database %s", path)
开发者ID:quodt,项目名称:etaui,代码行数:7,代码来源:daemon.py
示例3: FlushofGamelist
def FlushofGamelist(self):
''' No.1 clear table of gamelist '''
localgamelist = DBSession.query(GameList).all()
if len(localgamelist) != 0:
for eachlist in range(len(localgamelist)):
DBSession.delete(localgamelist[eachlist])
DBSession.commit()
''' No.2 analyst Config and create conn '''
self.getConfig = readFromConfigFile().get_config_zonelist('/WebserviceInterface/ServiceConfig/setting.ini')
for eachTuple in range(len(self.getConfig['Zonelist'])):
if self.getConfig['Zonelist'][eachTuple][0] == 'username':
self.change['username'] = self.getConfig['Zonelist'][eachTuple][1]
elif self.getConfig['Zonelist'][eachTuple][0] == 'password':
self.change['password'] = self.getConfig['Zonelist'][eachTuple][1]
elif self.getConfig['Zonelist'][eachTuple][0] == 'ipaddress':
self.change['ipaddress'] = self.getConfig['Zonelist'][eachTuple][1]
elif self.getConfig['Zonelist'][eachTuple][0] == 'port':
self.change['port'] = int(self.getConfig['Zonelist'][eachTuple][1])
elif self.getConfig['Zonelist'][eachTuple][0] == 'dbname':
self.change['dbname'] = self.getConfig['Zonelist'][eachTuple][1]
elif self.getConfig['Zonelist'][eachTuple][0] == 'tablename':
self.change['tablename'] = self.getConfig['Zonelist'][eachTuple][1]
(conn, cursor) = Connect().create(self.change)
sql = 'select * from %s' % self.change['tablename']
cursor.execute(sql)
result=cursor.fetchall()
for i in result:
print i
开发者ID:qbaoma,项目名称:web,代码行数:35,代码来源:flushtables.py
示例4: create_entry
def create_entry(data):
"""Write data to database
"""
data = map_data(data)
entry = Entry(date=datetime.now(), **data)
DBSession.add(entry)
DBSession.commit()
log.debug("Write entry %r", data)
开发者ID:quodt,项目名称:etaui,代码行数:8,代码来源:daemon.py
示例5: auth
def auth(cls, username, password):
session = DBSession()
u = session.query(cls).filter(cls.username==username).first()
if not u:
return False
password_md5 = md5(password.encode('utf-8')).hexdigest()
password_final = md5((password_md5 + u.salt).encode('utf-8')).hexdigest()
if u.password == password_final:
return u
开发者ID:wuchangqi,项目名称:fpage,代码行数:10,代码来源:user.py
示例6: set_password
def set_password(self, new_password):
salt = random_str()
password_md5 = md5(new_password.encode('utf-8')).hexdigest()
password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()
session = DBSession()
self.salt = salt
self.password = password_final
session.add(self)
session.commit()
开发者ID:521xueweihan,项目名称:fpage,代码行数:10,代码来源:user.py
示例7: flush
def flush(self, oracleCursor):
# execute in oracle VIEW
oracleCursor.execute('select * from MEP_ASSETREPORT')
self.all = self.cursor.fetchall()
for eachline in range(len(self.all)):
DBSession.add(ASSET(eachline, self.all[eachline][1], self.all[eachline][2], self.all[eachline][3], self.all[eachline][4], self.all[eachline][5], self.all[eachline][6], self.all[eachline][7], self.all[eachline][8], self.all[eachline][9], self.all[eachline][10], self.all[eachline][11], self.all[eachline][13], self.all[eachline][14], self.all[eachline][15], self.all[eachline][17], self.all[eachline][22]))
DBSession.commit()
开发者ID:qbaoma,项目名称:web,代码行数:10,代码来源:orcl.py
示例8: new
def new(cls, username, password):
salt = random_str()
password_md5 = md5(password.encode('utf-8')).hexdigest()
password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()
level = USER_LEVEL.ADMIN if cls.count() == 0 else USER_LEVEL.NORMAL # 首个用户赋予admin权限
the_time = int(time.time())
session = DBSession()
ret = cls(username=username, password=password_final, salt=salt, level=level, key=random_str(32),
key_time = the_time, reg_time = the_time)
session.add(ret)
session.commit()
return ret
开发者ID:521xueweihan,项目名称:fpage,代码行数:13,代码来源:user.py
示例9: new
def new(cls, username, password):
username = username.lower()
salt = random_str()
password_md5 = md5(password.encode('utf-8')).hexdigest()
password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()
state = USER_STATE.ADMIN if cls.count() == 0 else USER_STATE.NORMAL # first user is admin
the_time = int(time.time())
session = DBSession()
ret = cls(username=username, password=password_final, salt=salt, state=state, key=random_str(32),
key_time = the_time, reg_time = the_time)
session.add(ret)
session.commit()
return ret
开发者ID:fy0,项目名称:fpage,代码行数:14,代码来源:user.py
示例10: Recovery
def Recovery(self):
localAsset = DBSession.query(ASSET).all()
if len(localAsset) > 100:
for eachAsset in range(len(localAsset)):
DBSession.delete(localAsset[eachAsset])
DBSession.commit()
self.flush(self.cursor)
else:
self.flush(self.cursor)
self.cursor.close()
self.OracleConn.close()
开发者ID:qbaoma,项目名称:web,代码行数:15,代码来源:orcl.py
示例11: add_article
def add_article(request):
if 'form.submitted' in request.POST:
with transaction.manager:
article = Article(
title=request.POST['title'],
body=request.POST['body']
)
DBSession.add(article)
return HTTPFound(
location=route_url('article_list', request)
)
else:
return render_to_response(
'templates/add_article.pt',
{'back_url': route_url('article_list', request)},
request=request
)
开发者ID:bosim,项目名称:pyramid-talk,代码行数:18,代码来源:views.py
示例12: searchObject
def searchObject(self, machineroom, requestobject):
try:
allsearch = DBSession.query(ASSET).filter(and_(ASSET.partNum.like("%"+requestobject+"%"), ASSET.machineRoom.like("%"+machineroom+"%"), ASSET.useNow == 'Y')).all()
for eachAsset in range(len(allsearch)):
self.assetBack[allsearch[eachAsset].id] = dict(confNum=allsearch[eachAsset].confNum, serialNum=allsearch[eachAsset].serialNum, hostname=allsearch[eachAsset].hostname, companyIp=allsearch[eachAsset].companyIp, outIp=allsearch[eachAsset].outIp, storeIp=allsearch[eachAsset].storeIp, zcbm=allsearch[eachAsset].zcbm)
except Exception, e:
return dict(Status='false', Return=e)
开发者ID:qbaoma,项目名称:web,代码行数:10,代码来源:localAsset.py
示例13: getDatabase
def getDatabase(self):
searchLocal = DBSession.query(ASSET).all()
if len(searchLocal) > 100:
print "local table.asset has data. needn't."
else:
self.flush(self.cursor)
self.cursor.close()
self.OracleConn.close()
开发者ID:qbaoma,项目名称:web,代码行数:10,代码来源:orcl.py
示例14: main
def main(global_config, **settings):
config = Configurator(settings=settings)
config.add_route('article_list', '/')
config.add_route('show_article', '/article/{article}')
config.add_route('add_article', '/add_article')
config.scan()
# SQL Alchemy stuff.
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
try:
Base.metadata.create_all(engine)
with transaction.manager:
article = Article(title='Test article', body="Test test test")
DBSession.add(article)
except IntegrityError:
print "Skipping creating, integrity error was thrown"
return config.make_wsgi_app()
开发者ID:bosim,项目名称:pyramid-talk,代码行数:19,代码来源:__init__.py
示例15: analyNode
def analyNode(self, AgentZone):
try:
getNodeInform = DBSession.query(NodeList).filter_by(NodeZone = AgentZone).all()
if getNodeInform:
for eachNodeInform in range(len(getNodeInform)):
self.Nodeinform[getNodeInform[eachNodeInform].NodeID]=dict(NodeType=getNodeInform[eachNodeInform].NodeType, NodeZone=getNodeInform[eachNodeInform].NodeZone, NodeName=getNodeInform[eachNodeInform].NodeName, IP=getNodeInform[eachNodeInform].IP, Port=getNodeInform[eachNodeInform].Port)
else:
msg = 'MySQLdb : select from table.nodelist error.'
return msg
except Exception, e:
return e
开发者ID:qbaoma,项目名称:web,代码行数:13,代码来源:getNode.py
示例16: flushAgent
def flushAgent(self, machineroomSimple, Agent='Agent'):
try:
getSearchAgent = DBSession.query(Translate).filter_by(simple = Agent).first()
AgentSimple = getSearchAgent.detail
getSearchMachineroom = DBSession.query(Translate).filter_by(simple = machineroomSimple).first()
MrDetail = getSearchMachineroom.detail
getAgentList = AssetInformation().searchObject(MrDetail, AgentSimple)
print "######## LEN ", len(getAgentList['Return'])
for key,value in getAgentList['Return'].items():
AgentID = key
AgentZone = machineroomSimple
AgentName = value['hostname']
IP = self.iprule(key, machineroomSimple, value['companyIp'], value['outIp'], value['storeIp'])
Port = 'NULL'
IsUse = 1
except Exception, e:
return e
开发者ID:qbaoma,项目名称:web,代码行数:24,代码来源:allist.py
示例17: getFlushoftable
def getFlushoftable(self, signal='ALL'):
# No.1 clear table of gamename
localGameName = DBSession.query(Gameinform).all()
if len(localGameName) != 0:
for eachGamename in range(len(localGameName)):
DBSession.delete(localGameName[eachGamename])
DBSession.commit()
# No.2 get each Game information & fill in table
self.flush = Urlex().getInformationMultiple(signal)
for key,value in self.flush.items():
if key != 'NULL':
DBSession.add(Gameinform(self.count, key, value['ipaddress'], value['port'], value['dbname']))
self.count += 1
DBSession.commit()
开发者ID:qbaoma,项目名称:web,代码行数:21,代码来源:flushtables.py
示例18: show_article
def show_article(context, request):
article = {}
db_result = DBSession.query(Article).filter(
Article.id == context.article
).first()
if not db_result:
raise HTTPNotFound(
"Article could not be found"
)
article['id'] = db_result.id
article['title'] = db_result.title
article['body'] = db_result.body
return {
'article': article,
'back_url': route_url('article_list', request)
}
开发者ID:bosim,项目名称:pyramid-talk,代码行数:19,代码来源:views.py
示例19: article_list
def article_list(request):
results = []
db_results = DBSession.query(Article).all()
for db_result in db_results:
results.append({
'id': db_result.id,
'url': route_url(
'show_article',
request,
article=str(db_result.id)
),
'title': db_result.title
})
return {
'articles': results,
'add_article': route_url('add_article', request)
}
开发者ID:bosim,项目名称:pyramid-talk,代码行数:19,代码来源:views.py
示例20: FromConfNum
def FromConfNum(self, confNum):
Attitude = ""
ServerInform = {}
Internet = {}
Device = {}
try:
self.allLineofConfnum = DBSession.query(ASSET).filter_by(confNum = confNum).first()
print self.allLineofConfnum
if self.allLineofConfnum:
# All information collect
Attitude = self.allLineofConfnum.useNow
Device['confNum'] = self.allLineofConfnum.confNum
Device['partNum'] = self.allLineofConfnum.partNum
Device['serialNum'] = self.allLineofConfnum.serialNum
Device['zcbm'] = self.allLineofConfnum.zcbm
Device['machineRoom'] = self.allLineofConfnum.machineRoom
ServerInform['useProperty'] = self.allLineofConfnum.useProperty
ServerInform['conProject'] = self.allLineofConfnum.conProject
ServerInform['username'] = self.allLineofConfnum.username
ServerInform['userId'] = self.allLineofConfnum.userId
ServerInform['usage'] = self.allLineofConfnum.usage
Internet['hostname'] = self.allLineofConfnum.hostname
Internet['companyIp'] = self.allLineofConfnum.companyIp
Internet['outIp'] = self.allLineofConfnum.outIp
Internet['storeIp'] = self.allLineofConfnum.storeIp
return dict(State=Attitude, Device=Device, ServerInform=ServerInform, Internet=Internet)
else:
msg = 'MySQLdb : could not found any confNum.'
return msg
except Exception, e:
msg = e
return msg
开发者ID:qbaoma,项目名称:web,代码行数:42,代码来源:localAsset.py
注:本文中的model.DBSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论