Skip to content

Commit

Permalink
Fixes repr for model. Adds manager.id to result sets for cleanup iden…
Browse files Browse the repository at this point in the history
…tification.
  • Loading branch information
iamteem committed May 29, 2010
1 parent 22440dc commit aea78a4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
10 changes: 8 additions & 2 deletions redisco/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ def attributes_dict(self):
"""Returns the mapping of the model attributes and their
values.
"""
h = self.db.hgetall(self.key())
h = {}
for k in self.attributes.keys():
h[k] = getattr(self, k)
for k in self.lists.keys():
h[k] = getattr(self, k)
for k in self.references.keys():
Expand Down Expand Up @@ -508,7 +510,11 @@ def __ne__(self, other):
return not self.__eq__(other)

def __repr__(self):
return "<%s %s>" % (self.key(), self.attributes_dict)
if not self.is_new():
return "<%s %s>" % (self.key(), self.attributes_dict)
print "nyak"
return "<%s %s>" % (self.__class__.__name__, self.attributes_dict)



def get_model_from_key(key):
Expand Down
8 changes: 4 additions & 4 deletions redisco/models/modelset.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _add_set_filter(self, s):
"Attribute %s is not indexed in %s class." %
(k, self.model_class.__name__))
indices.append(index)
new_set_key = "~%s" % ("+".join([self.key] + indices),)
new_set_key = "~%s.%s" % ("+".join([self.key] + indices), id(self))
s.intersection(new_set_key, *[Set(n) for n in indices])
self._expire_or_delete.append(new_set_key)
return Set(new_set_key)
Expand All @@ -189,7 +189,7 @@ def _add_set_exclusions(self, s):
"Attribute %s is not indexed in %s class." %
(k, self.model_class.__name__))
indices.append(index)
new_set_key = "~%s" % ("-".join([self.key] + indices),)
new_set_key = "~%s.%s" % ("-".join([self.key] + indices), id(self))
s.difference(new_set_key, *[Set(n) for n in indices])
self._expire_or_delete.append(new_set_key)
return Set(new_set_key)
Expand Down Expand Up @@ -236,7 +236,7 @@ def _set_with_ordering(self, skey):
ordering = ordering.lstrip('-')
else:
desc = False
new_set_key = "%s#%s" % (old_set_key, ordering)
new_set_key = "%s#%s.%s" % (old_set_key, ordering, id(self))
by = "%s->%s" % (self.model_class._key['*'], ordering)
self.db.sort(old_set_key,
by=by,
Expand All @@ -253,7 +253,7 @@ def _set_without_ordering(self, skey):
# sort by id
num, start = self._get_limit_and_offset()
old_set_key = skey
new_set_key = "%s#" % old_set_key
new_set_key = "%s#.%s" % (old_set_key, id(self))
self.db.sort(old_set_key,
store=new_set_key,
start=start,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import os

version = '0.1.dev18'
version = '0.1.dev19'

try:
from setuptools import setup
Expand Down
7 changes: 7 additions & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ def test_unicode(self):
self.assertEqual("Niña Jose", p.full_name())


def test_repr(self):
person1 = Person(first_name="Granny", last_name="Goose")
self.assertEqual("<Person {'first_name': 'Granny', 'last_name': 'Goose'}>",
repr(person1))

self.assert_(person1.save())
self.assertEqual("<Person:1 {'first_name': 'Granny', 'last_name': 'Goose'}>",
repr(person1))

def test_update(self):
person1 = Person(first_name="Granny", last_name="Goose")
Expand Down

0 comments on commit aea78a4

Please sign in to comment.