Views

class lotus.views.mixins.NoOperationBreadcrumMixin[source]

A dummy and empty mixin to use when ‘view_breadcrumbs’ is not available.

class lotus.views.mixins.PreviewModeMixin[source]

A mixin to contain the logic for preview mode and add a context variable preview_mode.

Preview mode is only allowed for staff users which use URL with a specific argument as defined in setting LOTUS_PREVIEW_KEYWORD.

A staff user is only allowed for preview mode if its session have the right item set to True exactly.

The preview mode is essentially used to not filter queryset with publication criterias.

allowed_preview_mode(request)[source]

Return if preview mode is enabled or not.

get_context_data(**kwargs)[source]

Expose the preview mode state to template.

class lotus.views.mixins.ArticleFilterMixin(*args, **kwargs)[source]

A mixin to share Article filtering.

build_article_lookups(language=None, prefix=None)[source]

Build complex lookups to apply common publication criterias.

Also set a self.target_date attribute to store the date checked against as a reference for further usage (like in get_context_data).

Depends on allowed_preview_mode method as implemented in PreviewModeMixin (that manage preview mode) and the queryset must be for a model with a manager which implement get_for_lang and get_published methods.

Keyword Arguments:

language (string) – Language code to filter on.

Returns:

The lookups to give to a queryset filter.

Return type:

tuple

apply_article_lookups(queryset, language=None)[source]

Apply publication and language lookups to given queryset.

This will set a self.target_date attribute to store the date checked against as a reference for further usage (like in get_context_data).

The queryset must be for a model with a manager which implement get_for_lang and get_published methods. This support also allowed_preview_mode method as implemented in PreviewModeMixin (that manage preview mode) if it is available.

Parameters:

queryset (django.db.models.QuerySet) – Base queryset to start on.

Keyword Arguments:

language (string) – Language code to filter on.

Returns:

Improved queryset with required filtering lookups.

Return type:

django.db.models.QuerySet

class lotus.views.mixins.LanguageMixin[source]

A mixin to provide very common logic related to language.

get_language_code()[source]

Shortand to get_language_code function that already give the request object.

Warning

This should not be used in view code before request attribute has been set.

Returns:

Language code retrieved either from request object or settings.

Return type:

string

class lotus.views.mixins.LotusContextStage[source]

Mixin to inject Lotus stage into view context.

Lotus stage is commonly used for Lotus navigation, it just indicates where a view is located from main Lotus content type views (Article, Author, Category, ..).

Views which inherits from this mixin should set view attribute lotus_stage to a main content type in lowercase like articles, authors, category.

The default stage value is None.

Finally, the Lotus stage is just an helper for basic navigation like in a menu to highlight corresponding item. There is no code which use it so it can be ignored from custom Lotus implementation.

get_context_data(**kwargs)[source]

Expose the date “now” used for publication filter.

class lotus.views.mixins.ArticleFilterAbstractView(*args, **kwargs)[source]

Abstract class which gather all the classes needed to implement filtering on criterias.

get_context_data(**kwargs)[source]

Expose the date “now” used for publication filter and the article filtering. function

class lotus.views.mixins.TemplateFromObjectMixin[source]

A mixin to get the template to render from the object attribute template.

It is intended to override the template mechanism from TemplateResponseMixin and for a view which have an attribute object where to find the attribute template.

get_template_names()[source]

Overrides the original method to get the template name from the object.

Returns:

List of template name as expected by the Django mechanism but the list will always have an unique item.

Return type:

list

class lotus.views.ArticleIndexView(*args, **kwargs)[source]

Paginated list of articles.

model

alias of Article

