Forum

The forum application provides the ability to browse a tree of forums. It is based on a single AbstractForum abstract model.

Abstract models

Forum abstract models

This module defines abstract models provided by the forum application.

class machina.apps.forum.abstract_models.AbstractForum(*args, **kwargs)

Bases: MPTTModel, DatedModel

The main forum model.

The tree hierarchy of forums and categories is managed by the MPTTModel which is part of django-mptt.

clean()

Validates the forum instance.

get_image_upload_to(filename)

Returns the path to upload a new associated image to.

property is_category

Returns True if the forum is a category.

property is_forum

Returns True if the forum is a a default forum.

Returns True if the forum is a link.

property margin_level

Returns a margin value computed from the forum node’s level.

Used in templates or menus to create an easy-to-see left margin to contrast a forum from their parents.

save(*args, **kwargs)

Saves the forum instance.

update_trackers()

Updates the denormalized trackers associated with the forum instance.

machina.apps.forum.abstract_models.get_forum_image_upload_to(instance, filename)

Returns a valid upload path for an image file associated with a forum instance.

Views

Forum views

This module defines views provided by the forum application.

class machina.apps.forum.views.ForumView(**kwargs)

Bases: PermissionRequiredMixin, ListView

Displays a forum and its topics. If applicable, its sub-forums can also be displayed.

get(request, **kwargs)

Handles GET requests.

get_context_data(**kwargs)

Returns the context data to provide to the template.

get_controlled_object()

Returns the controlled object.

get_forum()

Returns the forum to consider.

get_queryset()

Returns the list of items for this view.

send_signal(request, response, forum)

Sends the signal associated with the view.

class machina.apps.forum.views.IndexView(**kwargs)

Bases: ListView

Displays the top-level forums.

get_context_data(**kwargs)

Returns the context data to provide to the template.

get_queryset()

Returns the list of items for this view.

Visibility

The visibility module

This module provides helper classes to manage and compute values that should be displayed when considering a tree of forums. This includes post counts, topic counts, siblings, …

class machina.apps.forum.visibility.ForumVisibilityContentNode(obj)

Bases: object

Represents a forum object and its “visibility content”.

This class provides common properties that should help computing values such as posts counts or topics counts for a specific forum instance.

last_post

Returns the latest post associated with the node or one of its descendants.

last_post_on

Returns the latest post date associated with the node or one of its descendants.

next_sibling

Returns the next sibling of the current node.

The next sibling is searched in the parent node if we are not considering a top-level node. Otherwise it is searched inside the list of nodes (which should be sorted by tree ID) that is associated with the considered tree instance.

posts_count

Returns the number of posts associated with the current node and its descendants.

previous_sibling

Returns the previous sibling of the current node.

The previous sibling is searched in the parent node if we are not considering a top-level node. Otherwise it is searched inside the list of nodes (which should be sorted by tree ID) that is associated with the considered tree instance.

topics_count

Returns the number of topics associated with the current node and its descendants.

class machina.apps.forum.visibility.ForumVisibilityContentTree(nodes=None)

Bases: object

Represents a tree of ForumVisibilityContentNode instances.

Such a tree can be used to easily compute sums or “global” values associated with a given set of forum instances. It can be useful to display forum information to a user (eg. in a list of forums, etc.).

as_dict

Returns a dictionary of forum ID / related node.

forums

Returns a list of Forum instances associated with the underlying nodes.

classmethod from_forums(forums)

Initializes a ForumVisibilityContentTree instance from a list of forums.

root_level

Returns the root level of the considered tree.

top_nodes

Returns only the node without immediate parent.

visible_forums

Returns only the forum instances associated with the current tree.

visible_nodes

Returns only the visible nodes associated with the current tree.