Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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
Ejemplo n.º 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)]
Ejemplo n.º 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)]
Ejemplo n.º 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)]
Ejemplo n.º 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)]
Ejemplo n.º 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())
Ejemplo n.º 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]
Ejemplo n.º 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]
Ejemplo n.º 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())
Ejemplo n.º 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]}
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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]
Ejemplo n.º 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)]
Ejemplo n.º 18
0
 def save(self, *args, **kwargs):
     if self.changed():
         self.updated = StrInt()
     return super(Resource, self).save(*args, **kwargs)
Ejemplo n.º 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)]
Ejemplo n.º 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]