コード例 #1
0
class CurrentTag(Model):
    # key is flattened tag
    current_batch = ForeignKey(Batch, null=True)
    tag = Tag()
    metadata = Dynamic(Unicode())

    @staticmethod
    def _flatten_tag(tag):
        return "%s:%s" % tag

    @staticmethod
    def _split_key(key):
        return tuple(key.split(':', 1))

    @classmethod
    def _tag_and_key(cls, tag_or_key):
        if isinstance(tag_or_key, tuple):
            # key looks like a tag
            tag, key = tag_or_key, cls._flatten_tag(tag_or_key)
        else:
            tag, key = cls._split_key(tag_or_key), tag_or_key
        return tag, key

    def __init__(self, manager, key, _riak_object=None, **kw):
        tag, key = self._tag_and_key(key)
        if _riak_object is None:
            kw['tag'] = tag
        super(CurrentTag, self).__init__(manager, key,
                                         _riak_object=_riak_object, **kw)

    @classmethod
    def load(cls, manager, key, result=None):
        _tag, key = cls._tag_and_key(key)
        return super(CurrentTag, cls).load(manager, key, result)
コード例 #2
0
ファイル: message_store.py プロジェクト: musabaloyi/vumi
class Batch(Model):
    # key is batch_id
    tags = ListOf(Tag())
    metadata = Dynamic(Unicode())
コード例 #3
0
class BatchVNone(Model):
    bucket = 'batch'

    # key is batch_id
    tags = ListOf(Tag())
    metadata = Dynamic(Unicode())
コード例 #4
0
ファイル: test_fields.py プロジェクト: Nagato23/vumi
 def test_validate(self):
     t = Tag()
     t.validate(("pool", "tagname"))
     self.assertRaises(ValidationError, t.validate, ["pool", "tagname"])
     self.assertRaises(ValidationError, t.validate, ("pool",))
コード例 #5
0
ファイル: test_fields.py プロジェクト: Nagato23/vumi
 def test_from_riak(self):
     t = Tag()
     self.assertEqual(t.from_riak(["pool", "tagname"]), ("pool", "tagname"))
コード例 #6
0
ファイル: test_fields.py プロジェクト: Nagato23/vumi
 def test_to_riak(self):
     t = Tag()
     self.assertEqual(t.to_riak(("pool", "tagname")), ["pool", "tagname"])
コード例 #7
0
 def test_validate(self):
     t = Tag()
     t.validate(("pool", "tagname"))
     self.assertRaises(ValidationError, t.validate, ["pool", "tagname"])
     self.assertRaises(ValidationError, t.validate, ("pool", ))
コード例 #8
0
 def test_from_riak(self):
     t = Tag()
     self.assertEqual(t.from_riak(["pool", "tagname"]), ("pool", "tagname"))
コード例 #9
0
 def test_to_riak(self):
     t = Tag()
     self.assertEqual(t.to_riak(("pool", "tagname")), ["pool", "tagname"])