Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

verbose_name and a few methods on ds

  • Loading branch information...
commit 19fd1f595ebe2d2c08ec2b82fe5e47e160f9799b 1 parent 8d2fc25
Simon Zimmermann authored
Showing with 28 additions and 10 deletions.
  1. +22 −4 odis/__init__.py
  2. +2 −2 odis/utils.py
  3. +4 −4 tests/tests.py
View
26 odis/__init__.py
@@ -164,6 +164,16 @@ def inter(self, target, keys):
def add(self, *members):
return self.db.sadd(self.key, *members)
+ def replace(self, *members):
+ 'replace all members in a set with new members'
+ p = self.db.pipeline(transaction=True)
+ p.delete(self.key)
+ p.sadd(self.key, *members)
+ p.execute()
+
+ def all(self):
+ return iter(self)
+
def delete(self, *members):
return self.db.srem(self.key, *members)
@@ -260,6 +270,9 @@ def _associative_op(self, command, target, keys, expire=60):
def add(self, score, member):
self.db.zadd(self.key, score, member)
+ def all(self):
+ return iter(self)
+
def delete(self, *members):
return self.db.zrem(self.key, *members)
@@ -715,10 +728,11 @@ def __init__(self,
nil=False,
default=EMPTY):
'''
- `index`: Key for value maps to `pk`. lookup by value possible.
- `unique`: Only one model with a given value.
- `nil`: Allow nil value.
- `default`: Set to default value if otherwise empty. '''
+ `verbose_name`: A verbose name for the field.
+ `index`: Key for value maps to `pk`. lookup by value possible.
+ `unique`: Only one model with a given value.
+ `nil`: Allow nil value.
+ `default`: Set to default value if otherwise empty. '''
self.verbose_name = verbose_name
self.unique = unique
self.index = index or unique
@@ -1033,6 +1047,10 @@ def key_for(cls, name, **kwargs):
def key(self):
return self.key_for('obj', pk=self.pk)
+ @property
+ def errors(self):
+ return getattr(self, '_errors', {})
+
def is_valid(self):
self._errors = {}
View
4 odis/utils.py
@@ -6,9 +6,9 @@
except ImportError:
pass
-def s():
+def s(color='NoColor'):
BdbQuit_excepthook.excepthook_ori = sys.excepthook
- Pdb('LightBG').set_trace(sys._getframe().f_back)
+ Pdb(color).set_trace(sys._getframe().f_back)
def timeit(method):
def wrapper(*args, **kw):
View
8 tests/tests.py
@@ -126,7 +126,7 @@ def test_choices(self):
def test_setfield(self):
q = Qux()
q.save()
- q.sets.sadd(*[u.pk for u in self.users[:2]])
+ q.sets.add(*[u.pk for u in self.users[:2]])
self.assertEqual(list(q.sets), self.users[:2])
q2 = Qux.obj.get(pk=q.pk)
self.assertEqual(list(q2.sets), self.users[:2])
@@ -134,8 +134,8 @@ def test_setfield(self):
def test_sortedsetfield(self):
q = Qux()
q.save()
- q.sortedsets.zadd(1.0, self.users[0].pk)
- q.sortedsets.zadd(0.2, self.users[1].pk)
+ q.sortedsets.add(1.0, self.users[0].pk)
+ q.sortedsets.add(0.2, self.users[1].pk)
self.assertEqual(list(q.sortedsets), [self.users[1], self.users[0]])
def test_relfield(self):
@@ -170,7 +170,7 @@ def test_sets_with_type(self):
q = Qux()
q.save()
values = [i * 1.0 for i in range(10)]
- q.sets_float.sadd(*values)
+ q.sets_float.add(*values)
res = set(q.sets_float)
for v in values:

0 comments on commit 19fd1f5

Please sign in to comment.
Something went wrong with that request. Please try again.