"""Views for the at home application."""

from django.views import generic
from at_home.models import Activity, Challenge


class IndexView(generic.ListView):
    """View for the at home application homepage."""

    template_name = "at_home/index.html"
    model = Activity
    context_object_name = "activities"


class ActivityView(generic.DetailView):
    """View for a specific activity."""

    model = Activity
    template_name = "at_home/activity.html"
    context_object_name = "activity"
    slug_url_kwarg = "activity_slug"


class ActivityChallengesView(generic.ListView):
    """View for challenges of a specific activity."""

    model = Challenge
    template_name = "at_home/activity_challenges.html"
    context_object_name = "challenge"
    slug_url_kwarg = "activity_slug"
    allow_empty = False

    def get_queryset(self, **kwargs):
        activity = Activity.objects.get(slug=self.kwargs['activity_slug'])
        return Challenge.objects.filter(activity=activity)

    def get_context_data(self, **kwargs):
        """Provide the context data for the activity view.

        Returns:
            Dictionary of context data.
        """
        context = super(ActivityChallengesView, self).get_context_data(**kwargs)
        activity = Activity.objects.get(slug=self.kwargs['activity_slug'])
        challenges = Challenge.objects.filter(activity=activity)
        context["activity"] = activity
        context["challenges"] = challenges
        context["challenge_answers"] = dict()
        return context

@@ -751,45 +751,9 @@
 enge
-%22%0A    slug_url_kwarg = %22activity_slug
+s
 %22%0A  
@@ -813,32 +813,37 @@
 wargs):%0A        
+self.
 activity = Activ
@@ -934,32 +934,37 @@
 filter(activity=
+self.
 activity)%0A%0A    d
@@ -1214,148 +1214,8 @@
 gs)%0A
-        activity = Activity.objects.get(slug=self.kwargs%5B'activity_slug'%5D)%0A        challenges = Challenge.objects.filter(activity=activity)%0A
     
@@ -1240,16 +1240,21 @@
 ity%22%5D = 
+self.
 activity
@@ -1258,97 +1258,8 @@
 ity%0A
-        context%5B%22challenges%22%5D = challenges%0A        context%5B%22challenge_answers%22%5D = dict()%0A
     

Tidy challenge view code