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

Python functions.current_timestamp函数代码示例

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

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



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

示例1: authenticate

 def authenticate(self, session):
     '''
     @see: IAuthenticationService.authenticate
     '''
     olderThan = self.session().query(current_timestamp()).scalar()
     olderThan -= self._sessionTimeOut
     sql = self.session().query(LoginMapped)
     sql = sql.filter(LoginMapped.Session == session)
     sql = sql.filter(LoginMapped.AccessedOn > olderThan)
     try: login = sql.one()
     except NoResultFound: raise InputError(Ref(_('Invalid session'), ref=Login.Session))
     assert isinstance(login, LoginMapped), 'Invalid login %s' % login
     login.AccessedOn = current_timestamp()
     self.session().flush((login,))
     self.session().expunge(login)
     commitNow()
     # We need to fore the commit because if there is an exception while processing the request we need to make
     # sure that the last access has been updated.
     
     userId = str(login.User)
     rights = (right.Name for right in self.userRbacService.getRights(login.User))
     accesses = self.aclAccessService.accessFor(self.aclAccessService.rightsFor(rights))
     allowed = []
     for access in accesses:
         assert isinstance(access, AclAccess), 'Invalid access %s' % access
         for propertyType, mark in access.markers.items():
             assert isinstance(propertyType, TypeProperty), 'Invalid property type %s' % propertyType
             assert isinstance(propertyType.parent, TypeModel)
             if propertyType.parent.clazz == User or issubclass(propertyType.parent.clazz, User):
                 for k in range(len(access.Filter)): access.Filter[k] = access.Filter[k].replace(mark, userId)
         allowed.append(access)
     return allowed
开发者ID:gizm0bill,项目名称:Superdesk,代码行数:32,代码来源:authentication.py


示例2: authenticate

    def authenticate(self, identifier, attributes, arguments):
        '''
        @see: IAuthenticationSupport.authenticate
        '''
        assert isinstance(identifier, str), 'Invalid identifier %s' % identifier
        assert isinstance(attributes, dict), 'Invalid attributes %s' % attributes
        assert isinstance(arguments, dict), 'Invalid arguments %s' % arguments

        olderThan = self.session().query(current_timestamp()).scalar()
        olderThan -= self.sessionTimeOut
        sql = self.session().query(LoginMapped)
        sql = sql.filter(LoginMapped.Session == identifier)
        sql = sql.filter(LoginMapped.AccessedOn > olderThan)
        try: login = sql.one()
        except NoResultFound: return False
        assert isinstance(login, LoginMapped), 'Invalid login %s' % login
        login.AccessedOn = current_timestamp()
        self.session().flush((login,))
        self.session().expunge(login)
        commitNow()
        # We need to fore the commit because if there is an exception while processing the request we need to make
        # sure that the last access has been updated.

        for authType in arguments:
            assert isinstance(authType, Type), 'Invalid type %s' % authType

            if authType == typeFor(User.Id): arguments[authType] = login.User
            else: raise DevelError('Invalid authenticated type %s' % authType)

        return True
开发者ID:adityaathalye,项目名称:Superdesk,代码行数:30,代码来源:authentication.py


示例3: make_changes_table

def make_changes_table(table, metadata):
    """Create an object log table for an object.
    """
    table_name = table.name
    entity_name = singular(table_name)
    changes_name = "%s_changes" % (entity_name)
    fk_id = "%s_id" % (entity_name)
    changes_table = rdb.Table(changes_name, metadata,
        rdb.Column("change_id", rdb.Integer, primary_key=True),
        # the item_id of the "owning" item being logged !+HEAD_DOCUMENT_ITEM
        rdb.Column("content_id", rdb.Integer, 
            rdb.ForeignKey(table.c[fk_id]),
            nullable=False,
            index=True
        ),
        rdb.Column("action", rdb.Unicode(16)),
        # audit date, exclusively managed by the system
        rdb.Column("date_audit", rdb.DateTime(timezone=False),
            default=functions.current_timestamp(),
            nullable=False
        ),
        # user-modifiable effective date, defaults to same value as audit date;
        # this is the date to be used for all intents and purposes other than 
        # for data auditing
        rdb.Column("date_active", rdb.DateTime(timezone=False),
            default=functions.current_timestamp(),
            nullable=False
        ),
        rdb.Column("description", rdb.UnicodeText),
        rdb.Column("notes", rdb.UnicodeText),
        rdb.Column("user_id", rdb.Integer, rdb.ForeignKey("users.user_id")),
        #!+SA0.7 rdb.Index("%s_changes_cid_idx" % (entity_name), "content_id"),
        useexisting=False
    )
    return changes_table
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:35,代码来源:schema.py


