Example #1
0
 def history_last(cls):
     items = cls.history.filter(StrInt.n_max(),
                                StrInt.n_min(),
                                max_results=1)
     if not items:
         return None
     return cls.get(items[0])
Example #2
0
 def history_last(cls):
     items = cls.history.filter(StrInt.n_max(),
                                StrInt.n_min(),
                                max_results=1)
     if not items:
         return None
     return cls.get(items[0])
Example #3
0
def test_strint_comparsions():
    a = StrInt(-1)
    b = StrInt(-2)
    c = StrInt.to_simple(b)
    assert isinstance(c, basestring)
    assert a > b
    assert a > c
Example #4
0
def load_all(startswith=None):
    if startswith:
        start = startswith
        end = startswith + '~'
        candids = DBResource.bucket.get_index("$key", start, end).results
    else:
        candids = DBResource.updated.filter(StrInt.p_min(), StrInt.p_max())
    return [Resource(r) for r in DBResource.multi_get(candids)]
Example #5
0
def load_all(startswith=None):
    if startswith:
        start = startswith
        end = startswith + '~'
        candids = DBResource.bucket.get_index("$key", start, end).results
    else:
        candids = DBResource.updated.filter(StrInt.p_min(), StrInt.p_max())
    return [Resource(r) for r in DBResource.multi_get(candids)]
Example #6
0
def load_updated(since=None, with_childs=True):
    if since is None:
        startkey = StrInt.p_min()
    else:
        startkey = since
    candids = DBResource.updated.filter(startkey, StrInt.p_max())
    if with_childs:
        candids = DBResource.childs(candids)
    return [Resource(r) for r in DBResource.multi_get(candids)]
Example #7
0
def load_updated(since=None, with_childs=True):
    if since is None:
        startkey = StrInt.p_min()
    else:
        startkey = since
    candids = DBResource.updated.filter(startkey, StrInt.p_max())
    if with_childs:
        candids = DBResource.childs(candids)
    return [Resource(r) for r in DBResource.multi_get(candids)]
Example #8
0
def test_updated_behaviour(rk):
    k1 = next(rk)

    _cmp = StrInt()
    r1 = create_resource(k1, {'name': 'blah'})
    r1.save()
    assert isinstance(r1._riak_object.data['updated'], basestring)
    assert not isinstance(r1.updated, basestring)
    assert r1.updated >= _cmp
    assert k1 in Resource.updated.filter(StrInt.p_min(), StrInt.p_max())
Example #9
0
def test_reversed_order_is_preserved():
    added = []
    for i in range(4):
        li = LogItem.new({'log': 'history'})
        li.save()
        added.append(li.key)
    added.reverse()
    assert list(
        LogItem.history.filter(StrInt.n_max(), StrInt.n_min(),
                               max_results=2)) == added[:2]
Example #10
0
def test_reversed_order_is_preserved():
    added = []
    for i in range(4):
        li = HistoryItem.new(str(i), {})
        li.save()
        added.append(li.key)
    added.reverse()
    assert list(HistoryItem.history.filter(StrInt.n_max(),
                                           StrInt.n_min(),
                                           max_results=2)) == added[:2]
Example #11
0
def test_updated_behaviour(rk):
    k1 = next(rk)

    _cmp = StrInt()
    r1 = create_resource(k1, {'name': 'blah'})
    r1.save()
    assert isinstance(r1._riak_object.data['updated'], basestring)
    assert not isinstance(r1.updated, basestring)
    assert r1.updated >= _cmp
    assert k1 in Resource.updated.filter(StrInt.p_min(), StrInt.p_max())
Example #12
0
def test_staged_not_indexed():
    added = []
    for i in range(3):
        li = LogItem.new({'log': 'staged'})
        li.save()
        added.append(li)

    for li in added[:2]:
        li.log = 'history'
        li.save()

    assert set(LogItem.history.filter(
        StrInt.n_max(), StrInt.n_min())) == {li.key
                                             for li in added[:2]}
Example #13
0
def test_strint_comparsions():
    a = StrInt(-1)
    b = StrInt(-2)
    c = StrInt.to_simple(b)
    assert isinstance(c, basestring)
    assert a > b
    assert a > c
Example #14
0
    def save(self):
        if any(f in self._modified_fields for
               f in HistoryItem.composite.fields):
            self.composite.reset()

        self.history = StrInt(next(NegativeCounter.get_or_create(
            'history')))
        return super(HistoryItem, self).save()
Example #15
0
    def save(self):
        if any(f in self._modified_fields for f in LogItem.composite.fields):
            self.composite.reset()

        if 'log' in self._modified_fields and self.log == 'history':
            self.history = StrInt(
                next(NegativeCounter.get_or_create('history')))
        return super(LogItem, self).save()
Example #16
0
def test_updated_only_last(rk):

    for i in range(3):
        r = create_resource(next(rk), {'name': str(i)})
        r.save()
    assert Resource.updated.filter(r.updated, StrInt.p_max()) == [r.key]
Example #17
0
def load_all():
    candids = DBResource.updated.filter(StrInt.p_min(), StrInt.p_max())
    return [Resource(r) for r in DBResource.multi_get(candids)]
Example #18
0
 def save(self, *args, **kwargs):
     if self.changed():
         self.updated = StrInt()
     return super(Resource, self).save(*args, **kwargs)
Example #19
0
def load_all():
    candids = DBResource.updated.filter(StrInt.p_min(), StrInt.p_max())
    return [Resource(r) for r in DBResource.multi_get(candids)]
Example #20
0
def test_updated_only_last(rk):

    for i in range(3):
        r = create_resource(next(rk), {'name': str(i)})
        r.save()
    assert Resource.updated.filter(r.updated, StrInt.p_max()) == [r.key]