#!/usr/bin/env python
# -*- coding: utf-8 -*-
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()

@@ -43,64 +43,8 @@
 -*-%0A
-from django.core.exceptions import ImproperlyConfigured%0A
 from
@@ -334,19 +334,23 @@
     
-nam
+templat
 es = %5B%5D%0A
     
@@ -345,16 +345,17 @@
 es = %5B%5D%0A
+%0A
         
@@ -398,24 +398,25 @@
 lder()%0A%0A
+%0A
         
 names.ap
@@ -399,35 +399,39 @@
 der()%0A%0A%0A        
-nam
+templat
 es.append(u'%7B%7D/%7B
@@ -420,25 +420,24 @@
 ates.append(
-u
 '%7B%7D/%7B%7D/%7B%7D.ht
@@ -429,24 +429,31 @@
 nd('%7B%7D/%7B%7D/%7B%7D
+/detail
 .html'.forma
@@ -454,29 +454,16 @@
 .format(
-%0A            
 domain_f
@@ -472,24 +472,134 @@
 der,
- self.long_slug,
+%0A                                                       self.long_slug,%0A                                                      
  sel
@@ -615,19 +615,23 @@
         
-nam
+templat
 es.appen
@@ -636,15 +636,21 @@
 end(
-u
 '%7B%7D/%7B%7D
+/detail
 .htm
@@ -677,26 +677,8 @@
 der,
- self.long_slug))%0A
 %0A   
@@ -686,13 +686,8 @@
     
-try:%0A
     
@@ -698,122 +698,121 @@
     
-names = names + super(DetailView, self).get_template_names()%0A        except ImproperlyConfigured:%0A            pass
+                                self.long_slug))%0A        templates.append('%7B%7D/detail.html'.format(domain_folder))
 %0A%0A  
@@ -824,19 +824,23 @@
  return 
-nam
+templat
 es%0A%0A    

Fix opps template engine (name list) on DetailView