Exemple #1
0
    def __init__(self, data, date, delta):
        assert data, "data is required"
        if len(data) > 0:
            assert date, "date is required"
            assert delta, "delta is required"
            data = set(data)
            model_class = type(lists.first(data))
            assert lists.all(lambda e: type(e) == model_class, data), "data contain items of different types"
            self.stored = model_class.objects.filter(pk__in=[e.id for e in data])
            db = map(lambda e: dict(pk=e.id, date=date(e)), self.stored)
            non_cached_entities = set(filter(lambda e: e.pk not in [x["pk"] for x in db], data))
            self.cached = data - non_cached_entities
            last_update_date = lambda e: filter(lambda x: x["pk"] == e.pk, db)[0]["date"]
            expired_places = filter(lambda e: timezone.now() - last_update_date(e) > delta, self.cached)

            self.for_insert = non_cached_entities
            self.for_update = expired_places
Exemple #2
0
 def test_all(self):
     self.assertTrue(lists.all(lambda x: x > 0, [1, 2, 3]))
     self.assertFalse(lists.all(lambda x: x is None, set([None, 1])))
     self.assertFalse(lists.all(lambda x: x > 1, [0, 1, 2]))