Simple Forums

Code Health

Goals

Simple forums aims to be a basic forum package for django that allows for creation of a basic forum in which there are various categories that each have user created threads under them.

License

This project is licensed under the GPL v3 license.

Contents

Overview

Requirements

  • Python 2.7, 3.3 [*], 3.4, or 3.5
  • Django 1.8+
  • bleach, bleach-whitelist, markdown, and pymdown-extensions [†]
[*]Python 3.3 is only supported for django versions < 1.9
[†]All these extensions are automatically installed if using pip

Features

  • Threads are separated into different topics to allow for easy organization
  • Easily swappable rendering solutions for markup

Installation

Django

Download

The easiest way to install simple forums is as a python package through pip:

$ pip install django-simple-forums
Installing

In settings.py:

INSTALLED_APPS = [
    ...
    # default django apps
    'adminsortable',
    'simple_forums',

    # If you want email notification functionality, add the following:
    'simple_forums.notifications',
    ...
]

If you would like an easy way to keep track of installed apps within your templates, add the following context processor (in settings.py):

TEMPLATES = [
    {
        'OPTIONS': {
            'context_processors': [
                # other context processors
                'simple_forums.context_processors.installed_apps',
            ],
        },
    },
]

In urls.py:

urlpatterns = [
    ...
    url(r'^forums/', include('simple_forums.urls')),
    ...
]
Note About Including URLs

If you don’t give the app a namespace (like include('simple_forums.urls', namespace='forum')), then you must add the namespace simple-forums when you reference URLs. Example:

# In a template file

{% url 'simple-forums:index' %}


# In a .py file

reverse('simple-forums:index')

Post-Installation

Apply the migrations for simple forums:

$ ./manage.py migrate

On your server, visit the admin page and start creating topics for users to post under.

Configuration

All configuration options for simple forums should be placed in a dictionary called SIMPLE_FORUMS in settings.py. Example:

SIMPLE_FORUMS = {
    'markup_renderer': 'simple_forums.markup_renderers.MarkdownRenderer',
}

Available Settings

markdown_extensions (=[‘pymdownx.github’])
A list of extensions to process markdown with. Only has an effect if MarkdownRenderer is used. The default list of extensions is defined in simple_forums.markup_renderers.MarkdownRenderer.DEFAULT_EXTENSIONS.
markup_renderer (=’simple_forums.backends.renderers.TextRenderer’)

This class specifies which form of markup should be used to render posts. Currently there is a choice between plain text and Markdown.

Choices:
  • 'simple_forums.backends.renderers.MarkdownRenderer'
  • 'simple_forums.backends.renderers.TextRenderer'
search_backend
A dictionary containing the settings for the search engine to use. See the Searching section for more details.

Templates

All of the following templates can be overriden by a template in the templates/simple_forums directory.

base.html
This is the base template for all the other templates. It defines the general layout of each page and contains the navigation.
login.html

This template is used if the default login view is used, which is really the default login view from Django’s authentication system.

Context:
  • form: The login form itself.

  • next: The url to redirect to after a successful login. Example usage:

    <input type="hidden" name="next" value="{{ next }}" />
    
search.html

Used for the search view. It contains a search form and an area for displaying search results.

Context:
  • query: The query string being searched for. This is only set if the query string is not blank.
  • results: Contains all of the objects that matched the query. These objects may be instances of the Thread or Message models.
thread_create.html

Used in the view for creating new threads.

Context:
  • form: The form for thread creation.
thread_detail.html

Template used when displaying a thread and all of its replies. This template is also responsible for showing the reply form.

Context:
  • reply_form: The form used to reply to the current thread.
  • thread: The current thread.
thread_list.html

Used to show the list of threads for a topic.

Context:
  • thread_list: A list of all the non-sticky threads in the topic.
  • topic: The topic whose threads are being listed.
  • sort_current: The name of the current sort option.
  • sort_options: A list of all possible sorting options.
  • sort_reversed: True if the current sorting order is reversed, False otherwise.
  • sticky_thread_list: A list of all the sticky threads in the topic.
topic_list.html

Used to list the topics in the forum.

Context:
  • topic_list: A list of all the topics in the forum.

Searching

Simple forums currently has a basic search engine that performs a keyword search over the titles of all the threads in the forum as well as the option to use the third party search engine elasticsearch.

Elasticsearch

Class: simple_forums.backends.search.ElasticSearch

Requires Installation of the elasticsearch-py package.

This backend connects to an elasticsearch server using the given credentials and uses it to perform searches. It is much more powerful than the Simple Search backend because it has the ability to search through replies to threads rather than just the thread titles.

Configuration Options:

host (Required): The hostname of the elasticsearch server

port (Required): The port to connect to the elasticsearch server on

index: The name of the elasticsearch index to use

Notifications

Configuration

To use email notifications, you must add 'simple_forums.notifications' to INSTALLED_APPS. Don’t forget to run your database migrations after doing that.

The other requirement for notifications is to have your email settings correctly configured. The crucial settings are EMAIL_HOST and EMAIL_PORT. For more information, refer to the django documentation.

Templates

To include notifications-specific items in your templates, you can use the variables provided by simple forums’ context processor (if installed). Example:

# my_app/my_template.html

{% if notifications_installed %}
    {{ notification_form }}
{% endif %}

Changelog

v1.3.4

Bug Fixes
  • Fix issue where fix for #41 didn’t work in Django < 1.9

v1.3.3

Bug Fixes
  • Fix #41: Using a namespace when including the app doesn’t cause submitting forms to break

v1.3.1

Features
  • Close #42: Allowing template tags to generate login/logout urls to take a view name as an optional parameter

v1.3.0

Features
  • Close #12: Adding ids to comments so they can be linked to
  • Close #28: Using django-admin-sortable to allow for re-ordering of topics in the admin interface
  • Close #29: Adding the option to use elasticsearch for searching
  • Close #32: Adding email notification system.

v1.2.0

Features
  • Close #13: Adding ability to sort thread listing.

v1.1.1

Bug Fixes
  • Fix #21: Specifying markdown output format as html5.
  • Fix #24: Removing dependency on bleach-whitelist package.
General
  • Close #25: Adding documentation for templates and searching.

v1.1.0

Features
  • Close #18: Adding a basic search engine.

v1.0.9

Bug Fixes:
  • Fix #23: Fixing issue where submitting a blank reply to a thread caused an error.

Indices and tables