• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python session.commit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.session.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: add_admin

def add_admin(emailormobile):
    user = session.query(User).filter(or_(User.email == emailormobile,User.mobile == emailormobile)).first()
    if not user:
        raise
    admin = Admin(admin_id = ut.create_admin_id(),user_id = user.user_id,created = time.time()*1000,updated = time.time()*1000)
    session.add(admin)
    session.commit()
开发者ID:realjade,项目名称:match,代码行数:7,代码来源:shell.py


示例2: normalize_paths

 def normalize_paths(self):
     if self.normalize:
         queryset = self.photoset.filter(~Photo.base_uri.endswith(os.sep)).all()
         if len(queryset):
             self.create_backup()
             for p in queryset:
                 p.base_uri += os.sep
             session.commit()
             logger.info(_("Normalized path separator on %s photos.") % len(queryset))
         
         if self.db_version >= DB_VERSION_ENCODED:
             total = 0
             # Look for photo without '%' in their path (i.e. not encoded)
             queryset = self.photoset.filter(~Photo.base_uri.like('%\\%%', escape="\\")).all()
             if len(queryset):
                 self.create_backup()
                 for p in queryset:
                     # Compare encoded version of base_uri to actual version
                     # (slice file:// part)
                     base_uri_encoded = urllib.quote(p.base_uri[7:].encode('utf-8'))
                     if base_uri_encoded != p.base_uri[7:]:
                         p.base_uri = p.base_uri[:7] + base_uri_encoded
                         total += 1
                 session.commit()
                 logger.info(_("Normalized path encoding on %s photos.") % total)
         self.normalize = False
开发者ID:leplatrem,项目名称:pyfspot,代码行数:26,代码来源:controller.py


示例3: recieve_message

def recieve_message():
    try:
        message = request.form.get('message')
        json_resp = False
        if not message:
            message = request.get_json()['message']
            json_resp = True

        message_data = Message(message=message)
        session.add(message_data)
        session.commit()

        if json_resp:
            resp = {
                'status': 'success',
                'message': message
            }
            return jsonify(**resp)
        else:
            return redirect(url_for('dashboard'))


    except Exception as e:
        resp = {
            'status': 'failed',
            'error': str(e)
        }

        return jsonify(**resp)
开发者ID:yashmehrotra,项目名称:HE-Task-1,代码行数:29,代码来源:app.py


示例4: exec_global

    def exec_global(self, request):
        """
        Execute a global-scoped command.
        """

        command = request["command"]

        if command == "go back to perm":
            liq.set_var("selected", "perm")
            liq.send_command("perm-switch.skip")

            self.send_feedback(request)

        elif command == "rescan":
            result = Utilities.rescan()
            self.send_feedback(request, result)

        elif command == "select":
            studio = session.query(Studio).find_by(slug=request["studio"].decode('utf-8'))

            if studio is not None:
                studio.selected = True
                session.add(studio)
                session.commit()
                liq.set_var("selected", str(studio.slug))
                sylog("INFO: Selecting " + studio.slug)
                self.send_feedback(request)
            else:
                self.send_feedback(request, "error", "Unknown studio %s" % request["studio"])
开发者ID:synopslive,项目名称:sydroid,代码行数:29,代码来源:Control.py


示例5: addEdit

    def addEdit(self, _thread_id, _content, _submitted=False):
        existingList = (
            session.query(bot_comments_anetpool)
            .filter_by(thread_id=_thread_id)
            .order_by(desc(bot_comments_anetpool.edit_id))
            .first()
        )

        if existingList is None:
            row = bot_comments_anetpool()
            row.thread_id = _thread_id
            _from_template = self.anetpool_template.split("	", 1)
            row.content = _from_template[0] + _content + "	" + _from_template[1]
            row.submitted = _submitted
            session.add(row)
        else:
            if len(existingList.content) + len(_content) >= 10000:
                row = bot_comments_anetpool()
                row.thread_id = _thread_id
                _from_template = self.anetpool_template.split("	", 1)
                row.content = _from_template[0] + _content + "	" + _from_template[1]
                row.submitted_id = "e" + str(existingList.edit_id)
                row.submitted = _submitted
                session.add(row)
            else:
                _from_save = existingList.content.split("	", 1)
                session.query(bot_comments_anetpool).filter_by(edit_id=existingList.edit_id).update(
                    {"content": _from_save[0] + _content + "	" + _from_save[1], "submitted": False}
                )
        session.commit()