示例4: getGateways

 def getGateways(self, session):
     '''
     @see: IAuthenticationService.getGateways
     '''
     olderThan = self.session().query(current_timestamp()).scalar()
     olderThan -= self._sessionTimeOut
     sql = self.session().query(LoginMapped)
     sql = sql.filter(LoginMapped.Session == session)
     sql = sql.filter(LoginMapped.AccessedOn > olderThan)
     try: login = sql.one()
     except NoResultFound: return ()
     assert isinstance(login, LoginMapped), 'Invalid login %s' % login
     login.AccessedOn = current_timestamp()
     self.session().flush((login,))
     self.session().expunge(login)
     commitNow()
     
     # We need to fore the commit because if there is an exception while processing the request we need to make
     # sure that the last access has been updated.
     proc = self._processing
     assert isinstance(proc, Processing), 'Invalid processing %s' % proc
     
     solicit = proc.execute(FILL_CLASSES, solicit=proc.ctx.solicit(acl=login.User)).solicit
     assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
     return solicit.gateways or ()
开发者ID:petrjasek,项目名称:ally-py-common,代码行数:25,代码来源:authentication.py


示例5: make_changes_table

def make_changes_table(table, metadata):
    """Create an object log table for an object.
    """
    table_name = table.name
    entity_name = singular(table_name)
    changes_name = "%s_changes" % (entity_name)
    fk_id = "%s_id" % (entity_name)
    changes_table = rdb.Table(changes_name, metadata,
        rdb.Column("change_id", rdb.Integer, primary_key=True),
        rdb.Column("content_id", rdb.Integer, rdb.ForeignKey(table.c[fk_id])),
        rdb.Column("action", rdb.Unicode(16)),
        # audit date, exclusively managed by the system
        rdb.Column("date_audit", rdb.DateTime(timezone=False),
            default=functions.current_timestamp(),
            nullable=False
        ),
        # user-modifiable effective date, defaults to same value as audit date;
        # this is the date to be used for all intents and purposes other than 
        # for data auditing
        rdb.Column("date_active", rdb.DateTime(timezone=False),
            default=functions.current_timestamp(),
            nullable=False
        ),
        rdb.Column("description", rdb.UnicodeText),
        rdb.Column("notes", rdb.UnicodeText),
        rdb.Column("user_id", rdb.Integer, rdb.ForeignKey("users.user_id")),
        useexisting=True # !+ZCA_TESTS(mr, jul-2011) tests break without this
    )
    return changes_table
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:29,代码来源:schema.py


示例6: authenticate

 def authenticate(self, session):
     '''
     @see: IAuthenticationService.authenticate
     '''
     olderThan = self.session().query(current_timestamp()).scalar()
     olderThan -= self._sessionTimeOut
     sql = self.session().query(LoginMapped)
     sql = sql.filter(LoginMapped.Session == session)
     sql = sql.filter(LoginMapped.AccessedOn > olderThan)
     try: login = sql.one()
     except NoResultFound: raise InputError(Ref(_('Invalid session'), ref=Login.Session))
     assert isinstance(login, LoginMapped), 'Invalid login %s' % login
     login.AccessedOn = current_timestamp()
     self.session().flush((login,))
     self.session().expunge(login)
     commitNow()
     
     # We need to fore the commit because if there is an exception while processing the request we need to make
     # sure that the last access has been updated.
     proc = self._processing
     assert isinstance(proc, Processing), 'Invalid processing %s' % proc
     
     solicitation = proc.ctx.solicitation()
     assert isinstance(solicitation, Solicitation), 'Invalid solicitation %s' % solicitation
     solicitation.userId = login.User
     solicitation.types = self.acl.types
     
     chain = Chain(proc)
     chain.process(**proc.fillIn(solicitation=solicitation, reply=proc.ctx.reply())).doAll()
     
     reply = chain.arg.reply
     assert isinstance(reply, Reply), 'Invalid reply %s' % reply
     if reply.gateways is None: return ()
     
     return sorted(reply.gateways, key=lambda gateway: (gateway.Pattern, gateway.Methods))
