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

Python last_modified.LastModified类代码示例

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

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



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

示例1: revise

    def revise(self, content, previous = None, author=None, force=False, reason=None):
        if content is None:
            content = ""
        if self.content == content:
            return
        force = True if previous is None else force
        max_length = special_length_restrictions_bytes.get(self.name, MAX_PAGE_LENGTH_BYTES)
        if len(content) > max_length:
            raise ContentLengthError(max_length)
        
        revision = getattr(self, 'revision', None)
        
        if not force and (revision and previous != revision):
            if previous:
                origcontent = WikiRevision.get(previous, pageid=self._id).content
            else:
                origcontent = ''
            try:
                content = threewaymerge(origcontent, content, self.content)
            except ConflictException as e:
                e.new_id = revision
                raise e
        
        wr = WikiRevision.create(self._id, content, author, reason)
        self.content = content
        self.last_edit_by = author
        self.last_edit_date = wr.date
        self.revision = str(wr._id)
        self._commit()

        LastModified.touch(self._fullname, "Edit")

        return wr
开发者ID:GodOfConquest,项目名称:reddit,代码行数:33,代码来源:wiki.py


示例2: add_comment_tree

def add_comment_tree(comments):
    # update the comment cache
    add_comments(comments)
    # update last modified
    links = Link._byID(list(set(com.link_id for com in tup(comments))), data=True, return_dict=False)
    for link in links:
        set_last_modified(link, "comments")
        LastModified.touch(link._fullname, "Comments")
开发者ID:huasanyelao,项目名称:reddit,代码行数:8,代码来源:queries.py


示例3: _commit

    def _commit(self, *a, **kw):
        assert self._id == self._rowkey(self.thing1_id, self.thing2_id)

        retval = ThingBase._commit(self, *a, **kw)

        from r2.models.last_modified import LastModified
        fullname = self._thing1_cls._fullname_from_id36(self.thing1_id)
        LastModified.touch(fullname, self._cf.column_family)

        return retval
开发者ID:JackePeng,项目名称:reddit,代码行数:10,代码来源:tdb_cassandra.py


示例4: update_vote_lookups

def update_vote_lookups(user, thing, direction):
    """Store info about the existence of this vote (before processing)."""
    # set the vote in memcached so the UI gets updated immediately
    key = prequeued_vote_key(user, thing)
    grace_period = int(g.vote_queue_grace_period.total_seconds())
    direction = Vote.serialize_direction(direction)
    g.cache.set(key, direction, time=grace_period+1)

    # update LastModified immediately to help us cull prequeued_vote lookups
    rel_cls = VotesByAccount.rel(thing.__class__)
    LastModified.touch(user._fullname, rel_cls._last_modified_name)
开发者ID:Arinzeokeke,项目名称:reddit,代码行数:11,代码来源:voting.py


示例5: update_last_visit

    def update_last_visit(self, current_time):
        from admintools import apply_updates

        apply_updates(self)

        prev_visit = LastModified.get(self._fullname, "Visit")
        if prev_visit and current_time - prev_visit < timedelta(days=1):
            return

        g.log.debug("Updating last visit for %s from %s to %s" % (self.name, prev_visit, current_time))

        LastModified.touch(self._fullname, "Visit")
开发者ID:numo16,项目名称:reddit,代码行数:12,代码来源:account.py


示例6: update_last_visit

    def update_last_visit(self, current_time):
        from admintools import apply_updates

        apply_updates(self)

        #prev_visit = getattr(self, 'last_visit', None)
        prev_visit = last_visit(self)

        if prev_visit and current_time - prev_visit < timedelta(1):
            return

        g.log.debug ("Updating last visit for %s from %s to %s" %
                    (self.name, prev_visit, current_time))
        set_last_visit(self)

        LastModified.touch(self._fullname, "Visit")
开发者ID:anirudh2290,项目名称:reddit,代码行数:16,代码来源:account.py


示例7: handle_vote

def handle_vote(user, thing, dir, ip, organic,
                cheater=False, foreground=False, timer=None):
    if timer is None:
        timer = SimpleSillyStub()

    from r2.lib.db import tdb_sql
    from sqlalchemy.exc import IntegrityError
    try:
        v = Vote.vote(user, thing, dir, ip, organic, cheater = cheater,
                      timer=timer)
    except (tdb_sql.CreationError, IntegrityError):
        g.log.error("duplicate vote for: %s" % str((user, thing, dir)))
        return

    timestamps = []
    if isinstance(thing, Link):
        new_vote(v, foreground=foreground, timer=timer)

        #update the modified flags
        if user._id == thing.author_id:
            timestamps.append('Overview')
            timestamps.append('Submitted')
            #update sup listings
            sup.add_update(user, 'submitted')

            #update sup listings
            if dir:
                sup.add_update(user, 'liked')
            elif dir is False:
                sup.add_update(user, 'disliked')

    elif isinstance(thing, Comment):
        #update last modified
        if user._id == thing.author_id:
            timestamps.append('Overview')
            timestamps.append('Commented')
            #update sup listings
            sup.add_update(user, 'commented')

    timer.intermediate("sup")

    for timestamp in timestamps:
        set_last_modified(user, timestamp.lower())
    LastModified.touch(user._fullname, timestamps)
    timer.intermediate("last_modified")
开发者ID:Anenome,项目名称:reddit,代码行数:45,代码来源:queries.py


示例8: update_last_visit

    def update_last_visit(self, current_time):
        from admintools import apply_updates

        timer = g.stats.get_timer("account.update_last_visit")
        timer.start()

        apply_updates(self, timer)

        prev_visit = LastModified.get(self._fullname, "Visit")
        timer.intermediate("get_last_modified")

        if prev_visit and current_time - prev_visit < timedelta(days=1):
            timer.intermediate("set_last_modified.noop")
            timer.stop()
            return

        LastModified.touch(self._fullname, "Visit")
        timer.intermediate("set_last_modified.done")
        timer.stop()
