Commit 41819dd7ec2f22a04db83459c33e31c2b7d16d99

Authored by Rohan Rangray
Exists in master

Resolved merge conflicts in view.py and test_api.py

Showing 4 changed files Side-by-side Diff

... ... @@ -2,6 +2,8 @@
2 2  
3 3 All of these commands should be run from this directory (the one containing README.md)
4 4  
  5 +Virtualenv for Windows creates a dir inexplicably named scripts rather than bin. So substitute venv/bin for venv/scripts if you are on Windows.
  6 +
5 7 Install virtualenv before continuing. This is most easily accomplished with:
6 8  
7 9 pip install virtualenv
flashcards/models.py View file @ 41819dd
... ... @@ -164,7 +164,7 @@
164 164 :param user:
165 165 :return: A queryset with all cards that should be visible to a user.
166 166 """
167   - return cls.objects.filter(is_hidden=False).exclude(userflashcard__user=user, userflashcard__pulled=None)
  167 + return cls.objects.filter(is_hidden=False).exclude(flashcardhide__user=user)
168 168  
169 169  
170 170 class UserFlashcardQuiz(Model):
flashcards/tests/test_api.py View file @ 41819dd
... ... @@ -260,4 +260,8 @@
260 260 self.user.save()
261 261 response = self.client.get('/api/sections/1/deck/')
262 262 self.assertEqual(response.status_code, HTTP_200_OK)
  263 +
  264 + def test_section_ordered_deck(self):
  265 + response = self.client.get('/api/sections/1/ordered_deck/')
  266 + self.assertEqual(response.status_code, HTTP_200_OK)
flashcards/views.py View file @ 41819dd
... ... @@ -16,7 +16,6 @@
16 16 from rest_framework.response import Response
17 17 from rest_framework.exceptions import AuthenticationFailed, NotAuthenticated, ValidationError, PermissionDenied
18 18 from simple_email_confirmation import EmailAddress
19   -from datetime import datetime
20 19  
21 20  
22 21 class SectionViewSet(ReadOnlyModelViewSet):
... ... @@ -31,9 +30,7 @@
31 30 Gets flashcards for a section, excluding hidden cards.
32 31 Returned in strictly chronological order (material date).
33 32 """
34   - flashcards = Flashcard.cards_visible_to(request.user).filter( \
35   - section=self.get_object(), is_hidden=False).all()
36   -
  33 + flashcards = Flashcard.cards_visible_to(request.user).filter(section=self.get_object())
37 34 return Response(FlashcardSerializer(flashcards, many=True).data)
38 35  
39 36 @detail_route(methods=['post'], permission_classes=[IsAuthenticated])
... ... @@ -88,6 +85,16 @@
88 85 Gets the contents of a user's deck for a given section.
89 86 """
90 87 qs = request.user.get_deck(self.get_object())
  88 + serializer = FlashcardSerializer(qs, many=True)
  89 + return Response(serializer.data)
  90 +
  91 + @detail_route(methods=['get'], permission_classes=[IsAuthenticated])
  92 + def ordered_deck(self, request, pk):
  93 + """
  94 + Get a chronological order by material_date of flashcards for a section.
  95 + This excludes hidden card.
  96 + """
  97 + qs = request.user.get_deck(self.get_object()).order_by('-material_date')
91 98 serializer = FlashcardSerializer(qs, many=True)
92 99 return Response(serializer.data)
93 100