當前位置: 首頁>>代碼示例>>Python>>正文


Python model.DBSession類代碼示例

本文整理匯總了Python中model.DBSession的典型用法代碼示例。如果您正苦於以下問題:Python DBSession類的具體用法?Python DBSession怎麽用?Python DBSession使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DBSession類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的model.DBSession類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。