开发者ID:XPRIYA,项目名称:HMWK2PartB,代码行数:19,代码来源:account.py


示例9: create

    def create(cls, thing1, thing2s, **kw):
        """Create a relationship between thing1 and thing2s.

        If there are any other views of this data, they will be updated as
        well.

        Takes kwargs which can be used by views
        or value_for to get additional information.

        """
        thing2s = tup(thing2s)
        values = {thing2._id36 : cls.value_for(thing1, thing2, **kw)
                  for thing2 in thing2s}
        cls._cf.insert(thing1._id36, values, ttl=cls._ttl)

        for view in cls._views:
            view.create(thing1, thing2s, **kw)

        if cls._write_last_modified:
            from r2.models.last_modified import LastModified
            LastModified.touch(thing1._fullname, cls._last_modified_name)
开发者ID:AHAMED750,项目名称:reddit,代码行数:21,代码来源:tdb_cassandra.py


示例10: fast_query

    def fast_query(cls, thing1, thing2s):
        """Find relationships between thing1 and various thing2s."""
        thing2s, thing2s_is_single = tup(thing2s, ret_is_single=True)

        if not thing1:
            return {}

        # don't bother looking up relationships for items that were created
        # since the last time the thing1 created a relationship of this type
        if cls._last_modified_name:
            from r2.models.last_modified import LastModified
            timestamp = LastModified.get(thing1._fullname,
                                         cls._last_modified_name)
            if timestamp:
                thing2s = [thing2 for thing2 in thing2s
                           if thing2._date <= timestamp]
            else:
                thing2s = []

        if not thing2s:
            return {}

        # fetch the row from cassandra. if it doesn't exist, thing1 has no
        # relation of this type to any thing2!
        try:
            columns = [thing2._id36 for thing2 in thing2s]
            results = cls._cf.get(thing1._id36, columns)
        except NotFoundException:
            results = {}

        # return the data in the expected format
        if not thing2s_is_single:
            # {(thing1, thing2) : value}
            thing2s_by_id = {thing2._id36 : thing2 for thing2 in thing2s}
            return {(thing1, thing2s_by_id[k]) : v
                    for k, v in results.iteritems()}
        else:
            if results:
                assert len(results) == 1
                return results.values()[0]
            else:
                raise NotFound("<%s %r>" % (cls.__name__, (thing1._id36,
                                                           thing2._id36)))
开发者ID:AHAMED750,项目名称:reddit,代码行数:43,代码来源:tdb_cassandra.py


示例11: change_password

def change_password(user, newpassword):
    user.password = bcrypt_password(newpassword)
    user._commit()
    LastModified.touch(user._fullname, 'Password')
    return True
开发者ID:XPRIYA,项目名称:HMWK2PartB,代码行数:5,代码来源:account.py


示例12: _fast_query

    def _fast_query(cls, thing1s, thing2s, properties = None, **kw):
        """Find all of the relations of this class between all of the
           members of thing1_ids and thing2_ids"""
        thing1s, thing1s_is_single = tup(thing1s, True)
        thing2s, thing2s_is_single = tup(thing2s, True)

        if not thing1s or not thing2s:
            return {}

        # grab the last time each thing1 modified this relation class so we can
        # know which relations not to even bother looking up
        if thing1s:
            from r2.models.last_modified import LastModified
            fullnames = [cls._thing1_cls._fullname_from_id36(thing1._id36)
                         for thing1 in thing1s]
            timestamps = LastModified.get_multi(fullnames,
                                                cls._cf.column_family)

        # build up a list of ids to look up, throwing out the ones that the
        # timestamp fetched above indicates are pointless
        ids = set()
        thing1_ids, thing2_ids = {}, {}
        for thing1 in thing1s:
            last_modification = timestamps.get(thing1._fullname)

            if not last_modification:
                continue

            for thing2 in thing2s:
                key = cls._rowkey(thing1._id36, thing2._id36)

                if key in ids:
                    continue

                if thing2._date > last_modification:
                    continue

                ids.add(key)
                thing2_ids[thing2._id36] = thing2
            thing1_ids[thing1._id36] = thing1

        # all relations must load these properties, even if unrequested
        if properties is not None:
            properties = set(properties)

            properties.add('thing1_id')
            properties.add('thing2_id')

        rels = {}
        if ids:
            rels = cls._byID(ids, properties=properties).values()

        if thing1s_is_single and thing2s_is_single:
            if rels:
                assert len(rels) == 1
                return rels[0]
            else:
                raise NotFound("<%s %r>" % (cls.__name__,
                                            cls._rowkey(thing1s[0]._id36,
                                                        thing2s[0]._id36)))

        return dict(((thing1_ids[rel.thing1_id], thing2_ids[rel.thing2_id]), rel)
                    for rel in rels)
开发者ID:JackePeng,项目名称:reddit,代码行数:63,代码来源:tdb_cassandra.py


示例13: add_comments

 def add_comments(self, comments):
     impl = self.IMPLEMENTATIONS[self.link.comment_tree_version]
     impl.add_comments(self, comments)
     utils.set_last_modified(self.link, 'comments')
     LastModified.touch(self.link._fullname, 'Comments')
开发者ID:0xcd03,项目名称:reddit,代码行数:5,代码来源:comment_tree.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python link.Comment类代码示例发布时间:2022-05-26
下一篇:
Python keyvalue.NamedGlobals类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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