Esempio n. 1
0
def test_safesort():
    from datetime import datetime
    
    y2000 = datetime(2000, 1, 1)
    y2005 = datetime(2005, 1, 1)
    y2010 = datetime(2010, 1, 1)
    
    assert h.safesort([y2005, y2010, y2000, None]) == [None, y2000, y2005, y2010]
    assert h.safesort([y2005, y2010, y2000, None], reverse=True) == [y2010, y2005, y2000, None]
    
    assert h.safesort([[y2005], [None]], key=lambda x: x[0]) == [[None], [y2005]]
Esempio n. 2
0
def test_safesort():
    from datetime import datetime

    y2000 = datetime(2000, 1, 1)
    y2005 = datetime(2005, 1, 1)
    y2010 = datetime(2010, 1, 1)

    assert h.safesort([y2005, y2010, y2000, None]) == [None, y2000, y2005, y2010]
    assert h.safesort([y2005, y2010, y2000, None], reverse=True) == [y2010, y2005, y2000, None]

    assert h.safesort([[y2005], [None]], key=lambda x: x[0]) == [[None], [y2005]]
Esempio n. 3
0
 def get_seeds(self, sort=False):
     seeds = [Seed(self, s) for s in self.seeds]
     if sort:
         seeds = h.safesort(seeds,
                            reverse=True,
                            key=lambda seed: seed.last_update)
     return seeds
Esempio n. 4
0
    def _get_lists(self, limit=50, offset=0, sort=True):
        # cache the default case
        if limit == 50 and offset == 0:
            keys = self._get_lists_cached()
        else:
            keys = self._get_lists_uncached(limit=limit, offset=offset)

        lists = self._site.get_many(keys)
        if sort:
            lists = h.safesort(lists, reverse=True, key=lambda list: list.last_modified)
        return lists
Esempio n. 5
0
 def get_lists(self, limit=1000, offset=0, sort=True):
     q = {
         "type": "/type/list",
         "seeds": self.get_seed(),
         "limit": limit,
         "offset": offset
     }
     keys = web.ctx.site.things(q)
     lists = web.ctx.site.get_many(keys)
     if sort:
         lists = h.safesort(lists, reverse=True, key=lambda list: list.last_modified)
     return lists
Esempio n. 6
0
    def get_seeds(self, sort=False, resolve_redirects=False):
        seeds = []
        for s in self.seeds:
            seed = Seed(self, s)
            max_checks = 10
            while resolve_redirects and seed.type == 'redirect' and max_checks:
                seed = Seed(self, web.ctx.site.get(seed.document.location))
                max_checks -= 1
            seeds.append(seed)

        if sort:
            seeds = h.safesort(seeds, reverse=True, key=lambda seed: seed.last_update)

        return seeds
Esempio n. 7
0
    def get_lists(self, seed=None, limit=100, offset=0, sort=True):
        """Returns all the lists of this user.

        When seed is specified, this returns all the lists which contain the
        given seed.

        seed could be an object or a string like "subject:cheese".
        """
        # cache the default case
        if seed is None and limit == 100 and offset == 0:
            keys = self._get_lists_cached()
        else:
            keys = self._get_lists_uncached(seed=seed, limit=limit, offset=offset)

        lists = self._site.get_many(keys)
        if sort:
            lists = h.safesort(lists, reverse=True, key=lambda list: list.last_modified)
        return lists
Esempio n. 8
0
 def get_seeds(self, sort=False):
     seeds = [Seed(self, s) for s in self.seeds]
     if sort:
         seeds = h.safesort(seeds, reverse=True, key=lambda seed: seed.last_update)
     return seeds