예제 #1
0
파일: review.py 프로젝트: santoshpy/manabi
def rest_card(request, card_id):
    '''
    Used for retrieving a specific card for reviewing it,
    or for submitting the grade of a card that has just been reviewed.
    '''
    #TODO-OLD refactor into facts (or no???)
    if request.method == 'GET':
        card = get_object_or_404(Card, pk=card_id)
        return card.to_api_dict()
    elif request.method == 'POST':
        # `duration` is in seconds (the time taken from viewing the card
        # to clicking Show Answer).
        params = clean_query(request.POST, {
            'grade': int,
            'duration': float,
            'questionDuration': float
        })

        if 'grade' in request.POST:
            # This is a card review.
            #
            card = get_object_or_404(Card, pk=card_id)

            if card.owner != request.user:
                raise PermissionDenied('You do not own this flashcard.')

            card.review(params['grade'],
                        duration=params.get('duration'),
                        question_duration=params.get('questionDuration'))

            return {'success': True}
예제 #2
0
파일: review.py 프로젝트: aehlke/manabi
def rest_card(request, card_id):
    """
    Used for retrieving a specific card for reviewing it,
    or for submitting the grade of a card that has just been reviewed.
    """
    # TODO-OLD refactor into facts (or no???)
    if request.method == "GET":
        card = get_object_or_404(Card, pk=card_id)
        return card.to_api_dict()
    elif request.method == "POST":
        # `duration` is in seconds (the time taken from viewing the card
        # to clicking Show Answer).
        params = clean_query(request.POST, {"grade": int, "duration": float, "questionDuration": float})

        if "grade" in request.POST:
            # This is a card review.
            #
            card = get_object_or_404(Card, pk=card_id)

            if card.owner != request.user:
                raise PermissionDenied("You do not own this flashcard.")

            card.review(
                params["grade"], duration=params.get("duration"), question_duration=params.get("questionDuration")
            )

            return {"success": True}
예제 #3
0
파일: api.py 프로젝트: santoshpy/manabi
    def post(self, request, **kwargs):
        # `duration` is in seconds (the time taken from viewing the card
        # to clicking Show Answer).
        params = clean_query(request.POST, {
            'grade': int,
            'duration': float,
            'question_duration': float,
        })

        card = self.get_object()

        card.review(params['grade'],
                    duration=params.get('duration'),
                    question_duration=params.get('question_duration'))

        return self.responses.no_content()
예제 #4
0
    def post(self, request, **kwargs):
        # `duration` is in seconds (the time taken from viewing the card
        # to clicking Show Answer).
        params = clean_query(request.POST, {
            'grade': int,
            'duration': float,
            'question_duration': float,
        })

        card = self.get_object()

        card.review(params['grade'],
                    duration=params.get('duration'),
                    question_duration=params.get('question_duration'))

        return self.responses.no_content()
예제 #5
0
    def post(self, request, **kwargs):
        # `duration` is in seconds (the time taken from viewing the card
        # to clicking Show Answer).
        params = clean_query(request.POST, {
            'grade': int,
            'duration': float,
            'questionDuration': float
        })

        card = get_object_or_404(models.Card, pk=self.kwargs.get('pk'))

        if card.owner != request.user:
            raise PermissionDenied('You do not own this flashcard.')

        card.review(params['grade'],
                    duration=params.get('duration'),
                    question_duration=params.get('questionDuration'))

        return self.responses.no_content()
예제 #6
0
    def post(self, request, **kwargs):
        # `duration` is in seconds (the time taken from viewing the card 
        # to clicking Show Answer).
        params = clean_query(request.POST, {
            'grade': int,
            'duration': float,
            'questionDuration': float
        })

        card = get_object_or_404(models.Card, pk=self.kwargs.get('pk')) 

        if card.owner != request.user:
            raise PermissionDenied('You do not own this flashcard.')

        card.review(
            params['grade'],
            duration=params.get('duration'),
            question_duration=params.get('questionDuration'))

        return self.responses.no_content()
예제 #7
0
파일: api.py 프로젝트: santoshpy/manabi
    def get(self, request, **kwargs):
        params = clean_query(request.GET, self.query_structure)

        count = params.get('count', 5)

        next_cards = models.Card.objects.next_cards(
            request.user,
            count,
            excluded_ids=params.get('excluded_cards', []),
            session_start=params.get('session_start'),
            deck=self.get_deck(),
            early_review=params.get('early_review'),
            learn_more=params.get('learn_more'),
        )

        #FIXME need to account for 0 cards returned

        # Assemble a list of the cards to be serialized.
        return self.render_to_response({
            'cards': [CardResource(card).get_data() for card in next_cards],
        })
예제 #8
0
    def get(self, request, **kwargs):
        params = clean_query(request.GET, self.query_structure)

        count = params.get('count', 5)

        next_cards = models.Card.objects.next_cards(
            request.user,
            count,
            excluded_ids=params.get('excluded_cards', []),
            session_start=params.get('session_start'),
            deck=self.get_deck(),
            early_review=params.get('early_review'),
            learn_more=params.get('learn_more'),
        )

        #FIXME need to account for 0 cards returned

        # Assemble a list of the cards to be serialized.
        return self.render_to_response({
            'cards': [CardResource(card).get_data() for card in next_cards],
        })
예제 #9
0
def rest_deck(request, deck_id):
    deck = get_deck_or_404(request.user, deck_id)

    if request.method == 'DELETE':
        if deck.subscriber_decks.filter(active=True).exists():
            deck.active = False
            deck.save()
        else:
            deck.delete_cascading()
    elif request.method == 'PUT':
        params = clean_query(request.POST, {'shared': bool})
        # change shared status
        if params.get('shared') is not None:
            if params['shared']:
                if deck.synchronized_with:
                    raise ApiException
                deck.share()
            else:
                if not deck.shared:
                    raise ApiException
                deck.unshare()
        return {'shared': deck.shared}
예제 #10
0
def rest_deck(request, deck_id):
    deck = get_deck_or_404(request.user, deck_id)

    if request.method == 'DELETE':
        if deck.subscriber_decks.filter(active=True).exists():
            deck.active = False
            deck.save()
        else:
            deck.delete_cascading()
    elif request.method == 'PUT':
        params = clean_query(request.POST, {'shared': bool})
        # change shared status
        if params.get('shared') is not None:
            if params['shared']:
                if deck.synchronized_with:
                    raise ApiException
                deck.share()
            else:
                if not deck.shared:
                    raise ApiException
                deck.unshare()
        return {'shared': deck.shared}
예제 #11
0
 def post(self, request, **kwargs):
     deck = get_deck_or_404(request.user, kwargs.get('pk'), must_own=True)
     params = clean_query(request.POST, {'suspended': bool})
     deck.suspended = params.get('suspended', deck.suspended)
     deck.save()
     return self.render_to_response({'suspended': deck.suspended})
예제 #12
0
 def post(self, request, **kwargs):
     deck = get_deck_or_404(request.user, kwargs.get('pk'), must_own=True)
     params = clean_query(request.POST, {'suspended': bool})
     deck.suspended = params.get('suspended', deck.suspended)
     deck.save()
     return self.render_to_response({'suspended': deck.suspended})