开发者ID:Halfnhav4,项目名称:Superdesk,代码行数:35,代码来源:authentication.py


示例7: last_update_time

def last_update_time() -> sa.Column:
    """A timestamp column set to CURRENT_TIMESTAMP on update.

    Return a column containing the time that a record was last updated.

    :return: a SQLAlchemy Column for a datetime with time zone auto-updating
             column
    """
    return sa.Column(
        pg.TIMESTAMP(timezone=True),
        nullable=False,
        server_default=current_timestamp(),
        onupdate=current_timestamp(),
    )
开发者ID:4sp1r3,项目名称:dokomoforms,代码行数:14,代码来源:util.py


示例8: update_available_cookies

 def update_available_cookies(self, user):
     now = datetime.datetime.now()
     now = datetime.datetime(now.year,now.month,now.day)
     if not user.last_cookie_date or (now - user.last_cookie_date).days > 0:
         user.available_cookies = Config.getint("Alliance","cookies")
         user.last_cookie_date = current_timestamp()
         session.commit()
开发者ID:Hardware-Hacks,项目名称:merlin,代码行数:7,代码来源:cookie.py


示例9: cancel

 def cancel(self, message, user, params):
     id = params.group(1)
     prop = self.load_prop(id)
     if prop is None:
         message.reply("No proposition number %s exists (idiot)."%(id,))
         return
     if not prop.active:
         message.reply("You can't cancel prop %d, it's already expired."%(prop.id,))
         return
     if prop.proposer is not user and not user.is_admin():
         message.reply("Only %s may cancel proposition %d."%(prop.proposer.name,prop.id))
         return
     
     self.recalculate_carebears(prop)
     
     yes, no, veto = self.sum_votes(prop)
     vote_result = "cancel"
     
     reply = self.text_result(vote_result, yes, no, veto)
     reply+= self.text_summary(prop)
     message.reply(reply)
     
     prop.active = False
     prop.closed = current_timestamp()
     prop.vote_result = vote_result
     session.commit()
开发者ID:JDD,项目名称:merlin,代码行数:26,代码来源:prop.py


示例10: insert

    def insert(self, post):
        '''
        @see: IPostService.insert
        '''
        assert isinstance(post, Post), 'Invalid post %s' % post
        postDb = PostMapped()
        copy(post, postDb, exclude=COPY_EXCLUDE)
        postDb.typeId = self._typeId(post.Type)

        postDb = self._adjustTexts(postDb)

        if post.CreatedOn is None: postDb.CreatedOn = current_timestamp()
        if not postDb.Author:
            colls = self.session().query(CollaboratorMapped).filter(CollaboratorMapped.User == postDb.Creator).all()
            if not colls:
                coll = CollaboratorMapped()
                coll.User = postDb.Creator
                src = self.session().query(SourceMapped).filter(SourceMapped.Name == PostServiceAlchemy.default_source_name).one()
                coll.Source = src.Id
                self.session().add(coll)
                self.session().flush((coll,))
                colls = (coll,)
            postDb.Author = colls[0].Id

        self.session().add(postDb)
        self.session().flush((postDb,))
        post.Id = postDb.Id
        return post.Id
开发者ID:AtomLaw,项目名称:Superdesk,代码行数:28,代码来源:post.py


示例11: createArticles