开发者ID:networkjanitor,项目名称:polarbytebot,代码行数:30,代码来源:polarbytebot.py


示例6: item_edit

def item_edit(item_title):
    categories = session.query(Category).all()
    item = session.query(Item).filter_by(
        title=item_title).one()
    user = session.query(User).filter_by(
        id=login_session.get('user_id')).one()
    if item.user is not None and item.user.id != user.id:
        return redirect(url_for('home'))
    if request.method == 'POST':
        form = vh.ItemForm(request.form, item)
        file_storage_err = vh.store_item_pic(
            item, request.files['picture'])
        if (not form.validate() or file_storage_err is not None):
            return render_template('item_edit.html',
                                   form=form,
                                   file_err=file_storage_err)
        form.populate_obj(item)
        try:
            session.add(item)
            session.commit()
        except ValueError as e:
            return "Database validation error: " + str(e)
        except SQLAlchemyError as e:
            # todo: log error, but don't display detailed message
            # for security reasons
            return "Database error: " + str(e)
        return redirect(url_for('home'))
    else:
        form = vh.ItemForm(obj=item)
        return render_template('item_edit.html',
                               form=form,
                               file_err=None)
开发者ID:ransomw,项目名称:udacity-fsnd-p3,代码行数:32,代码来源:views.py


示例7: add_comment

 def add_comment(self, _thing_id, _content, _submitted=False, _signature=None):
     if _signature is None:
         _signature = self.signature
     last_id = _thing_id
     extra_len = len("\n\n--- continued below ---") + len(_signature)
     while True:
         if len(_content) <= 0:
             return
         content_parts = _content.split("\n")
         stiched_content = ""
         for part in content_parts:
             if len(stiched_content) + len(part + "\n") + extra_len <= 10000:
                 stiched_content += part + "\n"
             else:
                 break
         row = bot_comments()
         row.thing_id = last_id
         row.submitted = _submitted
         if _content[len(stiched_content) :] == "":
             row.content = stiched_content + _signature
         else:
             row.content = stiched_content + "\n\n--- continued below ---" + _signature
         session.add(row)
         session.commit()
         last_id = "i{}".format(session.query(bot_comments).order_by(desc(bot_comments.id)).first().id)
         _content = _content[len(stiched_content) :]
开发者ID:networkjanitor,项目名称:polarbytebot,代码行数:26,代码来源:polarbytebot.py


示例8: submitComments

 def submitComments(self):
     global r
     to_be_commented = session.query(bot_comments).filter_by(submitted=False).all()
     for tbcm in to_be_commented:
         obj = r.get_info(thing_id=tbcm.thing_id)
         if tbcm.thing_id[:2] == "t3":
             try:
                 reply_obj = obj.add_comment(tbcm.content)
             except (praw.errors.InvalidSubmission):
                 self.updateSubmitted(bot_comments, tbcm.id, "del-1")
                 logging.warning("submitComment: failed (parentDeleted): {0}".format(tbcm.id))
             else:
                 self.updateSubmitted(bot_comments, tbcm.id, reply_obj.name)
                 logging.info("submitComment: submit: {0}".format(tbcm.id))
         elif tbcm.thing_id[:2] == "t1":
             try:
                 reply_obj = obj.reply(tbcm.content)
             except (praw.errors.InvalidComment):
                 self.updateSubmitted(bot_comments, tbcm.id, "del-1")
                 logging.warning("submitComment: failed (parentDeleted): {0}".format(tbcm.id))
             else:
                 self.updateSubmitted(bot_comments, tbcm.id, reply_obj.name)
                 logging.info("submitComment: submit: {0}".format(tbcm.id))
         elif tbcm.thing_id[:1] == "i":
             new_id = self.searchSubmitted(bot_comments, tbcm.thing_id[1:])
             if new_id == "del-1":
                 self.updateSubmitted(bot_comments, tbcm.id, "del-1")
             if new_id is not None:
                 self.updateThingId(bot_comments, tbcm.id, new_id)
         session.commit()
开发者ID:networkjanitor,项目名称:polarbytebot,代码行数:30,代码来源:polarbytebot.py


示例9: insert_test

def insert_test():
    tom = Teacher(name='Tom', subject='Physics')
    session.add(tom)
    session.commit()
    lucy = Student(name='Lucy', head_teacher_id=tom.id)
    session.add(lucy)
    session.commit()
