当前位置: 首页>>代码示例>>Python>>正文


Python Session.add方法代码示例

本文整理汇总了Python中model.Session.add方法的典型用法代码示例。如果您正苦于以下问题:Python Session.add方法的具体用法?Python Session.add怎么用?Python Session.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Session的用法示例。


在下文中一共展示了Session.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_book_save

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def new_book_save():
	status, msg = True, ''

	b_name = request.args.get('name')

	s = Session()
	b = Book(b_name)

	for key, val in request.args.items():
		if key == 'name':
			continue
		a = s.query(Author).filter_by(id=key).first()
		b.authors.append(a)

	s.add(b)

	try:
		s.commit()
	except IntegrityError:
		status = False
		msg = 'The book with name %s already exists' % b_name

	s.close()

	return json.dumps({'ok': status, 'msg': msg})
开发者ID:Azurin,项目名称:beta,代码行数:27,代码来源:controller.py

示例2: syncSeason

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
    def syncSeason(self, serie, season):
        qry = Session.query(Serie).filter_by(path=serie)
        if qry.count() == 0:
            raise Exception("No serie linked to %s/%s" % (serie, saison))
        serie = qry.one()

        path = season
        num = getSeasonNumFromFoldername(season)

        if num is None:
            raise Exception("This is not a season (%s)" % season)

        season = filter(lambda season: season.num == num, serie.seasons)
        if len(season) == 0:
            season = Season(num=num, path=path)
            Session.add(season)
            serie.seasons.append(season)
        else:
            assert 1 == len(season)
            season = season[0]
            season.num = num
            season.path = path

        episodes = glob(os.path.join(self.basepath, serie.path, season.path, "*"))
        episodes = filter(lambda episode: os.path.isfile(episode), episodes)

        for episode in [os.path.basename(e) for e in episodes]:
            try:
                self.syncEpisode(serie.path, season.path, episode)
            except:
                pass
开发者ID:PiTiLeZarD,项目名称:BetaSeries-Scripts,代码行数:33,代码来源:filesystem.py

示例3: initialize_device

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def initialize_device():
    """
    Set up the Device info into the database.
    By this time, the HardwareDefinition and SoftwareDefinition
    entries must be entered.
    """
    session = Session()

    hd = session.query(HardwareDefinition).one()
    sd = session.query(SoftwareDefinition).one()

    device = Device(id=hd.serial_number,
                    interior_sensor=hd.interior_sensor,
                    exterior_sensor=hd.exterior_sensor)

    device.hardware_version = hd.hardware_version
    device.software_version = sd.software_version
    device.database_service = True  # database always set to True
    device.device_service = sd.device_service
    device.grainbin_service = sd.grainbin_service
    session.add(device)

    # set grainbin info
    if sd.grainbin_service:
        grainbins = initialize_grainbin(device.id, hd.grainbin_reader_count)
        device.grainbin_count = len(grainbins)
        session.add_all(grainbins)

    session.commit()
    session.close()
    return
开发者ID:nstoik,项目名称:farm_device,代码行数:33,代码来源:db_manage.py

示例4: make_account

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def make_account(username, password):
    session = Session()
    a = Account(username, password)
    session.add(a)
    bot = MBotData("testerbot", 0, 0, )
    
    session.commit()
开发者ID:shmup,项目名称:another-python-mud,代码行数:9,代码来源:account.py

示例5: create_default_user

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def create_default_user():
    session = Session()
    default_user = User('admin', 'password1234', '[email protected]')
    session.add(default_user)
    session.commit()
    session.close()
    return
开发者ID:nstoik,项目名称:farm_monitor,代码行数:9,代码来源:db_manage.py

示例6: create_statuses

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def create_statuses():
    session = Session()
    existing = set(item.name for item in session.query(Status))
    for status in ["PASS", "FAIL", "OK", "ERROR", "TIMEOUT", "CRASH",
                   "ASSERT", "SKIP", "NOTRUN"]:
        if status not in existing:
            session.add(Status(name=status))
    session.commit()