def createArticles():

    artService = entityFor(IArticleService)
    slug = 'article-demo'
    #assert isinstance(artService, ArticleServiceAlchemy)
    
    try:
        artService.getBySlug(slug)
        return 
    #    session.query(ArticleMapped.Id).filter(ArticleMapped.Id == '1').one()[0]
    except (NoResultFound, InputError):
        theArticle = ArticleMapped()
        theArticle.CreatedOn = current_timestamp()
        theArticle.Slug = slug
        artService.insert(theArticle)
    
    artCtxService = entityFor(IArticleCtxService)

    assert isinstance(artCtxService, ArticleCtxServiceAlchemy)
    
    for typ in [1,2,3,4]:
        ctx = ArticleCtxMapped()
        ctx.Type = typ
        ctx.Content = DATA['article_content']
        ctx.Article = theArticle.Id
        artCtxService.insert(ctx)
开发者ID:AtomLaw,项目名称:Superdesk,代码行数:26,代码来源:temp_populate.py


示例12: insert

 def insert(self, blog):
     '''
     @see: IBlogService.insert
     '''
     assert isinstance(blog, Blog), 'Invalid blog %s' % blog
     if blog.CreatedOn is None: blog.CreatedOn = current_timestamp()
     return super().insert(blog)
开发者ID:AtomLaw,项目名称:Superdesk,代码行数:7,代码来源:blog.py


示例13: insert

    def insert(self, post):
        '''
        @see: IPostService.insert
        '''
        assert isinstance(post, Post), 'Invalid post %s' % post
        postDb = PostMapped()
        copy(post, postDb, exclude=COPY_EXCLUDE)
        postDb.typeId = self._typeId(post.Type)

        # TODO: implement the proper fix using SQLAlchemy compilation rules
        nohigh = { i: None for i in range(0x10000, 0x110000) }
        if postDb.Meta: postDb.Meta = postDb.Meta.translate(nohigh)
        if postDb.Content: postDb.Content = postDb.Content.translate(nohigh)
        if postDb.ContentPlain: postDb.ContentPlain = postDb.ContentPlain.translate(nohigh)

        if post.CreatedOn is None: postDb.CreatedOn = current_timestamp()
        if not postDb.Author:
            colls = self.session().query(CollaboratorMapped).filter(CollaboratorMapped.User == postDb.Creator).all()
            if not colls:
                coll = CollaboratorMapped()
                coll.User = postDb.Creator
                src = self.session().query(SourceMapped).filter(SourceMapped.Name == PostServiceAlchemy.default_source_name).one()
                coll.Source = src.Id
                self.session().add(coll)
                self.session().flush((coll,))
                colls = (coll,)
            postDb.Author = colls[0].Id

        self.session().add(postDb)
        self.session().flush((postDb,))
        post.Id = postDb.Id
        return post.Id
开发者ID:Halfnhav4,项目名称:Superdesk,代码行数:32,代码来源:post.py


示例14: performLogin

    def performLogin(self, authentication):
        '''
        @see: IAuthenticationService.performLogin
        '''
        assert isinstance(authentication, Authentication), 'Invalid authentication %s' % authentication

        if authentication.Token is None:
            raise InputError(Ref(_('The login token is required'), ref=Authentication.Token))
        if authentication.HashedToken is None:
            raise InputError(Ref(_('The hashed login token is required'), ref=Authentication.HashedToken))
        if authentication.UserName is None:
            raise InputError(Ref(_('A user name is required for authentication'), ref=Authentication.UserName))

        olderThan = self.session().query(current_timestamp()).scalar()
        olderThan -= self._authenticationTimeOut
        sql = self.session().query(TokenMapped)
        sql = sql.filter(TokenMapped.Token == authentication.Token)
        sql = sql.filter(TokenMapped.requestedOn > olderThan)
        if sql.delete() > 0:
            commitNow()  # We make sure that the delete has been performed

            try: user = self.session().query(UserMapped).filter(UserMapped.Name == authentication.UserName).filter(UserMapped.DeletedOn == None).one()
            except NoResultFound: user = None

            if user is not None:
                assert isinstance(user, UserMapped), 'Invalid user %s' % user

                hashedToken = hmac.new(bytes(user.Name, 'utf8'),
                                       bytes(user.password, 'utf8'), hashlib.sha512).hexdigest()
                hashedToken = hmac.new(bytes(hashedToken, 'utf8'),
                                       bytes(authentication.Token, 'utf8'), hashlib.sha512).hexdigest()

                if authentication.HashedToken == hashedToken:
                    hash = hashlib.sha512()
                    hash.update(urandom(self.authentication_token_size))

                    login = LoginMapped()
                    login.Session = hash.hexdigest()
                    login.User = user.Id
                    login.CreatedOn = login.AccessedOn = current_timestamp()

                    try: self.session().add(login)
                    except SQLAlchemyError as e: handle(e, login)

                    return login

        raise InputError(_('Invalid credentials'))
