Models¶
- class lotus.models.translated.Translated(*args, **kwargs)[source]¶
Abstract model for common content translation fields.
- language¶
Required language code.
- class lotus.models.author.AuthorManagerEnabled(*args, **kwargs)[source]¶
Proxy model manager to avoid overriding default User’s manager:
https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-model-managers
- class lotus.models.author.Author(*args, **kwargs)[source]¶
Proxy model around User model gotten from
django.contrib.auth.models.get_user_model.- get_absolute_url()[source]¶
Builds and returns the author’s URL based on his username.
TODO: The try..except does not seems useful.
- get_absolute_api_url()[source]¶
Return absolute URL to the author detail viewset from API.
- Returns:
An URL.
- Return type:
string
- COMMON_ORDER_BY = ['first_name', 'last_name']¶
List of field order commonly used in frontend view/api
- class lotus.models.category.Category(*args, **kwargs)[source]¶
Category model.
- original¶
Optional original category when object is a translation.
- modified¶
Automatic modification date.
- title¶
Required unique title string.
- slug¶
Required unique slug string.
- template¶
Optional custom template path string.
- lead¶
Optional text lead.
- description¶
Optional description string.
- cover¶
Optional cover image file.
- cover_alt_text¶
Optional alternative text for cover image.
- COMMON_ORDER_BY = ['title']¶
List of field order commonly used in frontend view/api.
- TREE_ORDER_BY = ['path', 'title']¶
List of field order to use with any tree queryset.
- node_order_by = ['title']¶
Treebeard attribute only used for ordering with position name when performing writing operation on categories.
Warning
DO NOT CHANGE, it may corrupt tree for already saved data, however
Category.fix_tree(fix_paths=True)should fix corruption.
- language¶
Required language code.
- get_absolute_url()[source]¶
Return absolute URL to the category detail view.
- Returns:
An URL.
- Return type:
string
- get_absolute_api_url()[source]¶
Return absolute URL to the author detail viewset from API.
- Returns:
An URL.
- Return type:
string
- get_edit_url()[source]¶
Return absolute URL to edit category from admin.
- Returns:
An URL.
- Return type:
string
- get_subcategories()[source]¶
Return category children, results are enforced on category language.
- Returns:
List of children categories.
- Return type:
queryset
- classmethod apply_tree_queryset_filter(queryset, language=None, parent=None, current=None)[source]¶
Apply lookups on a queryset to filter items.
Warning
With some filter combinations this could return empty results.
- Parameters:
queryset (Queryset) – The queryset where to append filters.
- Keyword Arguments:
cls (class object) – The model class, typically
Category.language (string) – Language code to use in queryset filter, every Category in different language will be excluded from results. If not given, all Category from mixed languages are returned.
parent (Category) – A category object used to start the tree. If not given, we assume than parent is the root of all categories meaning the whole tree will be returned.
current (Category) – The current category is used to find the tree branch to unfold. When given, only the nodes from the tree branch will be returned along the top level nodes (with the same depth than the parent) and children nodes that are not part of the branch are ignored.
- Returns:
The given queryset with possible filters. If no filter arguments are given, the queryset is returned unchanged.
- Return type:
Queryset
- classmethod get_nested_tree(parent=None, language=None, current=None, branch=True, safe=True)[source]¶
A convenient method to get a Category tree with language filtered or not.
This was based on
MP_Node.dump_bulk()method but opposed to it this method applies some filters on queryset.If language argument is set with “en” only the english objects will be returned from queryset, this means “Item 1”, “Item 2” and “Item 3.1”. However since “Item 3.1” is a child of “Item 3” that is excluded from language filter, “Items 3.1” won’t be in resulting tree because its parent does not exist in results.
The output is probably not suitable anymore with
MP_Node.load_bulk()because we keep/add some additional items to a node, opposed to the “dump_bulk” payload.Warning
With some filter combinations this could return an empty list.
- Parameters:
cls (class object) – The model class, typically
Category.language (string) – Language code to use in queryset filter, every Category in different language will be excluded from results. If not given, all Category from mixed languages are returned.
parent (Category) – A category object used to start the tree. If not given, we assume than parent is the root of all categories meaning the whole tree will be returned.
current (Category) – Basically the current category is only used to mark a node as “active”. But with
branchargument enabled it will be used for the “branch unfolding” mode.branch (boolean) – The current category will be used to find the tree branch to unfold. When this is true and
currentis given, only the nodes from the tree branch will be returned along the top level nodes (with the same depth than the parent) and children nodes that are not part of the branch are ignored.safe (boolean) – Due to the fact we can exclude item from language filter, we can have KeyError exception when building tree. If this argument is true, there won’t be any exception for this case and missing key will just be ignored. If false, any exception related to missing node key will be raised.
- Results:
list: Recursive list of Category tree. Each item is dictionnary of node values and it will be something like this:
{ "data": { "language": "en", "original": None, "modified": now, "title": "Item 1", "slug": "item-1", "lead": "", "description": "", "cover": "", }, "id": 1, "active": False, "depth": 1, "path": "0001", "children": [] }
The
childrenis only present if the node has children.
- move_into(parent)[source]¶
Move object as a child of given parent.
This is a shortcut around MP_Node.move() method but with positionning forced on ‘sorted child’ technic because it is the only one that fit to Lotus needs.
You should never try to manually set a Category as a child of a parent Category because it will probably not correctly manage the node path rewriting.
- Raises:
LanguageMismatchError – If both object language and parent language are differents.
- Parameters:
parent (Category) – A category object to define as the parent.
- save(*args, **kwargs)[source]¶
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class lotus.models.album.Album(*args, **kwargs)[source]¶
Album container for items.
- title¶
A required title string.
- modified¶
Automatic modification date.
- save(*args, **kwargs)[source]¶
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class lotus.models.album.AlbumItem(*args, **kwargs)[source]¶
Album item model.
- modified¶
Automatic modification date.
- title¶
Required title string.
- order¶
Optional number for order position in item list.
- media¶
Required media file.
- COMMON_ORDER_BY = ['order', 'title']¶
List of field order commonly used in frontend view/api
- save(*args, **kwargs)[source]¶
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class lotus.models.article.Article(*args, **kwargs)[source]¶
Article model.
- original¶
Optional original category when object is a translation.
- status¶
Required article status.
- featured¶
Optional article featured mark.
- pinned¶
Optional article pinned mark.
- private¶
Optional privacy.
- publish_date¶
Required publication date.
- publish_time¶
Required publication time.
- publish_end¶
Optional publication end date.
- last_update¶
Last edition date.
- title¶
Required title string.
- slug¶
Required unique slug string.
- template¶
Optional custom template path string.
- seo_title¶
Optional SEO title string used as meta title if not blank, instead of default behavior to use article title.
- lead¶
Optional text lead.
- introduction¶
Optional text introduction.
- content¶
Optional text content.
- cover¶
Optional cover image.
- cover_alt_text¶
Optional alternative text for cover image.
- image¶
Optional main image.
- image_alt_text¶
Optional alternative text for main image.
- categories¶
Optional related Categories.
- authors¶
Optional related Authors.
Optional related article.
- tags = <taggit.managers._TaggableManager object>¶
Optional tags
- album¶
Optional album relation.
- language¶
Required language code.
- COMMON_ORDER_BY = ['-pinned', '-publish_date', '-publish_time', 'title']¶
List of field order commonly used in frontend view/api
- build_absolute_url(urlname)[source]¶
Build object absolute URL with language prefix for url name.
Language is forced on article language.
- Parameters:
urlname (string) – The URL name to reverse with kwargs to get absolute URL.
- Returns:
Object absolute URL.
- Return type:
string
- get_absolute_url()[source]¶
Return absolute URL to the article detail view.
- Returns:
An URL.
- Return type:
string
- get_absolute_api_url()[source]¶
Return absolute URL to the article detail viewset from API.
- Returns:
An URL.
- Return type:
string
- get_absolute_preview_url()[source]¶
Return absolute URL to the article detail view in forced preview mode.
- Returns:
An URL.
- Return type:
string
- get_edit_url()[source]¶
Return absolute URL to edit article from admin.
- Returns:
An URL.
- Return type:
string
- get_authors()[source]¶
Return article authors.
- Returns:
List of article authors.
- Return type:
queryset
- get_categories()[source]¶
Return article categories, results are enforced on article language.
- Returns:
List of article categories.
- Return type:
queryset
- get_album_items()[source]¶
Return album items.
Depends on
use_original_albumvalue.- Returns:
List of album items.
- Return type:
queryset
Return article related articles.
Warning
On default without
filter_funcdefined this won’t apply any publication criteria, only the language filtering.You would need to give it a proper filtering function to ensure about results.
TODO: Concretely for now, the ‘filter_func’ is not used in HTML frontend but it should, either from a variable context or a template tag.
- Keyword Arguments:
filter_func (function) – A function used to create a queryset for related articles filtered. It has been done to be given
ArticleFilterMixin.apply_article_lookupsso any other given function should at least expect the same arguments.- Returns:
List of related articles.
- Return type:
queryset
- get_tags()[source]¶
Return article tags.
- Returns:
List of related ‘taggit.models.Tag’ objects.
- Return type:
queryset
- publish_datetime()[source]¶
Return a datetime from joined publish date and time.
- Returns:
Publish datetime with UTC timezone.
- Return type:
datetime.datetime
- get_states(now=None)[source]¶
Computate every publication states.
State names depend from
settings.LOTUS_ARTICLE_PUBLICATION_STATE_NAMESand each state name can be disabled (never raised in states) if its key name have been removed from setting.- Keywords Arguments:
- now (datetime.datetime): Commonly the current datetime ‘now’ (timezone
aware) which have been used in queryset lookup to check for publication availability. It is used to determine if article publish “start date” is to come next or if article publish “end date” is over the current date. Empty by default, there will be no state about start/end dates.
- Returns:
A list of all article state names.
- Return type:
list
- is_published(now=None)[source]¶
Check for all publication criterias for a datetime.
- Keywords Arguments:
- now (datetime.datetime): Datetime to match against for publication states.
Default to
Noneso it will use current datetime.
- Returns:
True if object is published else False.
- Return type:
boolean
- save(*args, **kwargs)[source]¶
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.