开发者ID:jgraham,项目名称:wptreport,代码行数:10,代码来源:dbhandler.py

示例7: add_order

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
 def add_order(self):
     s = Session()
     ord = Order()
     ord.manager_id = self.parent.user.id
     ord.device =  unicode(self.ui.device.text())
     ord.description =  unicode(self.ui.description)
     ord.client_id = s.query(Client).filter_by(id=unicode(self.ui.client.itemText(self.ui.client.currentIndex())).split()[0]).one().id
     s.add(ord)
     s.commit()
     s.close()
     self.close()
开发者ID:frolova,项目名称:sc,代码行数:13,代码来源:AddOrderWidget.py

示例8: add_provider

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def add_provider(db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude):

    # if db is enabled, then open a session with the database
    if db_enabled:
        session = Session()

        # create an instance of the Provider type
        provider = Provider(lastname=lastname, firstname=firstname,
                            credentials=credentials, addr1=addr1, addr2=addr2,
                            city=city, zipcode=zipcode,state=state,
                            latitude=latitude, longitude=longitude)


    #To check if the record already exists in database 
    p = select([Provider.firstname]).where(Provider.firstname+Provider.lastname+Provider.credentials
                                           +Provider.addr1+Provider.addr2 == firstname+lastname+credentials+addr1+addr2)

    res = session.execute(p)
    prov_data = res.fetchone()
    session.close()    

    #To check if record exists, then this step will be skipped
    if not(prov_data):
        session = Session()
        # To fetch the Geographical coordinates from Zip_geotable 
        z = select([Zip_geo.latitude, Zip_geo.longitude]).where(Zip_geo.zipcode == zipcode)
        result = session.execute(z)
        geo_data = result.fetchone()

        if geo_data:
            latitude = geo_data.latitude
            longitude= geo_data.longitude
            #print db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude
            
            
            # create an instance of the Provider type
            provider = Provider(lastname=lastname, firstname=firstname,
                                credentials=credentials, addr1=addr1, addr2=addr2,
                                city=city, zipcode=zipcode,state=state,
                                latitude=latitude, longitude=longitude)            
            

            # if db is enabled, then add to the recordset and commit the txn
            session.add(provider)
            session.commit()
            session.close()
                
    return provider
开发者ID:qlikstar,项目名称:Stride,代码行数:50,代码来源:driver.py

示例9: add_zipdata

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def add_zipdata(db_enabled, zipcode, latitude, longitude):
    
    # if db is enabled, then open a session with the database
    if db_enabled:
        session = Session()

    # create an instance of the Zip_Geo type
    zip_geo= Zip_geo(zipcode=zipcode, latitude=latitude, longitude=longitude)

    # if db is enabled, then add to the recordset and commit the txn
    if db_enabled:
        session.add(zip_geo)
        session.commit()
        session.close()
                  
    return zip_geo
开发者ID:qlikstar,项目名称:Stride,代码行数:18,代码来源:driver.py

示例10: syncSerie

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
 def syncSerie(self, serie):
     self._setDetails(serie)
     
     for season_bs in self.details:
         season_num = 'S%s' % str(season_bs['number']).zfill(2)
         
         season = filter(lambda season: season.num == season_num, serie.seasons)
         if len(season) == 0:
             season = Season(num=season_num)
             Session.add(season)
             serie.seasons.append(season)
         else:
             assert(len(season) == 1)
             season = season[0]
             
         self.syncSeason(serie, season)
开发者ID:PiTiLeZarD,项目名称:BetaSeries-Scripts,代码行数:18,代码来源:bs_updater.py

