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


Python DBSession.add方法代碼示例

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


在下文中一共展示了DBSession.add方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_entry

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
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,代碼行數:10,代碼來源:daemon.py

示例2: flush

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
 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,代碼行數:12,代碼來源:orcl.py

示例3: set_password

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
 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,代碼行數:12,代碼來源:user.py

示例4: new

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
    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,代碼行數:15,代碼來源:user.py

示例5: new

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
    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,代碼行數:16,代碼來源:user.py

示例6: add_article

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
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,代碼行數:20,代碼來源:views.py

示例7: main

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
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,代碼行數:21,代碼來源:__init__.py

示例8: getFlushoftable

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
    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,代碼行數:23,代碼來源:flushtables.py

示例9: crawling

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
def crawling(company_short_name):
    param = {'first': 'false', 'pn': 0, 'kd': ''}
    param = {'first': 'false', 'pn': page, 'sortField': 0, 'havemark': 0}
    log = "[{}]\t抓取第 {} 頁完畢, 當前頁職位個數{}, 累計已抓{}, 該公司總計{}"
    count = 0
    for i in range(max_iter):
        param['pn'] += 1
        req = requests.post(job_url, data=param)
        info = json.loads(req.content)
        total_count = int(info['content']['positionResult']['totalCount'])
        job_list = info['content']['positionResult']['result']
        count += len(job_list)
        print log.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), param['pn'],
                         len(job_list), count, total_count)
        session = DBSession()
        for job in job_list:
            c = Job(
                    company_id=company.get("companyId"),
                    company_full_name=company.get("companyFullName"),
                    company_short_name=company.get("companyShortName"),
                    city=company.get("city"),
                    position_num=company.get("positionNum"),
                    city_score=company.get("cityScore"),
                    finance_stage=company.get("financeStage"),
                    industry_field=company.get("industryField"),
                    country_score=company.get("countryScore"),
                    company_features=company.get("companyFeatures"),
                    process_rate=company.get("processRate"),
                    interview_remark_num=company.get("interviewRemarkNum"),
                    approve=company.get("approve"),
                    create_time=datetime.now()
            )
            session.add(c)
        session.commit()
        session.close()
        time.sleep(3)
        if len(job_list) == 0: break
    return count
開發者ID:hit-suit,項目名稱:MNIST,代碼行數:40,代碼來源:job.py

示例10: refresh_key

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
 def refresh_key(self):
     session = DBSession()
     self.key = random_str(32)
     self.key_time = int(time.time())
     session.add(self)
     session.commit()
開發者ID:fy0,項目名稱:fpage,代碼行數:8,代碼來源:user.py

