Example #1
0
 def get(self, request):
     '''
     List the available top-level resource URLs.
     '''
     context = {
         'deck_list_url': reverse('rest-deck_list'),
         'shared_deck_list_url': reverse('rest-shared_deck_list'),
         'next_cards_for_review_url': reverse('rest-next_cards_for_review'),
         'review_undo_stack_url': reverse('rest-review_undo_stack'),
         'all_decks_url': reverse('rest-all_decks'),
     }
     return self.render_to_response(context)
Example #2
0
 def get(self, request):
     '''
     List the available top-level resource URLs.
     '''
     context = {
         'deck_list_url': reverse('rest-deck_list'),
         'shared_deck_list_url': reverse('rest-shared_deck_list'),
         'next_cards_for_review_url': reverse(
                 'rest-next_cards_for_review'),
         'review_undo_stack_url': reverse('rest-review_undo_stack'),
         'all_decks_url': reverse('rest-all_decks'),
     }
     return self.render_to_response(context)
Example #3
0
    def post(self, request, **kwargs):
        user = self.request.user
        deck = get_deck_or_404(user, self.kwargs.get('pk'))

        # Is it already this user's deck?
        if deck.owner == user:
            return self.responses.see_other(
                reverse('rest-deck', args=[deck.id]))

        # Check if the user is aready subscribed to this deck.
        subscriber_deck = deck.get_subscriber_deck_for_user(user)
        if subscriber_deck:
            return self.responses.see_other(
                reverse('rest-deck', args=[subscriber_deck.id]))

        # Create the new subscriber deck and give its URL.
        new_deck = deck.subscribe(user)
        return self.responses.created(reverse('rest-deck', args=[new_deck.id]))
Example #4
0
    def post(self, request, **kwargs):
        user = self.request.user
        deck = get_deck_or_404(user, self.kwargs.get('pk'))

        # Is it already this user's deck?
        if deck.owner == user:
            return self.responses.see_other(
                    reverse('rest-deck', args=[deck.id]))
        
        # Check if the user is aready subscribed to this deck.
        subscriber_deck = deck.get_subscriber_deck_for_user(user)
        if subscriber_deck:
            return self.responses.see_other(
                    reverse('rest-deck', args=[subscriber_deck.id]))
                    

        # Create the new subscriber deck and give its URL.
        new_deck = deck.subscribe(user)
        return self.responses.created(
                reverse('rest-deck', args=[new_deck.id]))
Example #5
0
    def get_object(self):
        deck = get_deck_or_404(self.request.user, self.kwargs.get('pk'))

        # If the user is already subscribed to this deck,
        # redirect to their subscribed copy.
        subscriber = deck.get_subscriber_deck_for_user(self.request.user)
        if subscriber:
            raise HttpTemporaryRedirectException(
                    reverse('rest-deck', args=[subscriber.id]))

        return deck
Example #6
0
    def get_object(self):
        deck = get_deck_or_404(self.request.user, self.kwargs.get('pk'))

        # If the user is already subscribed to this deck,
        # redirect to their subscribed copy.
        subscriber = deck.get_subscriber_deck_for_user(self.request.user)
        if subscriber:
            raise HttpTemporaryRedirectException(
                reverse('rest-deck', args=[subscriber.id]))

        return deck
Example #7
0
    def get_context_data(self, *args, **kwargs):
        '''
        Add `request.user`-dependent fields, for sharing or subscribing.
        '''
        context = super(Deck, self).get_context_data(*args, **kwargs)
        deck = self.get_object()

        context['owned_by_current_user'] = deck.owner == self.request.user

        # add the review-related data.
        if context['owned_by_current_user']:
            context.update(review_start_context(self.request, deck))
        else:
            context['subscription_url'] = reverse(
                    'rest-deck_subscription', args=[deck.id])

        return context
Example #8
0
    def get_context_data(self, *args, **kwargs):
        '''
        Add `request.user`-dependent fields, for sharing or subscribing.
        '''
        context = super(Deck, self).get_context_data(*args, **kwargs)
        deck = self.get_object()

        context['owned_by_current_user'] = deck.owner == self.request.user

        # add the review-related data.
        if context['owned_by_current_user']:
            context.update(review_start_context(self.request, deck))
        else:
            context['subscription_url'] = reverse('rest-deck_subscription',
                                                  args=[deck.id])

        return context
Example #9
0
 def get_url(self):
     return reverse('rest-all_decks')
Example #10
0
 def get_url(self):
     return reverse('rest-shared_deck_list')
Example #11
0
 def get_url(self):
     return reverse('rest-all_decks')
Example #12
0
 def get_url(self):
     return reverse('rest-shared_deck_list')