gregmuellegger / django-mobile

Detect mobile browsers and serve different template flavours to them.
http://pypi.python.org/pypi/django-mobile
BSD 3-Clause "New" or "Revised" License
560 stars 170 forks source link

Template name for Class Based View. #57

Open ghost opened 9 years ago

ghost commented 9 years ago

Hey I've got it to work but when I created the 'mobile/directory/venue_index.html and venue_list.html it doesn't use the templates. Sure it's some small thing I just missed.

class VenueList(JSONResponseMixin, MultipleObjectTemplateResponseMixin, BaseListView):
    model = Venue
    paginate_by = 20
    context_object_name = 'venues'
    category = None
    slug_level = ""
    area = None

    template_name = 'directory/venue_index.html'

    def get_queryset(self):
        if self.request.is_mobile:
            qs = Venue.objects.filter(visible=True,).order_by('-hot', '-created')
            if self.kwargs.get('category', None):
                self.template_name = 'directory/venue_list.html'
                slugs = self.kwargs['category'].strip('/').split('/')
                self.category = get_object_or_404(Category, slug=slugs[-1])
                qs = qs.filter(categories__in=self.category.get_descendants(include_self=True))
            if self.kwargs.get('area', None):
                self.template_name = 'directory/venue_list.html'

                self.template_name = 'directory/venue_list.html'
                slugs = self.kwargs['area'].strip('/').split('/')
                self.area = get_object_or_404(Area, slug=slugs[-1])
                qs = qs.filter(area__in=self.area.get_descendants(include_self=True))
            if self.request.META.get('HTTP_ACCEPT', None) == 'application/json':
                qs = qs.filter(longitude__isnull=False, latitude__isnull=False).exclude(longitude=0, latitude=0).order_by('name')
            self.queryset = qs.distinct()
            return self.queryset
gregmuellegger commented 9 years ago

Hey, have you added django_mobile.loader.Loader as first item to your TEMPLATE_LOADERS setting?