示例11: DetailforEachOid

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
    def DetailforEachOid(self, name, message):
        
        # Oid = 1.1
        if name == 'insert':
            
            ''' Step 1. All information about input detail '''
            tmpProjectName = ""
            tmpProjectFunc = ""
            tmpKernel = ""
            tmpCpuCoreNum = ""
            tmpSerialNum = ""
            tmpZCBM = ""
            tmpMemory = ""
            tmpCpuType = ""
            tmpModel = ""
            tmpHostName = ""
            tmpOS = ""
            tmpManufacturer = ""
            tmpEthInfo = {}
            tmpTimestamp = int(round(time.time()))
            Resultofbody = {}
            
            for key,value in message.items():
                if key == 'Status':
                    if value != 'Success':
                        return dict(Status='False', msg='Message check Failed.')
            
            if type(message['Result']).__name__ == 'str':
                Resultofbody = changeDict().strtodict(message['Result'])
            else:
                Resultofbody = message['Result']
 
            for keys,values in Resultofbody.items():
                if keys == 'Project':
                    for K,V in Resultofbody[keys].items():
                        if K == 'Name':
                            tmpProjectName = self.changestr(V)
                        elif K == 'Func':
                            tmpProjectFunc = self.changestr(V)
                    
                elif keys == 'HwInfo':
                    for KK,VV in Resultofbody[keys].items():
                        if KK == 'Kernel':
                            tmpKernel = self.changestr(VV)
                        elif KK == 'CpuCoreNum':
                            tmpCpuCoreNum = self.changestr(VV)
                        elif KK == 'SN':
                            tmpSerialNum = self.changestr(VV)
                        elif KK == 'ZCBM':
                            tmpZCBM = self.changestr(VV)
                        elif KK == 'Memory':
                            tmpMemory = self.changestr(VV)
                        elif KK == 'CpuType':
                            tmpCpuType = self.changestr(VV)
                        elif KK == 'Model':
                            tmpModel = self.changestr(VV)
                        elif KK == 'HostName':
                            tmpHostName = self.changestr(VV)
                        elif KK == 'OS':
                            tmpOS = self.changestr(VV)
                        elif KK == 'Manufacturer':
                            tmpManufacturer = self.changestr(VV)
                            
                    
                elif keys == 'EthInfo':
                    
                    for eachline in Resultofbody[keys]:
                        tmpStatus = ''
                        tmpip = ''
                        tmpmask = ''
                        tmpethname = ''
                        for KKK, VVV in eachline.items():
                            if KKK == 'status':
                                tmpStatus = self.changestr(VVV)
                            elif KKK == 'ip':
                                tmpip = self.changestr(VVV)
                            elif KKK == 'mask':
                                tmpmask = self.changestr(VVV)
                            elif KKK == 'ethname':
                                tmpethname = self.changestr(VVV)
                                
                        tmpEthInfo[tmpethname] = dict(status=tmpStatus, ip=tmpip, mask=tmpmask)

            if tmpZCBM == '':
                return dict(Status='False', msg='Input Server has not ZCBM.')

            ''' get eth detail '''
            tmpEthDict = {}
            for key,value in tmpEthInfo.items():
                if key == 'eth0':
                    getSearchofeth = DBSession.query(Ethdetail).filter(Ethdetail.ip == value['ip'], Ethdetail.mask == value['mask']).first()
                    if getSearchofeth:
                        tmpEthDict['eth0'] = getSearchofeth.eid
                    else:
                        getethcount = DBSession.query(Ethdetail).count()
                        getethcount = (getethcount + 1)
                        DBSession.add(Ethdetail(getethcount,value['status'],value['ip'],value['mask'],'eth0'))
                        tmpEthDict['eth0'] = getethcount
                elif key == 'eth1':
                    getSearchofethone = DBSession.query(Ethdetail).filter(Ethdetail.ip == value['ip'], Ethdetail.mask == value['mask']).first()
#.........這裏部分代碼省略.........
開發者ID:qbaoma,項目名稱:web,代碼行數:103,代碼來源:oidDetail.py

示例12: initdata

