Shortcuts (feincms3.shortcuts)

For me, the most useful part of Django’s generic class based views is the template name generation and the context variable naming for list and detail views, and also the pagination.

The rest of the CBV is less flexible than I’d like them to be, i.e. integrating forms on detail pages can be a hassle.

Because of this, render_list and render_detail.

feincms3.shortcuts.template_name(model, template_name_suffix)[source]

Given a model and a template name suffix, return the resulting template path:

>>> template_name(Article, '_detail')
'articles/article_detail.html'
>>> template_name(User, '_form')
'auth/user_form.html'
feincms3.shortcuts.render_list(request, queryset, context=None, *, template_name_suffix='_list', paginate_by=None)[source]

Render a list of items

Usage example:

def article_list(request, ...):
    queryset = Article.objects.published()
    return render_list(
        request,
        queryset,
        paginate_by=10,
    )

You can also pass an additional context dictionary and/or specify the template name suffix. The query parameter page is hardcoded for specifying the current page if using pagination.

The queryset (or the page if using pagination) are passed into the template as object_list AND <model_name>_list, i.e. article_list in the example above.

feincms3.shortcuts.render_detail(request, object, context=None, *, template_name_suffix='_detail')[source]

Render a single item

Usage example:

def article_detail(request, slug):
    article = get_object_or_404(Article.objects.published(), slug=slug)
    return render_detail(
        request,
        article,
    )

An additional context dictionary is also supported, and specifying the template name suffix too.

The Article instance in the example above is passed as object AND article (lowercased model name) into the template.