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)
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)
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]))
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]))
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
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
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
def get_url(self): return reverse('rest-all_decks')
def get_url(self): return reverse('rest-shared_deck_list')