def get_context_data(self, **kwargs):
        """ Returns the context data to provide to the template. """
        context = super().get_context_data(**kwargs)

        # Insert the considered topic and the associated forum into the context
        topic = self.get_topic()
        context['topic'] = topic
        context['forum'] = topic.forum

        # Handles the case when a poll is associated to the topic
        try:
            if hasattr(topic, 'poll') and topic.poll.options.exists():
                context['poll'] = topic.poll
                context['poll_form'] = self.poll_form_class(poll=topic.poll)
                context['view_results_action'] = self.request.GET.get('view_results', None)
                context['change_vote_action'] = self.request.GET.get('change_vote', None)
        except ObjectDoesNotExist:  # pragma: no cover
            pass

        return context
def get_context_data ( self , ** kwargs ) : context = super ( ) . get_context_data ( ** kwargs ) topic = self . get_topic ( ) context [ 'topic' ] = topic context [ 'forum' ] = topic . forum try : if hasattr ( topic , 'poll' ) and topic . poll . options . exists ( ) : context [ 'poll' ] = topic . poll context [ 'poll_form' ] = self . poll_form_class ( poll = topic . poll ) context [ 'view_results_action' ] = self . request . GET . get ( 'view_results' , None ) context [ 'change_vote_action' ] = self . request . GET . get ( 'change_vote' , None ) except ObjectDoesNotExist : pass return context
Returns the context data to provide to the template.