Exemplo n.º 1
0
    def get_lesson_new_cards(
        self,
        is_latest: bool,
        user,
        deck_id: int = None,
        category: str = None,
        complete_lte: int = 99,
        complete_gte: int = None,
        ordering: str = None,
    ) -> list:
        """
        Get the new cards for a lesson
        """
        complete_lte = complete_lte if complete_lte else 99
        query = self.filter(created_by=user,
                            complete__lte=complete_lte).select_related(
                                'created_by', 'modified_by',
                                'deck').order_by('?')
        if ordering:
            query = query.order_by(ordering)
        if complete_gte:
            query = query.filter(complete__gte=complete_gte)
        if deck_id:
            query = query.filter(deck_id=deck_id)
        if category:
            query = query.filter(category=category)
        if is_latest:
            date = arrow.utcnow().replace(
                hour=0, minute=0, second=0, microsecond=0).shift(
                    days=-config.get('lesson_latest_days', user)).datetime
            query = query.filter(created__gte=date)

        return query[:config.get('cards_per_lesson', user)]
Exemplo n.º 2
0
 def get_lesson_learned_cards(self, user) -> list:
     """
     Get the learned cards for a lesson
     """
     query = self.filter(created_by=user, complete=100).select_related(
         'created_by', 'modified_by', 'deck').order_by('?')
     return query[:config.get('cards_to_repeat', user)]
Exemplo n.º 3
0
 def translation(request):
     """
     Returns translations for a word
     """
     result = translate(
         request.GET.get('word'),
         config.get('language', request.user),
     )
     return Response(result, status=200)
Exemplo n.º 4
0
    def test_calc_api_cache(self):
        """
        Should cache settings in memory
        """
        admin = User.objects.get(username='******')
        clear_mermory_cache(admin)
        with self.assertNumQueries(2):
            assert get('attempts_to_remember', admin) == 10
        with self.assertNumQueries(0):
            assert get('attempts_to_remember', admin) == 10

        user_settings = Settings.objects.get_by_user(admin)
        user_settings.attempts_to_remember = 5
        user_settings.save()

        with self.assertNumQueries(1):
            assert get('attempts_to_remember', admin) == 5
        with self.assertNumQueries(0):
            assert get('attempts_to_remember', admin) == 5
Exemplo n.º 5
0
def test_settings_get_default():
    """
    Should return the default value if the user is not provided
    """
    assert get('attempts_to_remember') == 10