Template tags#
- lotus.templatetags.lotus.article_state_list(context, article, **kwargs)[source]#
Return all state names for given article object.
This is a shortcut around
Article.get_states
to be able to use thelotus_now
context variable or force another value.Example
At least you must give an Article object:
{% load lotus %} {% article_state_list article [now=custom_now] [prefix="foo_"] %}
Optional
now
argument expect a datetime to use instead of current date;Optional
prefix
argument expect a string to prepend all returned state names.
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included.article (lotus.models.article.Article) – Article object to compute states.
- Keyword Arguments:
now (datetime.datetime) – A datetime to use to compare against publish start and end dates to check for some publication criterias. See
Article.get_states
docstring for more details.prefix (string) – A string to prefix every names. Empty by default.
- Returns:
A list of every state names.
- Return type:
list
- lotus.templatetags.lotus.article_states(context, article, **kwargs)[source]#
Return a string of state names for given article object.
Identical to
article_state_list
but return a string instead of list.Example
At least you must give an Article object:
{% load lotus %} {% article_states article [now=custom_now] [prefix="foo_"] %}
Optional
now
argument expect a datetime to use instead of current date;Optional
prefix
argument expect a string to prepend all returned state names.
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included.article (lotus.models.article.Article) – Article object to compute states.
- Keyword Arguments:
now (datetime.datetime) – A datetime to use to compare against publish start and end dates to check for some publication criterias. See
Article.get_states
docstring for more details.prefix (string) – A string to prefix every names. Empty by default.
- Returns:
Every state names divided by a white space.
- Return type:
string
- lotus.templatetags.lotus.translation_siblings(context, source, tag_name=None, **kwargs)[source]#
A tag to get translation siblings for given source object.
This tag can work for an Article or a Category object to retrieve every translation siblings, like all translation children for an original source or translation children and original for a translation.
Note than for Article object the tag will require a datetime it may refer to for filtering results with publication criterias. Either the datetime will be set as a template context variable
lotus_now
(as implemented inArticleFilterMixin
) or it can be given through the tag argumentnow
.Example
At least you must give an Article object:
{% load lotus %} {% translation_siblings_html article [now=custom_now] [preview=True] %}
Optional
now
argument expect a datetime to use instead of current date;Optional
preview
argument expect a boolean to explicitely disable or enable preview mode, on default it isNone
to determine it automatically.
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included. This is only used with an Article object, so it should be safe to be empty for a Category.source (object) – Either a
lotus.models.Article
orlotus.models.Category
to retrieve its translation siblings.
- Keyword Arguments:
now (datetime.datetime) – A datetime to use to compare against publish start and end dates to check for some publication criterias. Only used for Article object.
preview (boolean) – Option to bypass checking preview mode from context and force it to a value, either True to enable it, False to disable it or None to let the basic behavior to determine it from its template context variable. Default to None.
tag_name (string) – Template tag name to display in error messages. This is something used in template tags which inherit from
translation_siblings
. You don’t have to care about it in your common template tag usage.
- Returns:
A dictionnary with item
source
for the given source object and itemsiblings
for retrieved translation sibling objects.- Return type:
dict
- lotus.templatetags.lotus.translation_siblings_html(context, source, **kwargs)[source]#
Work like
translation_siblings
but render HTML from a template instead.Example
At least you must give an Article object:
{% load lotus %} {% translation_siblings_html article [now=custom_now] [template="foo/bar.html"] [preview=True] %}
Optional
now
argument expect a datetime to use instead of current date;Optional
template
argument expect a string for a template path to use instead of default one;Optional
preview
argument expect a boolean to explicitely disable or enable preview mode, on default it isNone
to determine it automatically;
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included. This is only used with an Article object, so it should be safe to be empty for a Category.source (object) – Either a
lotus.models.Article
orlotus.models.Category
to retrieve its translation siblings.
- Keyword Arguments:
now (datetime.datetime) – A datetime to use to compare against publish start and end dates to check for some publication criterias. Only used for Article object.
template (string) – A path to a custom template to use instead of the default one. If not given, the default one will be used, each model have its own default template, see settings.
preview (boolean) – Option to bypass checking preview mode from context and force it to a value, either True to enable it, False to disable it or None to let the basic behavior to determine it from its template context variable. Default to None.
- Returns:
Rendered template tag fragment.
- Return type:
string
- lotus.templatetags.lotus.preview_switch(context)[source]#
Display a button to enable or disable preview mode.
Example
This tag does not expect any argument:
{% load lotus %} {% preview_switch %}
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included. Note that context requires the session and user objects to be present (when available for authenticated users) so you need to enable the respective middleware/context processors in your project settings.- Returns:
A dictionnary of payload to build preview button template.
user: User object (or Anonymous)
allowed: Boolean to determine if user is allowed for preview mode or not;
current_mode: Either
enabled
ordisabled
string to indicate current preview mode state;redirection: A string for the path to give to button URL that will be used to redirect to once preview toggle has been requested;
- Return type:
dict
- lotus.templatetags.lotus.check_object_lang_availability(context, source, **kwargs)[source]#
Determine if an object has a language that are not available from
LANGUAGES
setting.Example
This tag does not expect any other argument than
source
:{% load lotus %} {% check_object_lang_availability article_object as object_lang_availability %}
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variables. It is not used from this tag.source (object) – Any object with an attribute
language
that will be checked againstsettings.LANGUAGES
however the tag will fails silently for given source that does not have this attribute.
- Returns:
A dictionnary with summary informations of object language and its availability.
- Return type:
dict
- lotus.templatetags.lotus.article_get_related(context, article, **kwargs)[source]#
Returns the related articles for a given article object.
It rely on an optional filtering function used to filter article objects to apply publication and language lookups. This function is searched in template context as an item named
apply_article_lookups
, if not found no filtering is applied.Commonly the filtering function would be
ArticleFilterMixin.apply_article_lookups
that is already supplied in Article detail view and viewset.Example
You must give an Article object:
{% load lotus %} {% article_get_related myarticle %}
Or:
{% load lotus %} {% article_get_related myarticle as relateds %}
No other arguments are expected.
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included.article (lotus.models.article.Article) – Article object to compute states.
- Returns:
Queryset for retrieved related articles.
- Return type:
queyrset
- lotus.templatetags.lotus.get_categories(context, current=None)[source]#
Generates and returns a list of all categories for current language.
Example
This tag does not require any argument to work:
{% load lotus %} {% get_categories_html [current=mycategory] %}
And accept optional arguments:
current
argument expect a category object to check against each item,the matching item will be marked as active.
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included.- Keyword Arguments:
current (lotus.models.article.Category) – A category object to check against each item, the matching item will be marked as active.
- Returns:
A dictionary containing a list of dictionaries, each of which has the
title
andurl
of a category.- Return type:
dict
- lotus.templatetags.lotus.get_categories_html(context, current=None, template=None)[source]#
Work like
get_categories
but render HTML from a template instead.Example
This tag does not require any argument to work:
{% load lotus %} {% get_categories_html [current=mycategory] [template="foo/bar.html"] %}
And accept optional arguments:
current
: expect a category object to check against each item,the matching item will be marked as active;
template
: a string for a template path to use;
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included. This is only used with an Article object, so it should be safe to be empty for a Category.- Keyword Arguments:
current (lotus.models.article.Category) – A category object to check against each item, the matching item will be marked as active.
template (string) – A path for custom template to use. If not given a default one will be used from setting
LOTUS_CATEGORIES_TAG_TEMPLATE
.
- Returns:
Rendered template tag fragment.
- Return type:
string
- lotus.templatetags.lotus.get_album_html(context, album, template=None)[source]#
Render an Album object with a template.
Example
This tag requires
album
argument to work:{% load lotus %} {% get_album_html album %}
- Parameters:
context (object) – Either a
django.template.Context
or a dictionnary for context variable for template where the tag is included.album (lotus.models.article.Album) – An album object.
- Keyword Arguments:
template (string) – A path for custom template to use. If not given a default one will be used from setting
LOTUS_ALBUM_TAG_TEMPLATE
.- Returns:
Rendered template tag fragment.
- Return type:
string