from django.core.exceptions import ImproperlyConfigured
from django.views.generic.detail import DetailView as DjangoDetailView
from django.contrib.sites.models import get_current_site
from django.utils import timezone

from opps.views.generic.base import View


class DetailView(View, DjangoDetailView):

    def get_template_names(self):
        names = []
        domain_folder = self.get_template_folder()

        names.append(u'{}/{}/{}.html'.format(
            domain_folder, self.long_slug, self.slug))
        names.append(u'{}/{}.html'.format(domain_folder, self.long_slug))

        try:
            names = names + super(DetailView, self).get_template_names()
        except ImproperlyConfigured:
            pass

        return names

    def get_queryset(self):
        self.site = get_current_site(self.request)
        self.slug = self.kwargs.get('slug')
        self.long_slug = self.get_long_slug()
        if not self.long_slug:
            return None

        self.set_channel_rules()

        filters = {}
        filters['site_domain'] = self.site.domain
        filters['channel_long_slug'] = self.long_slug
        filters['slug'] = self.slug

        preview_enabled = self.request.user and self.request.user.is_staff

        if not preview_enabled:
            filters['date_available__lte'] = timezone.now()
            filters['published'] = True

        queryset = super(DetailView, self).get_queryset()
        return queryset.filter(**filters)._clone()

from django.views.generic.detail import DetailView as DjangoDetailView
from django.contrib.sites.models import get_current_site
from django.utils import timezone

from opps.views.generic.base import View


class DetailView(View, DjangoDetailView):

    def get_template_names(self):
        templates = []

        domain_folder = self.get_template_folder()


        templates.append('{}/{}/{}/detail.html'.format(domain_folder,
                                                       self.long_slug,
                                                       self.slug))
        templates.append('{}/{}/detail.html'.format(domain_folder,
                                                    self.long_slug))
        templates.append('{}/detail.html'.format(domain_folder))

        return templates

    def get_queryset(self):
        self.site = get_current_site(self.request)
        self.slug = self.kwargs.get('slug')
        self.long_slug = self.get_long_slug()
        if not self.long_slug:
            return None

        self.set_channel_rules()

        filters = {}
        filters['site_domain'] = self.site.domain
        filters['channel_long_slug'] = self.long_slug
        filters['slug'] = self.slug

        preview_enabled = self.request.user and self.request.user.is_staff

        if not preview_enabled:
            filters['date_available__lte'] = timezone.now()
            filters['published'] = True

        queryset = super(DetailView, self).get_queryset()
        return queryset.filter(**filters)._clone()

Fix opps template engine (name list) on DetailView
Fix opps template engine (name list) on DetailView

- from django.core.exceptions import ImproperlyConfigured
  from django.views.generic.detail import DetailView as DjangoDetailView
  from django.contrib.sites.models import get_current_site
  from django.utils import timezone
  
  from opps.views.generic.base import View
  
  
  class DetailView(View, DjangoDetailView):
  
      def get_template_names(self):
-         names = []
+         templates = []
+ 
          domain_folder = self.get_template_folder()
  
-         names.append(u'{}/{}/{}.html'.format(
-             domain_folder, self.long_slug, self.slug))
-         names.append(u'{}/{}.html'.format(domain_folder, self.long_slug))
  
-         try:
-             names = names + super(DetailView, self).get_template_names()
-         except ImproperlyConfigured:
-             pass
+         templates.append('{}/{}/{}/detail.html'.format(domain_folder,
+                                                        self.long_slug,
+                                                        self.slug))
+         templates.append('{}/{}/detail.html'.format(domain_folder,
+                                                     self.long_slug))
+         templates.append('{}/detail.html'.format(domain_folder))
  
-         return names
+         return templates
  
      def get_queryset(self):
          self.site = get_current_site(self.request)
          self.slug = self.kwargs.get('slug')
          self.long_slug = self.get_long_slug()
          if not self.long_slug:
              return None
  
          self.set_channel_rules()
  
          filters = {}
          filters['site_domain'] = self.site.domain
          filters['channel_long_slug'] = self.long_slug
          filters['slug'] = self.slug
  
          preview_enabled = self.request.user and self.request.user.is_staff
  
          if not preview_enabled:
              filters['date_available__lte'] = timezone.now()
              filters['published'] = True
  
          queryset = super(DetailView, self).get_queryset()
          return queryset.filter(**filters)._clone()
  
Fix opps template engine (name list) on DetailView
## Code Before:
from django.core.exceptions import ImproperlyConfigured
from django.views.generic.detail import DetailView as DjangoDetailView
from django.contrib.sites.models import get_current_site
from django.utils import timezone

from opps.views.generic.base import View


class DetailView(View, DjangoDetailView):

    def get_template_names(self):
        names = []
        domain_folder = self.get_template_folder()

        names.append(u'{}/{}/{}.html'.format(
            domain_folder, self.long_slug, self.slug))
        names.append(u'{}/{}.html'.format(domain_folder, self.long_slug))

        try:
            names = names + super(DetailView, self).get_template_names()
        except ImproperlyConfigured:
            pass

        return names

    def get_queryset(self):
        self.site = get_current_site(self.request)
        self.slug = self.kwargs.get('slug')
        self.long_slug = self.get_long_slug()
        if not self.long_slug:
            return None

        self.set_channel_rules()

        filters = {}
        filters['site_domain'] = self.site.domain
        filters['channel_long_slug'] = self.long_slug
        filters['slug'] = self.slug

        preview_enabled = self.request.user and self.request.user.is_staff

        if not preview_enabled:
            filters['date_available__lte'] = timezone.now()
            filters['published'] = True

        queryset = super(DetailView, self).get_queryset()
        return queryset.filter(**filters)._clone()

## Instruction:
Fix opps template engine (name list) on DetailView
## Code After:
from django.views.generic.detail import DetailView as DjangoDetailView
from django.contrib.sites.models import get_current_site
from django.utils import timezone

from opps.views.generic.base import View


class DetailView(View, DjangoDetailView):

    def get_template_names(self):
        templates = []

        domain_folder = self.get_template_folder()


        templates.append('{}/{}/{}/detail.html'.format(domain_folder,
                                                       self.long_slug,
                                                       self.slug))
        templates.append('{}/{}/detail.html'.format(domain_folder,
                                                    self.long_slug))
        templates.append('{}/detail.html'.format(domain_folder))

        return templates

    def get_queryset(self):
        self.site = get_current_site(self.request)
        self.slug = self.kwargs.get('slug')
        self.long_slug = self.get_long_slug()
        if not self.long_slug:
            return None

        self.set_channel_rules()

        filters = {}
        filters['site_domain'] = self.site.domain
        filters['channel_long_slug'] = self.long_slug
        filters['slug'] = self.slug

        preview_enabled = self.request.user and self.request.user.is_staff

        if not preview_enabled:
            filters['date_available__lte'] = timezone.now()
            filters['published'] = True

        queryset = super(DetailView, self).get_queryset()
        return queryset.filter(**filters)._clone()