get_queryset()[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

class lotus.views.ArticleDetailView(*args, **kwargs)[source]

Article detail.

model

alias of Article

get_queryset()[source]

Get the base queryset which may include the basic publication filter depending preview mode.

Preview mode is enabled from a flag in session and only for staff user. If it is disabled publication criterias are applied on lookups.

Also apply lookup against “preview” mode.

get_object(queryset=None)[source]

Apply the right filters to get the article object.

class lotus.views.AuthorIndexView(**kwargs)[source]

List of authors which have contributed at least to one article.

model

alias of Author

get_queryset()[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

class lotus.views.AuthorDetailView(*args, **kwargs)[source]

Author detail and its related article list.

Opposed to article or category listing, this one list objects for language from request, not from the author language since it dont have one.

model

alias of Author

listed_model

alias of Article

pk_url_kwarg = None
get_queryset_for_object()[source]

Build queryset base to get Author.

get_queryset()[source]

Build queryset base to list Author articles.

Depend on “self.object” to list the Author related objects.

class lotus.views.CategoryIndexView(**kwargs)[source]

List of categories

model

alias of Category

get_queryset()[source]

Build queryset base with language filtering to list categories.

class lotus.views.CategoryDetailView(*args, **kwargs)[source]

Category detail and its related article list.

model

alias of Category

listed_model

alias of Article

pk_url_kwarg = None
get_queryset_for_object()[source]

Build queryset base with language filtering to get Category.

get_queryset()[source]

Build queryset base to list Category articles.

Depend on “self.object” to list the Category related objects filtered on its language.

class lotus.views.DisabledTagIndexView(**kwargs)[source]

A very basic view which always return the common Http404 page.

class lotus.views.EnabledTagIndexView(*args, **kwargs)[source]

List of tags that are related from at least one article.

model

alias of Tag

get_queryset()[source]

Build complex queryset to get all tags which have published articles.

Published articles are determined with the common publication criterias.

class lotus.views.PreviewArticleDetailView(*args, **kwargs)[source]

TODO: Should force set the context var for preview mode at True without to tamper session so the user session is still in its current state but it can preview.

allowed_preview_mode(request)[source]

Force preview mode for querysets.

get_context_data(**kwargs)[source]

Force preview mode in context (without tampering preview mode in session).

get(request, *args, **kwargs)[source]

Ensure that user is allowed to use this view.

class lotus.views.PreviewTogglerView(**kwargs)[source]

Toggle preview mode in user session.

The redirection url can not be one of the preview toggler url, this is to avoid malicious redirection loop.

Only authenticated admin user is allowed to use this view and an URL argument “next” is required to be given and not relative (not starting with /) else it is assumed as a bad operation.

get_redirect_url(*args, **kwargs)[source]

Return the URL redirect to. Keyword arguments from the URL pattern match generating the redirect request are provided as kwargs to this method.

class lotus.views.TagIndexView(*args, **kwargs)

This is the effective index class view which inherit either from the working index view or the dummy 404 view if Tag index is enabled or not according to settings.

class lotus.views.TagDetailView(*args, **kwargs)[source]

Tag detail and its related article list.

Opposed to article or category listing, this one list objects for language from request, not from the tag language since it dont have one.

model

alias of Tag

listed_model

alias of Article

pk_url_kwarg = None
get_queryset_for_object()[source]

Build queryset base to get Tag.

get_queryset()[source]

Build queryset base to list Tag articles.

Depend on “self.object” to list the Tag related objects.

class lotus.views.TagAutocompleteView(**kwargs)[source]

View to return JSON response for a tag list.

Default returns paginated list of all available tags. If request argument q is given, the list will return tag items that start with text from argument.

Worth to notice this is language agnostic, since a Tag does not have any specific language.

test_func()[source]

Limit to admin only

get_queryset()[source]

Filter the queryset with GET[‘q’].

post(request, *args, **kwargs)[source]

POST request is forbidden since DAL would create a tag for a missing value.

class lotus.views.admin.AdminTranslateView(**kwargs)[source]

Mixin to display a form to select a language to translate an object to.

The form does not perform a POST request. Instead it will make a GET to the object create form with some URL argument so the create form will know it will have to prefill fields “language” and “original”, the user still have to fill everything else.

Form only displays the language which are still available (not in original and its possible translations).

Given ID is used to retrieve an object and get its original if its translation. Finally the form will always redirect to an original object.

Despite inheriting from DetailView, this is not a ready to use view, you need inherit it to define the mode and template_name attributes correctly.

get_queryset()[source]

Return the QuerySet that will be used to look up the object.

This method is called by the default implementation of get_object() and may not be called if get_object() is overridden.

get_object(queryset=None)[source]

Return the object the view is displaying.

Require self.queryset and a pk or slug argument in the URLconf. Subclasses can override this to return any object.

get_context_data(**kwargs)[source]

Append specific admin context

class lotus.views.admin.ArticleAdminTranslateView(**kwargs)[source]

Display a form to select a language to translate an article to.

model

alias of Article

class lotus.views.admin.CategoryAdminTranslateView(**kwargs)[source]

Display a form to select a language to translate a category to.

model

alias of Category

class lotus.views.admin.CategoryAdminTreeView(**kwargs)[source]

An admin view to list a tree of categories.

Since it is a tree this view can’t enable pagination because it is not safe to cut a tree in multiple pages.

model

alias of Category

get_view_media()[source]

Get Media object for Category admin views static files.

Returns:

Media object.

Return type:

django.forms.widgets.Media

get_context_data(**kwargs)[source]

Append specific admin context.

This includes:

  • The page title;

  • The tree object;

  • The media object;

class lotus.views.admin.CustomLotusAdminContext[source]

Mixin to add required context for a custom model admin view.

The view which use it must have the model correctly set to your model, if your view has no model then this mixin is probably useless.

Also, there is an additional useful context variable title to set yourself in your view since its value is totally related to the view itself.