当前位置: 首页>>代码示例>>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;未经允许,请勿转载。