示例11: syncSerie

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
    def syncSerie(self, serie):
        qry = Session.query(Serie).filter_by(path=serie)
        if qry.count() == 0:
            Session.add(Serie(path=serie))
        serie = qry.one()

        if serie.seasons is None:
            serie.seasons = []

        seasons = glob(os.path.join(self.basepath, serie.path, "*"))
        seasons = filter(lambda season: os.path.isdir(season), seasons)

        for season in [os.path.basename(s) for s in seasons]:
            try:
                self.syncSeason(serie.path, season)
            except:
                pass
开发者ID:PiTiLeZarD,项目名称:BetaSeries-Scripts,代码行数:19,代码来源:filesystem.py

示例12: new_author_save

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def new_author_save():
	status, msg = True, ''

	a_name = request.args.get('name')

	s = Session()
	s.add(Author(a_name))

	try:
		s.commit()
	except IntegrityError:
		status = False
		msg = 'The author with name %s already exists' % a_name

	s.close()

	return json.dumps({'ok': status, 'msg': msg})
开发者ID:Azurin,项目名称:beta,代码行数:19,代码来源:controller.py

示例13: PUT

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
    def PUT(self, id):
        data = web.data()
        item = json.loads(data)
        if id == '0':
            id = None
        code = item['code'] if ('code' in item) else 'code'
        title = item['title'] if ('title' in item) else 'title'
        try:
            posttime = datetime.datetime.strptime(item['posttime'], '%Y-%m-%d')
        except (KeyError, ValueError):
            posttime = datetime.datetime.now()
        remark = item['remark'] if ('remark' in item) else ''

        articleobj = ArticleModel(id, code, title, posttime, remark)
        articledict = {'code': code, 'title': title, 'posttime': posttime, 'remark': remark}
        if id:
            Session.query(ArticleModel).filter(ArticleModel.id==id).update(articledict)
        else:
            Session.add(articleobj)
        Session.commit()
开发者ID:gerpayt,项目名称:sendManage,代码行数:22,代码来源:controller.py

示例14: check_realm

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def check_realm(server):
    logging.debug("Checking realm status")
    realmInfo = connection.get_realm(EUROPE, wowconfig["realm"])

    session = Session()
    realm = session.query(Realm).filter(Realm.name == realmInfo.name).first()
    
    if realm is None:
        logging.debug("Never seen realm '{0}', creating new cache entry".format(realmInfo.name))
        realm = Realm(name=realmInfo.name, lastseen=datetime.datetime.now())
        session.add(realm)

    prevonline = realm.online
    prevlastseen = realm.lastseen

    realm.online = realmInfo.status
    realm.lastchecked = datetime.datetime.now()
    if realm.online:
        realm.lastseen = realm.lastchecked
    
    set_pvparea(session, realm, realmInfo.tolbarad)
    set_pvparea(session, realm, realmInfo.wintergrasp)
    
    session.commit()
    
    if (prevonline != realm.online):
        if realm.online:
            send_message(
                server,
                "announcements",
                u"{0} just came online! (offline for {1})".format(
                    realm.name,
                    humanize.naturaldelta(datetime.datetime.now() - prevlastseen)
                )
            )
        else:
            send_message(
                server,
                wowconfig["announcements"]["realm"],
                u"{0} just went offline".realm.name
            )
开发者ID:Michaeljmeyer3,项目名称:slackcraft,代码行数:43,代码来源:process.py

示例15: system_setup_init

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import add [as 别名]
def system_setup_init(status):
    """
    Create a SystemSetup entry in the database.
    Specify if the device is standalone configuration
    (status=True) or alongside a FarmMonitor (status=False)
    """
    session = Session()
    system_setup = SystemSetup()
    if status == 'True':
        system_setup.standalone_configuration = True
    else:
        system_setup.standalone_configuration = False

    session.add(system_setup)
    session.commit()

    initialize_routes(session)

    session.close()

    return
开发者ID:nstoik,项目名称:farm_device,代码行数:23,代码来源:db_manage.py


注:本文中的model.Session.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。