开发者ID:Halfnhav4,项目名称:Superdesk,代码行数:47,代码来源:authentication.py


示例15: is_updated

 def is_updated(self):
     return deferred(
         sa.Column(
             sa.TIMESTAMP, nullable=False, default=datetime.datetime.now,
             server_default=sqlaexp.text('0'),
             onupdate=datetime.datetime.now,
             server_onupdate=sqlafunc.current_timestamp(),
             ))
开发者ID:TakesxiSximada,项目名称:azoth,代码行数:8,代码来源:models.py


示例16: putLive

 def putLive(self, blogId):
     '''
     @see: IBlogService.putLive
     '''
     blog = self.session().query(BlogMapped).get(blogId)
     if not blog: raise InputError(_('Invalid blog or credentials'))
     assert isinstance(blog, Blog), 'Invalid blog %s' % blog
     blog.LiveOn = current_timestamp() if blog.LiveOn is None else None
     self.session().merge(blog)
开发者ID:AtomLaw,项目名称:Superdesk,代码行数:9,代码来源:blog.py


示例17: hide

 def hide(self, blogId):
     '''
     @see: IBlogService.hide
     '''
     blog = self.session().query(BlogMapped).get(blogId)
     if not blog: raise InputError(_('Invalid blog or credentials'))
     assert isinstance(blog, Blog), 'Invalid blog %s' % blog
     blog.DeletedOn = current_timestamp() 
     self.session().merge(blog)   
开发者ID:Eduardoescamilla,项目名称:Live-Blog,代码行数:9,代码来源:blog.py


示例18: updateLastAccessOn

def updateLastAccessOn(session, groupId):
    sql = session.query(BlogCollaboratorGroupMapped)
    sql = sql.filter(BlogCollaboratorGroupMapped.Id == groupId)

    try: group = sql.one()
    except NoResultFound: raise InputError(Ref(_('No collaborator group'), ref=BlogCollaboratorGroupMapped.Id))
    
    group.LastAccessOn = current_timestamp()
    session.add(group) 
    session.flush((group,))
开发者ID:AtomLaw,项目名称:Superdesk,代码行数:10,代码来源:blog_collaborator_group.py


示例19: delete

 def delete(self, id):
     '''
     @see: IUserService.delete
     '''
     userDb = self.session().query(UserMapped).get(id)
     if not userDb or userDb.DeletedOn is not None: return False
     assert isinstance(userDb, UserMapped), 'Invalid user %s' % userDb
     userDb.DeletedOn = current_timestamp()
     self.session().merge(userDb)
     return True
开发者ID:Halfnhav4,项目名称:Superdesk,代码行数:10,代码来源:user.py


示例20: delete

    def delete(self, id):
        '''
        @see: IPostService.delete
        '''
        postDb = self.session().query(PostMapped).get(id)
        if not postDb or postDb.DeletedOn is not None: return False

        postDb.DeletedOn = current_timestamp()
        self.session().flush((postDb,))
        return True
开发者ID:Eduardoescamilla,项目名称:Live-Blog,代码行数:10,代码来源:post.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python functions.max函数代码示例发布时间:2022-05-27
下一篇:
Python functions.count函数代码示例发布时间: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