From b8253918fc5e7c28b146e83dc1c44b91ecfda1e7 Mon Sep 17 00:00:00 2001 From: Andrew Buss Date: Wed, 20 May 2015 00:12:55 -0700 Subject: [PATCH] fix feed returning hidden cards --- flashcards/models.py | 7 +++---- flashcards/tests/test_api.py | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/flashcards/models.py b/flashcards/models.py index a092180..a995dd3 100644 --- a/flashcards/models.py +++ b/flashcards/models.py @@ -313,7 +313,6 @@ class Section(Model): """ return self.whitelist.filter(email=user.email).exists() - def enroll(self, user): if user.sections.filter(pk=self.pk).exists(): raise ValidationError('User is already enrolled in this section') @@ -339,10 +338,9 @@ class Section(Model): 0].short_start_time else: data = '' - cache.set("section_%d_lecture_times" % self.pk, data, 24*60*60) + cache.set("section_%d_lecture_times" % self.pk, data, 24 * 60 * 60) return data - @property def long_name(self): return '%s %s (%s)' % (self.course_title, self.lecture_times, self.instructor) @@ -352,7 +350,8 @@ class Section(Model): return '%s %s' % (self.department_abbreviation, self.course_num) def get_feed_for_user(self, user): - qs = Flashcard.objects.filter(section=self).exclude(userflashcard__user=user).order_by('pushed') + qs = Flashcard.objects.filter(section=self).exclude(flashcardhide__user=user).exclude( + userflashcard__user=user).order_by('pushed') return qs def get_cards_for_user(self, user): diff --git a/flashcards/tests/test_api.py b/flashcards/tests/test_api.py index 9a7f82f..b7f0de7 100644 --- a/flashcards/tests/test_api.py +++ b/flashcards/tests/test_api.py @@ -358,6 +358,10 @@ class SectionViewSetTest(APITestCase): response = self.client.get('/api/sections/{}/feed/'.format(self.section.pk)) self.assertEqual(response.status_code, HTTP_200_OK) self.assertEqual(response.data[0]['id'], 1) + self.flashcard.hide_from(self.user) + response = self.client.get('/api/sections/{}/feed/'.format(self.section.pk)) + self.assertEqual(response.status_code, HTTP_200_OK) + self.assertNotEqual(response.data[0]['id'], 1) def test_section_ordered_deck(self): self.user.sections.add(self.section) -- 1.9.1