# 需要導入模塊: from model import DBSession [as 別名]
# 或者: from model.DBSession import add [as 別名]
def initdata():
 
    # Packtype insert 
    getLength = initcheck(Packtype)
    if int(getLength) == 0:
        DBSession.add(Packtype(0,0,1,1,0))
        DBSession.add(Packtype(1,1,0,1,0))
        DBSession.add(Packtype(2,2,1,1,1))
        DBSession.add(Packtype(3,3,0,1,1))
        DBSession.add(Packtype(4,4,1,0,0))
        DBSession.add(Packtype(5,5,0,0,0))
        DBSession.add(Packtype(6,6,1,0,1))
        DBSession.add(Packtype(7,7,0,0,1))
    
    # CommandType insert
    getCommandLength = initcheck(CommandType)
    if int(getCommandLength) == 0:
        DBSession.add(CommandType(0,'10001','ClientHeartBeatCmd'))
        DBSession.add(CommandType(1,'10002','ServerHeartBeatCmd'))
        DBSession.add(CommandType(2,'11000','ClientLoginCmd'))
        DBSession.add(CommandType(3,'11001','ServerLoginCmd'))
        DBSession.add(CommandType(4,'11100','ClientAllServerInformationCmd'))
        DBSession.add(CommandType(5,'11101','ServerAllServerInformationCmd'))
        DBSession.add(CommandType(10,'11300','ClientNumberofCurves'))
        DBSession.add(CommandType(11,'11301','ServerNumberofCurves'))
        DBSession.add(CommandType(12,'11400','ClientNumberofCurvesPeople'))
        DBSession.add(CommandType(13,'11401','ServerNumberofCurvesPeople'))
        DBSession.add(CommandType(14,'11500','ClientVerifyKeyRequest'))
        DBSession.add(CommandType(15,'11501','ServerVerifyKeyRequest'))
        DBSession.add(CommandType(16,'11600','ClientHistoryofCurvesPeople'))
        DBSession.add(CommandType(17,'11601','ServerHistoryofCurvesPeople'))
        DBSession.add(CommandType(100,'19000','ClientADUserLoginCmd'))
        DBSession.add(CommandType(101,'19001','ServerADUserLoginCmd'))
        DBSession.add(CommandType(110,'19500','ClientCompanySMSCmd'))
        DBSession.add(CommandType(111,'19501','ServerCompanySMSCmd'))
        DBSession.add(CommandType(120,'19800','ClientAutoOCinform'))
        DBSession.add(CommandType(121,'19801','ServerAutoOCinform'))
        DBSession.add(CommandType(150,'20000','PassEvent'))
        DBSession.add(CommandType(151,'20001','PassEventReturn'))
        DBSession.add(CommandType(180,'21000','AlarmUnifity'))
        DBSession.add(CommandType(181,'21001','AlarmUnifityReturn'))
        DBSession.add(CommandType(182,'21100','TestAlarmUnifity'))
        DBSession.add(CommandType(183,'21101','TestAlarmUnifityReturn'))
        DBSession.add(CommandType(190,'30000','CaptureEvent'))
        DBSession.add(CommandType(191,'30001','CaptureEventReturn'))
        DBSession.add(CommandType(200,'31000','EventReceive'))
        DBSession.add(CommandType(201,'31001','EventReturn'))
        DBSession.add(CommandType(202,'31100','TestEventReceive'))
        DBSession.add(CommandType(203,'31101','TestEventReturn'))
        
        
        
    getCommandRelation = initcheck(CommandTypeRelation)
    if int(getCommandRelation) == 0:
        DBSession.add(CommandTypeRelation(0,1,0))
        DBSession.add(CommandTypeRelation(2,101,100))
        DBSession.add(CommandTypeRelation(1,3,2))
        DBSession.add(CommandTypeRelation(3,5,4))
        DBSession.add(CommandTypeRelation(4,11,10))
        DBSession.add(CommandTypeRelation(5,13,12))
        DBSession.add(CommandTypeRelation(6,15,14))
        DBSession.add(CommandTypeRelation(7,17,16))
        DBSession.add(CommandTypeRelation(10,121,120))
        DBSession.add(CommandTypeRelation(11,151,150))
        DBSession.add(CommandTypeRelation(12,111,110))
        DBSession.add(CommandTypeRelation(13,181,180))
        DBSession.add(CommandTypeRelation(14,183,182))
        DBSession.add(CommandTypeRelation(15,201,200))
        DBSession.add(CommandTypeRelation(16,203,202))
        DBSession.add(CommandTypeRelation(17,191,190))
    
    # Validate
    getValidateLength = initcheck(Validate)
    if int(getValidateLength) == 0:
        DBSession.add(Validate(0,'crc32'))
        DBSession.add(Validate(1,'md5'))
     
    # Encrypt    
    getEncryptLength = initcheck(Encrypt)
    if int(getEncryptLength) == 0:
        DBSession.add(Encrypt(0,0,'make encrypt with data'))
        DBSession.add(Encrypt(1,1,'make encrypt without data'))
    
    # Compress
    getCompressLength = initcheck(Compress)
    if int(getCompressLength) == 0:
        DBSession.add(Compress(0,0,'make Zlib with data'))
        DBSession.add(Compress(1,1,'make Zlib without data'))
    
    # Translate    
    getTranslate = initcheck(Translate)
    if int(getTranslate) == 0:
        DBSession.add(Translate(0,'ZR','真如'))
        DBSession.add(Translate(1,'NJ','南京'))
        DBSession.add(Translate(2,'TJ','天津'))
        DBSession.add(Translate(3,'WH','武漢'))
        DBSession.add(Translate(4,'BJ','北京'))
        DBSession.add(Translate(5,'LG','龍崗'))
        DBSession.add(Translate(100,'Agent','服務器'))
        DBSession.add(Translate(101,'Server','服務器'))
#.........這裏部分代碼省略.........
開發者ID:qbaoma,項目名稱:web,代碼行數:103,代碼來源:initData.py


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