开发者ID:EmuxEvans,项目名称:py_learn,代码行数:7,代码来源:test.py


示例10: save_utf

def save_utf(utf):
	current_user = session_user(request)
	utf_bool = bool(utf)
	current_user.support_utf8 = utf_bool
	current_user.tested_utf8 = True
	session.commit()
	return redirect(url_for('home'))
开发者ID:bradmerlin,项目名称:mxit-blackjack_flask,代码行数:7,代码来源:app.py


示例11: load_playlists

def load_playlists(session):
    user = 1
    playlist_titles = ["Narrative Shorts", "Something Different", "Hellbent Sports", "Documentaries"]
    for title in playlist_titles:
        playlist = models.Playlists(title=title, user_id=user)
        session.add(playlist)
    session.commit()
开发者ID:bessiec,项目名称:PlayShortFlix-Hackbright-Project,代码行数:7,代码来源:seed.py


示例12: set_online

    def set_online(cls, jid, show=None):
        """ 设置成员在线
        Arguments:
            `jid`   -   成员jid
            `show`  -   stanza.show
        """
        m = cls.get_one(jid)
        if not m:
            return False
        try:
            status = session.query(Status)\
                    .filter(and_(Status.resource == jid.resource,
                                 Status.member == m)).one()
            status.show = show
        except NoResultFound:
            status = Status(show, jid.resource)
            if m.status:
                m.status.append(status)
            else:
                m.status = [status]
        finally:
            try:
                session.commit()
            except:
                session.rollback()

        return True
开发者ID:Jack1007,项目名称:clubot,代码行数:27,代码来源:logics.py


示例13: get_whole_page_content

def get_whole_page_content(amount):
	'''
	get_whold_page_content()
	amount : get_page_amount()
	return : write sqlite
	'''
	count = 0
	for page_num in range(1, amount+1):
		print u'Scraping page <%3d>...' % page_num


		url = build_url(page_num)

		print u'Now in: %s' % url

		# get page_content
		content_lst = get_content_from_page(url)

		print u'Get <%3d> pices from this page.\n' % len(content_lst)

		for author, content in content_lst:
			content_obj = Hot(author=author, content=content)
			session.add(content_obj)
			count += 1

		if count >= 100:
			session.commit()
			count = 0

		# couldn't be too soon
		time.sleep(3)

	session.commit()
	return 
开发者ID:glrh111,项目名称:python-features,代码行数:34,代码来源:spider.py


示例14: mod

def mod():
    global __HEXDIGEST__
    if request.method == "GET":
        mess = session.query(EmailMessage).get(__HEXDIGEST__)
        if mess is None or mess.approved == True:
            flash('No new messages to edit')
            return render_template('edit.html')
        dct = json.loads(mess.everything)
        form = EditForm()
        form.subject.data = dct.get('subject')
        form.text.data = dct.get('body-plain')
        form.approved.data = mess.approved
        return render_template('edit.html', form=form) 
    else:
        form = EditForm(request.form)
        mess = session.query(EmailMessage).get(__HEXDIGEST__)
        if form.approved.data == True:
            send_message(form.data)
            mess.approved = True
            session.add(mess)
            session.commit()
            flash('message sent')
            return render_template('edit.html')
        flash("bad form")
        return "bad form"
开发者ID:NSkelsey,项目名称:verdant,代码行数:25,代码来源:app.py


示例15: message_good

def message_good(form):
    global __HEXDIGEST__
    _json = json.dumps(form.to_dict())
    mess = EmailMessage(_json)
    mess.hexdigest = __HEXDIGEST__
    session.add(mess)
    session.commit()
开发者ID:NSkelsey,项目名称:verdant,代码行数:7,代码来源:app.py


示例16: websocket_to_database

def websocket_to_database():
    try:
        websocket = yield from websockets.connect("wss://ws-feed.exchange.coinbase.com")
    except gaierror:
        db_logger.error('socket.gaierror - had a problem connecting to Coinbase feed')
        return
    yield from websocket.send('{"type": "subscribe", "product_id": "BTC-USD"}')
    while True:
        message = yield from websocket.recv()
        if message is None:
            file_logger.error('Websocket message is None!')
            break
        try:
            message = json.loads(message)
        except TypeError:
            db_logger.error('JSON did not load, see ' + str(message))
            continue
        if message['type'] != 'match':
            continue
        new_message = Messages()
        for key in message:
            if hasattr(new_message, key):
                setattr(new_message, key, message[key])
            else:
                db_logger.error(str(key) + ' is missing, see ' + str(message))
                continue
        try:
            session.add(new_message)
            session.commit()
        except IntegrityError:
            session.rollback()
        except DatabaseError:
            file_logger.error('Database Error')
            session.rollback()
