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


Python Session.rollback方法代码示例

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


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

示例1: save_users_request

# 需要导入模块: from core.people.person import Session [as 别名]
# 或者: from core.people.person.Session import rollback [as 别名]
def save_users_request(sender, text):
    """ should be in separate file"""
    #start sqlalchemy session
    sess = Session()
    profile = None

    #exctract sender email
    if sender:
        email = sender.split('/')[0]
        if email:
            update_list_from_jabber({email})
            #find user profile by primary email
            try:
                profile = sess.query(Profile).filter(
                    Profile.email == email).one()
            except Exception as e:
                logger.exception(e)
                return False

    if not profile:
        return False

    req = {}
    logger.info('save new request %s' % text)
    try:
        req['request'] = text
        req['type'] = 'command'
        req['uuid'] = profile.uuid
        request = ProfileRequest(**req)
        sess.add(request)
        sess.commit()
    except Exception as e:
        sess.rollback()
        logger.exception(e)
开发者ID:vsilent,项目名称:smarty-bot,代码行数:36,代码来源:requests.py

示例2: on_continue

# 需要导入模块: from core.people.person import Session [as 别名]
# 或者: from core.people.person.Session import rollback [as 别名]
    def on_continue(self, msg):
        """docstring for on_continue"""
        todo = {}
        response = "Ok."
        request = msg.get('request', None)
        sender = msg.get('sender', '')
        req_from = msg.get('from', '')
        #error = msg.get('error', '')
        #logger.info('error %s..........................' % error)
        #logger.info('req_from %s..........................' % req_from)
        #logger.info('request %s..........................' % request)

        sess = Session()

        #exctract sender email
        email = sender.split('/')[0]

        #find user profile by primary email
        profile = sess.query(Profile).filter(Profile.email == email).one()

        if self.is_correct_format(request):
            insert = {}
            insert['uuid'] = profile.uuid
            insert['type'] = 'custom'
            insert['created'] = datetime.datetime.utcnow()
            logger.debug('request type %s' % type(request), request)
            insert['spent'] = request

            try:
                ts = ProfileTimesheet(**insert)
                sess.add(ts)
                sess.commit()
            except Exception as e:
                sess.rollback()
                logger.exception(e)
                report_bug(e)
                response = 'I could not save it, problem has \
                been already reported to developer'
        else:
            response = " type something like:  8 hours "
            todo['continue'] = 1

        if req_from == 'jabber':
            todo = {'text': response,
                    'jmsg': response,
                    'type': 'response',
                    'continue': 0}
            self.response = todo

        if req_from == 'julius':
            from core.broadcast import say, bang
            bang()
            todo = {'say': response,
                    'text': response,
                    'type': 'response',
                    'continue': 0}
            self.response = say(self.request.replace('say', '').upper())

        return self.response
开发者ID:vsilent,项目名称:smarty-bot,代码行数:61,代码来源:reaction.py

示例3: run

# 需要导入模块: from core.people.person import Session [as 别名]
# 或者: from core.people.person.Session import rollback [as 别名]
    def run(self):
        """default method"""

        #start sqlalchemy session
        sess = Session()
        sender = self.req_obj.get('sender', '')

        #exctract sender email
        email = sender.split('/')[0]

        #find user profile by primary email
        profile = sess.query(Profile).filter(Profile.email == email).one()

        #exstract url from request
        req = self.request.replace('add user', '', 1)
        name = req.strip().split()

        response = 'sorry you are not allowed to add new users'
        if profile.type == 'admin' and self.req_from == 'jabber':
            if name:
                logger.info('new user %s' % name)
                exists = sess.query(Profile).filter(
                    and_(Profile.first_name == name[0],
                         Profile.last_name == name[1])).all()
                user = {}

                if not exists:
                    try:
                        user['first_name'] = name[0]
                        user['last_name'] = name[1]
                        user['email'] = name[2]
                        add_profile(user)

                    except Exception as e:
                        sess.rollback()
                        logger.exception(e)

                    response = '%s added' % name
                else:
                    response = 'looks like %s is already exists' % name

            else:
                response = """
                Hmm  could not parse name,
                can you add it like this:
                    add user John Smith [email protected]"""

        if self.req_from == 'jabber':
            todo = {'text': response, 'jmsg': response, 'type': 'response'}
            self.response = todo

        if self.req_from == 'julius':
            bang()
            todo = {'say': response, 'text': response, 'type': 'response'}
            self.response = say(self.request.replace('say', '').upper())

        return self.response
开发者ID:vsilent,项目名称:smarty-bot,代码行数:59,代码来源:reaction.py

示例4: run

# 需要导入模块: from core.people.person import Session [as 别名]
# 或者: from core.people.person.Session import rollback [as 别名]
    def run(self):
        """default method"""

        #start sqlalchemy session
        sess = Session()

        sender = self.req_obj.get('sender', '')

        #exctract sender email
        email = sender.split('/')[0]

        #find user profile by primary email
        profile = sess.query(Profile).filter(Profile.email == email).one()

        #exstract url from request
        req = self.request.replace('add url', '', 1).strip()
        url = re.search("(?P<url>https?://[^\s]+)", req).group("url")
        logger.info('got %s' % url)

        if url:
            exists = sess.query(ProfileLink).filter(and_(ProfileLink.url == url, ProfileLink.uuid == profile.uuid)).all()
            link = {}

            if not exists:
                try:
                    link['url'] = url
                    link['type'] = 'external'
                    link['uuid'] = profile.uuid

                    l = ProfileLink(**link)
                    sess.add(l)
                    sess.commit()

                except Exception as e:
                    sess.rollback()
                    logger.exception(e)

                response = '%s added to your collection' % url
            else:
                response = 'looks like %s is already in collection' % url

        else:
            response = 'seems like %s is not valid url' % url

        if self.req_from == 'jabber':
            todo = { 'text' : response, 'jmsg' : response, 'type': 'response' }
            self.response = todo

        if self.req_from == 'julius':
            bang()
            todo = { 'say': response , 'text' : response ,'type': 'response' }
            self.response = say(self.request.replace('say', '').upper())

        return self.response
开发者ID:vsilent,项目名称:smarty-bot,代码行数:56,代码来源:reaction.py


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