Permalink
Browse files

fix delete handling

  • Loading branch information...
1 parent b9dd85b commit 9d28d36aacb00443a7ec28c52ae293a73abc9b5c @aehlke committed Mar 26, 2012
Showing with 14 additions and 4 deletions.
  1. +5 −1 apps/flashcards/models/managers/cardmanager.py
  2. +9 −3 apps/flashcards/models/redis_models.py
View
6 apps/flashcards/models/managers/cardmanager.py
@@ -346,19 +346,23 @@ def of_user(self, user, with_upstream=False):
user_cards = user_cards.without_upstream(user)
return user_cards
-
+
def without_upstream(self, user):
'''
Excludes cards that the subscribed user doesn't yet own,
but which are in a synchronized deck this user owns.
'''
+ #card_ids = redis.smembers('cards:owner:%s' % user.id)
+ #return self.filter(id__in=card_ids)
return self.filter(fact__deck__owner=user)
def of_upstream(self, user):
'''
Filters to include only upstream cards (which the
user hasn't copied yet).
'''
+ #card_ids = redis.smembers('cards:owner:%s' % user.id)
+ #return self.exclude(id__in=card_ids)
return self.exclude(fact__deck__owner=user)
def with_tags(self, tags):
View
12 apps/flashcards/models/redis_models.py
@@ -45,6 +45,10 @@ def update_ease_factor(self):
else:
redis.zrem(key, self.card.id)
+ def update_card_owner(self):
+ key = 'cards:owner:%s' % self.card.fact.deck.owner_id
+ redis.sadd(key, self.card.id)
+
def after_review(self):
''' Call after a card is reviewed. '''
#self._update_review_date()
@@ -55,11 +59,13 @@ def after_review(self):
def update_all(self):
self.update_deck()
self.update_ease_factor()
+ self.update_card_owner()
def delete(self):
deck_id = card.fact.deck_id
- redis.srem('cards:deck:' + deck_id, card.id)
- redis.zrem('ease_factor:deck:' + deck_id, card.id)
+ redis.srem('cards:deck:%s' % deck_id, card.id)
+ redis.zrem('ease_factor:deck:%s' % deck_id, card.id)
+ redis.srem('cards:owner:%s' % card.fact.deck.owner_id, card.id)
@@ -73,5 +79,5 @@ def card_saved(sender, card, created, **kwargs):
@receiver(post_delete, sender=Card, dispatch_uid='card_deleted_redis')
def card_deleted(sender, card, **kwargs):
- redis.
+ card.redis.delete()

0 comments on commit 9d28d36

Please sign in to comment.