Sphene Community Tools

Community

Copyright © 2007-2018 by Herbert Poul

You are not logged in.
Login
Register

Change Language:



AddThis Social Bookmark Button

A Django site.

Powered by Sphene Community Tools

Tutorial

Tutorial

This is a simple tutorial what it needs to configure a simple Forum and Wiki for your website. It walks you through creating a new project and than adding the necessary confugration changes to integrate Forum and Wiki. These should be quite the same steps required to add it to your own website or an existing project.

1. Creating a new simple Django project

You should already know how to do this, it's just a standard django setup, but i'll still walk through all steps. I am using Django 1.4 here. (Django 1.4 has a significantly different default project setup)

1.1. Create a new project

$ django-admin.py startproject simpleproject

1.2. Configuring project to get it up and running

First of all, since i don't want to commit my database settings into subversion i'll create a simpleproject/settings_local.py and include it at the end of my simpleproject/settings.py:

# settings_local overwrites a few settings from here, and has to define SECRET_KEY
from simpleproject.settings_local import *

my simpleproject/settings_local.py contains:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'test.sqlite',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

now you can run syncdb:

Herbys-i7:simpleproject herbert$ ./manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'herbert'):
E-mail address: a@b.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

Because i am on Mac OSX i got the "ValueError: unknown locale: UTF-8" error, so i actually ran:

LC_CTYPE="en_US.UTF-8" ./manage.py syncdb

but i don't think this should be necessary often..

Ok, now after our syncdb the default django project should be stable and we can run it:

Herbys-i7:simpleproject herbert$ ./manage.py runserver
Validating models...

0 errors found
Django version 1.4b1, using settings 'simpleproject.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

I guess this was not too exciting for anyone, since you already use django, so let's go ahead!

2. Sphene Community Tools

2.1. Installation

First of all you have to install SCT (the communitytools project) - you can either download it and run setup.py or use the GIT version from https://github.com/hpoul/sct-communitytools

I usually prefer to have the GIT version, so i checked it out into the same directory and added the 'sct-communitytools/sphenecoll' path to the PYTHONPATH.

2.2. Project Configuration

Add the following applications to your INSTALLED_APPS:

    'south', # the only requirement for SCT
    'sphene.community', # base community features and utils (user profiles, etc.)
    'sphene.sphboard', # forum application
    'sphene.sphwiki', # very simple wiki application

2.3. Adding MIDDLEWARE_CLASSES and TEMPLATE_CONTEXT_PROCESSORS

SCT (currently) needs at least two middleware classes and one template context processor. Add the following to middlewares to the TOP of your MIDDLEWARE_CLASSES:

    'sphene.community.middleware.ThreadLocals',
    'sphene.community.middleware.GroupMiddleware',

To add the template context processor you need to modify TEMPLATE_CONTEXT_PROCESSOR - this variable is by default not set in the generated settings.py - so if you don't have it yet in your settings.py you have to add it:

# import the default values from django settings
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS

TEMPLATE_CONTEXT_PROCESSORS += (
    # add navigation middleware for SCT
    'sphene.community.context_processors.navigation',
)

2.4. Modifying urls.py

Now you have to wire up the three applications into your urls.py so modify simpleproject/urls.py and update it to match the following:

defaultdict = { 'groupName': 'example' }

urlpatterns = patterns('',
    url(r'^community/', include('sphene.community.urls'), defaultdict),
    url(r'^board/', include('sphene.sphboard.urls'), defaultdict),
    url(r'^wiki/', include('sphene.sphwiki.urls'), defaultdict),
)

(the meaning of 'groupName' is described further below.)

2.5. Synchronizing tables

After adding the community projects, run syncdb again which will create all necessary tables. (Because of south you have to use syncdb --all and migrate --fake for the first time. Whenever you upgrade SCT you have to run: ./manage.py migrate).

./manage.py syncdb --all
./manage.py migrate --fake

2.6. Create base template

SCT requires a template called base.html which has at least a block called "content" and one called "head". To make this easier we will create a small community app which hosts only your template. If you are integrating SCT into your own project, you probably already have a base template.

./manage.py startapp mysitecommunity

and add 'mysitecommunity' to INSTALLED_APPS in settings.py

Now create a template directory and edit base.html

Herbys-i7:simpleproject herbert$ mkdir mysitecommunity/templates
Herbys-i7:simpleproject herbert$ vi mysitecommunity/templates/base.html

which looks like:

<html>
<head>
  <title>Example Project</title>
  {% block head %}
  {% endblock %}
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>

For a more complete example you can look into the simpleproject example in the subversion repository.

2.7. And we are done

Now start your project with ./manage.py runserver and head over to http://127.0.0.1:8000/board/ - You should see a very simple forum application.

3. Community Groups

In SCT everything is based on 'Community Groups' - every forum or wiki snip is part of a 'Group' - This Group has nothing to do with the user groups which is basically only for assigning permissions - a community group is more similar to the concept of the Sites Application since every community Group has one URL assigned. The main difference is tough, that Community Groups are ment to be hosted on the same django instance with the same configuration, while Sites have a different configuration for each 'Site'.

When running syncdb SCT will by default create a 'example' Community Groups which we have configured in our urls.py to use. You can configure or create more Community Groups in the Django Admin interface:

Anyway .. first of all ... we need to get into the admin web interface.. so we need to assign an URL: open urls.py and uncomment the following line:

 (r'^admin/', include('django.contrib.admin.urls')),

Now run the project using: "./manage.py runserver" and head over to your admin page, propably: http://127.0.0.1:8000/admin/

There you need to login with your superuser - user you created with the first 'syncdb' call and head over to 'Community' -> 'Groups' (NOT Auth -> Groups) and click 'Add group'. Enter something like:

The only important for now is the 'name' .. i assume below that we have a group called 'example' which .. will be the only one we want (for now) ...

Last Modified: 2012-06-04 10:05:02 by Herbert Poul - [ Snip Changes ] [ Wiki History ]

3 Comments

Customize List
Anonymous
2569
5
2010-07-22 05:56:00
Anonymous
1840
1
2010-03-24 14:22:53
Anonymous
2297
4
2010-01-20 23:32:46
3 Threads

Please login to create a new thread.



Powered by Sphene Community Tools