from ..filters import EpisodeFilters
from ..models import Episode, Program, StaticPage
from .page import PageListView
from .program import ProgramPageDetailView

__all__ = (
    "EpisodeDetailView",
    "EpisodeListView",
)


class EpisodeDetailView(ProgramPageDetailView):
    model = Episode

    def get_context_data(self, **kwargs):
        if "tracks" not in kwargs:
            kwargs["tracks"] = self.object.track_set.order_by("position")
        return super().get_context_data(**kwargs)


class EpisodeListView(PageListView):
    model = Episode
    filterset_class = EpisodeFilters
    item_template_name = "aircox/widgets/episode_item.html"
    has_headline = True
    parent_model = Program
    attach_to_value = StaticPage.ATTACH_TO_EPISODES