开发者ID:PierreRochard,项目名称:big-dipper,代码行数:34,代码来源:websocket_feed.py


示例17: fetchGamelogs

	def fetchGamelogs(self, player):

		# Delete all gamelogs for player
		for gamelog in player.gamelogs:
			session.delete(gamelog)

		scraper = Scraper()
		logs = scraper.getGamelogs(player.id)
		gamelogs = []
		for log in logs:
			gamelog = Gamelog()
			gamelog.player = player
			gamelog.game_id = log['game_id']
			gamelog.MIN = log['MIN']
			gamelog.FGM = log['FGM']
			gamelog.FGA = log['FGA']
			gamelog.FG_PCT = log['FG_PCT']
			gamelog.FG3M = log['FG3M']
			gamelog.FG3A = log['FG3A']
			gamelog.FG3_PCT = log['FG3_PCT'] 
			gamelog.FG3M = log['FTM']
			gamelog.FG3A = log['FTA']
			gamelog.FG3_PCT = log['FT_PCT'] 
			gamelog.OREB = log['OREB']
			gamelog.DREB = log['DREB']
			gamelog.REB = log['REB'] 
			gamelog.AST = log['AST']
			gamelog.STL = log['STL']
			gamelog.BLK = log['BLK']
			gamelog.TOV = log['TOV']
			gamelog.PTS = log['PTS'] 
			gamelog.DK = self.calcDK(log)
			gamelogs.append(gamelog)
		session.add_all(gamelogs)
		session.commit()
开发者ID:cyrusaf,项目名称:sports-betting,代码行数:35,代码来源:Model.py


示例18: save_game

def save_game(current_game,user):
	"""	Save a Game State for a particular MxitUser to the database.
	"""
	active_game = session.query(SaveGame).filter_by(user_id=user.id).first()
	#Update the saved game to the new one.
	active_game.game = current_game
	session.commit()
开发者ID:bradmerlin,项目名称:mxit-blackjack_flask,代码行数:7,代码来源:app.py


示例19: get_page_links2

def get_page_links2():
    '''
        Description: get images' second layer links
    '''
    pageLink = page_link1_queue.get()
    print "page links2 process id:%s" %os.getpid()
    print "Starting to crawl : %s" %pageLink
    if pageLink:
        #picture_urls = []  
        response = requests.get(pageLink, headers=headers) 
        soup = BeautifulSoup(response.text, "html.parser")
        picture_divs = soup.find_all("div", {"class":"pic"})
        for picture_div in picture_divs:
            picture_url = picture_div.find("a").get("href")
            page_link2_queue.put(picture_url)
            #picture_urls.append(picture_url)

            query = session.query(SecondLevelLinks)
            query_result = query.filter(SecondLevelLinks.url==picture_url).first()
            if query_result:
                continue
            else:
                second_level_links = SecondLevelLinks(url=picture_url)
                session.add(second_level_links)
        session.flush()
        session.commit()

        return page_link2_queue
    else:
        return None
开发者ID:zhengze,项目名称:imagecrawler,代码行数:30,代码来源:crawler.py


示例20: set_info

    def set_info(cls, jid, key, value):
        """ 设置成员选项
        Arguments:
            `jid`   -   jid
            `key`   -   选项键
            `value` -   选项值
        """
        m = cls.get_one(jid)
        try:
            info = session.query(Info).filter(and_(Info.key == key,
                                                   Info.member == m,
                                                   Info.is_global == 0)).one()
            info.value = value
        except NoResultFound:
            info = Info(key, value)
            if m.infos:
                m.infos.append(info)
            else:
                m.infos = [info]
        finally:
            try:
                session.commit()
            except:
                session.rollback()

        return info
开发者ID:Jack1007,项目名称:clubot,代码行数:26,代码来源:logics.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python session.query函数代码示例发布时间:2022-05-27
下一篇:
Python session.add函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap