Example #1
0
    def get_object(self, bits):
        try:
            ct = get_content_type(bits[-1])
            bits = bits[:-1]
        except (Http404, IndexError):
            ct = False

        if bits:
            cat = get_cached_object_or_404(Category, tree_path=u'/'.join(bits), site__id=settings.SITE_ID)
        else:
            cat = get_cached_object(Category, tree_parent__isnull=True, site__id=settings.SITE_ID)

        if ct:
            return (cat, ct)
        return cat
Example #2
0
File: feeds.py Project: whit/ella
    def get_object(self, bits):
        try:
            ct = get_content_type(bits[-1])
            bits = bits[:-1]
        except (Http404, IndexError):
            ct = False

        if bits:
            cat = get_cached_object_or_404(Category, tree_path=u'/'.join(bits), site__id=settings.SITE_ID)
        else:
            cat = get_cached_object(Category, tree_parent__isnull=True, site__id=settings.SITE_ID)

        if ct:
            return (cat, ct)
        return cat
Example #3
0
 def test_by_brute_force(self):
     for m in get_models():
         if issubclass(m, Publishable):
             ct = ContentType.objects.get_for_model(m)
             self.assert_equals(
                 ct, get_content_type(slugify(m._meta.verbose_name_plural)))
Example #4
0
    def get_context(self, request, category='', year=None, month=None, \
        day=None, content_type=None,
        paginate_by=listingex_settings.PAGINATE_BY):

        # pagination
        if 'p' in request.GET and request.GET['p'].isdigit():
            page_no = int(request.GET['p'])
        else:
            page_no = 1

        # if we are not on the first page, display a different template
        category_title_page = page_no == 1

        kwa = {}
        if year:
            category_title_page = False
            year = int(year)
            kwa['publish_from__year'] = year

        if month:
            try:
                month = int(month)
                date(year, month, 1)
            except ValueError:
                raise Http404()
            kwa['publish_from__month'] = month

        if day:
            try:
                day = int(day)
                date(year, month, day)
            except ValueError:
                raise Http404()
            kwa['publish_from__day'] = day

        cat = get_cached_object_or_404(Category, tree_path=category,
                                       site__id=settings.SITE_ID)
        kwa['category'] = cat
        if category:
            kwa['children'] = Listing.objects.ALL

        if content_type:
            ct = get_content_type(content_type)
            kwa['content_types'] = [ct]
        else:
            ct = False

        qset = Listing.objects.get_queryset_wrapper(kwa)

        if self.is_ex_applied(cat):
            per_first_page = (listingex_settings.FIRST_PAGE_COUNT or
                              paginate_by)
        else:
            per_first_page = paginate_by

        paginator = PaginatorEx(qset, per_first_page, paginate_by)

        if page_no > paginator.num_pages or page_no < 1:
            raise Http404()

        page = paginator.page(page_no)
        listings = page.object_list

        context = {
                'page': page,
                'is_paginated': paginator.num_pages > 1,
                'results_per_page': paginate_by,
                'content_type': ct,
                'content_type_name': content_type,
                'listings': listings,
                'category': cat,
                'is_homepage': (not bool(category) and page_no == 1
                                and year is None),
                'is_title_page': category_title_page,
                'archive_entry_year': lambda: self._archive_entry_year(cat),
            }

        return context
Example #5
0
 def test_by_brute_force(self):
     for m in get_models():
         if issubclass(m, Publishable):
             ct = ContentType.objects.get_for_model(m)
             tools.assert_equals(ct, get_content_type(slugify(m._meta.verbose_name_plural)))
Example #6
0
 def test_by_brute_force(self):
     for ct in ContentType.objects.all():
         self.assert_equals(ct, get_content_type(slugify(ct.model_class()._meta.verbose_name_plural)))