Exemple #1
0
def personas(request, category=None):
    listing = personas_listing(request, category)

    # I guess this was a Complete Theme after all.
    if isinstance(listing,
                  (HttpResponsePermanentRedirect, HttpResponseRedirect)):
        return listing

    categories, filter_, base, cat = listing

    count = cat.count if cat else base.count()

    addons = amo.utils.paginate(request, filter_.qs, PAGINATE_PERSONAS_BY,
                                count=count)

    if 'sort' not in request.GET and count > MIN_COUNT_FOR_LANDING:
        template = 'browse/personas/category_landing.html'
    else:
        template = 'browse/personas/grid.html'

    if cat:
        ids = AddonCategory.creatured_random(cat, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")
    else:
        ids = Addon.featured_random(request.APP, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")

    ctx = {'categories': categories, 'category': cat, 'addons': addons,
           'filter': filter_, 'sorting': filter_.field,
           'sort_opts': filter_.opts,
           'featured': featured, 'search_cat': 'themes',
           'is_homepage': cat is None and 'sort' not in request.GET}
    return render(request, template, ctx)
Exemple #2
0
def creatured(request, category):
    TYPE = amo.ADDON_EXTENSION
    q = Category.objects.filter(application=request.APP.id, type=TYPE)
    category = get_object_or_404(q, slug=category)
    ids = AddonCategory.creatured_random(category, request.LANG)
    addons = manual_order(Addon.objects.public(), ids, pk_name='addons.id')
    return render(request, 'browse/creatured.html',
                  {'addons': addons, 'category': category,
                   'sorting': 'featured'})
Exemple #3
0
def creatured(request, category):
    TYPE = amo.ADDON_EXTENSION
    q = Category.objects.filter(application=request.APP.id, type=TYPE)
    category = get_object_or_404(q, slug=category)
    ids = AddonCategory.creatured_random(category, request.LANG)
    addons = manual_order(Addon.objects.public(), ids, pk_name='addons.id')
    return render(request, 'browse/creatured.html',
                  {'addons': addons, 'category': category,
                   'sorting': 'featured'})
Exemple #4
0
def personas(request, category=None, template=None):
    listing = personas_listing(request, category)

    # I guess this was a Complete Theme after all.
    if isinstance(listing,
                  (HttpResponsePermanentRedirect, HttpResponseRedirect)):
        return listing

    categories, filter_, base, cat = listing

    if filter_.field == 'up-and-coming':
        # Almost hardcoding the number of element because performing
        # `filter_.qs.count()` is a performance killer. We're still
        # verifying the `base.count()` for the template switch below.
        base_count = base.count()
        count = (base_count if base_count < MIN_COUNT_FOR_LANDING else
                 PAGINATE_PERSONAS_BY * settings.PERSONA_DEFAULT_PAGES)
    else:
        # Pass the count from base instead of letting it come from
        # filter_.qs.count() since that would join against personas.
        count = cat.count if cat else base.count()

    addons = amo.utils.paginate(request,
                                filter_.qs,
                                PAGINATE_PERSONAS_BY,
                                count=count)

    if ('sort' not in request.GET
            and ((request.MOBILE and not cat) or
                 (not request.MOBILE and count > MIN_COUNT_FOR_LANDING))):
        template += 'category_landing.html'
    else:
        template += 'grid.html'

    if cat:
        ids = AddonCategory.creatured_random(cat, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")
    else:
        ids = Addon.featured_random(request.APP, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")

    ctx = {
        'categories': categories,
        'category': cat,
        'addons': addons,
        'filter': filter_,
        'sorting': filter_.field,
        'sort_opts': filter_.opts,
        'featured': featured,
        'search_cat': 'themes',
        'is_homepage': cat is None and 'sort' not in request.GET
    }
    return render(request, template, ctx)
Exemple #5
0
def personas(request, category=None, template=None):
    listing = personas_listing(request, category)

    # I guess this was a Complete Theme after all.
    if isinstance(listing,
                  (HttpResponsePermanentRedirect, HttpResponseRedirect)):
        return listing

    categories, filter_, base, cat = listing

    if filter_.field == 'up-and-coming':
        # Almost hardcoding the number of element because performing
        # `filter_.qs.count()` is a performance killer. We're still
        # verifying the `base.count()` for the template switch below.
        base_count = base.count()
        count = (base_count if base_count < MIN_COUNT_FOR_LANDING
                 else PAGINATE_PERSONAS_BY * settings.PERSONA_DEFAULT_PAGES)
    else:
        # Pass the count from base instead of letting it come from
        # filter_.qs.count() since that would join against personas.
        count = cat.count if cat else base.count()

    addons = amo.utils.paginate(request, filter_.qs, PAGINATE_PERSONAS_BY,
                                count=count)

    if ('sort' not in request.GET and (
            (request.MOBILE and not cat) or
            (not request.MOBILE and count > MIN_COUNT_FOR_LANDING))):
        template += 'category_landing.html'
    else:
        template += 'grid.html'

    if cat:
        ids = AddonCategory.creatured_random(cat, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")
    else:
        ids = Addon.featured_random(request.APP, request.LANG)
        featured = manual_order(base, ids, pk_name="addons.id")

    ctx = {'categories': categories, 'category': cat, 'addons': addons,
           'filter': filter_, 'sorting': filter_.field,
           'sort_opts': filter_.opts,
           'featured': featured, 'search_cat': 'themes',
           'is_homepage': cat is None and 'sort' not in request.GET}
    return render(request, template, ctx)
Exemple #6
0
 def __init__(self, request, base, category, key, default):
     self.category = category
     self.ids = AddonCategory.creatured_random(category, request.LANG)
     super(CategoryLandingFilter, self).__init__(request, base, key,
                                                 default)
Exemple #7
0
 def __init__(self, request, base, category, key, default):
     self.category = category
     self.ids = AddonCategory.creatured_random(category, request.LANG)
     super(CategoryLandingFilter, self).__init__(request, base, key,
                                                 default)