Commit 28a4bd2e76e8a9fb4a37532064f8be85a8b0783c
1 parent
90b3c45f13
Exists in
master
Refactored code in accordance with the code review
Showing 2 changed files with 7 additions and 2 deletions Side-by-side Diff
flashcards/models.py
View file @
28a4bd2
... | ... | @@ -143,6 +143,11 @@ |
143 | 143 | pulled = DateTimeField(auto_now_add=True, help_text="When the user pulled the card") |
144 | 144 | flashcard = ForeignKey('Flashcard') |
145 | 145 | |
146 | + def get_mask(self): | |
147 | + if self.mask is None: | |
148 | + return self.flashcard.mask | |
149 | + return self.mask | |
150 | + | |
146 | 151 | class Meta: |
147 | 152 | # There can be at most one UserFlashcard for each User and Flashcard |
148 | 153 | unique_together = (('user', 'flashcard'),) |
flashcards/views.py
View file @
28a4bd2
... | ... | @@ -342,6 +342,7 @@ |
342 | 342 | new_flashcard = flashcard.edit(user, new_flashcard) |
343 | 343 | return Response(FlashcardSerializer(new_flashcard).data, status=HTTP_200_OK) |
344 | 344 | |
345 | + | |
345 | 346 | class UserFlashcardQuizViewSet(GenericViewSet, CreateModelMixin, UpdateModelMixin): |
346 | 347 | permission_classes = [IsAuthenticated, IsFlashcardReviewer] |
347 | 348 | queryset = UserFlashcardQuiz.objects.all() |
348 | 349 | |
... | ... | @@ -373,11 +374,10 @@ |
373 | 374 | raise ValidationError("No matching flashcard found in your decks") |
374 | 375 | |
375 | 376 | user_flashcard = user_flashcard_filter.order_by('?').first() |
376 | - mask = user_flashcard.mask.get_random_blank() | |
377 | + mask = user_flashcard.get_mask().get_random_blank() | |
377 | 378 | user_flashcard_quiz = UserFlashcardQuiz(user_flashcard=user_flashcard, |
378 | 379 | blanked_word=user_flashcard.flashcard.text[slice(*mask)]) |
379 | 380 | user_flashcard_quiz.save() |
380 | - assert user_flashcard_quiz is not None | |
381 | 381 | response = QuizResponseSerializer(instance=user_flashcard_quiz, mask=mask) |
382 | 382 | return Response(response.data, status=HTTP_200_OK) |
383 | 383 |