Sphene Community Tools

Community

Copyright © 2007-2009 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

If you want to get started with SCT quickly, please use the CommunityDraft project instead.

This describes what is needed to start a new project from scratch which uses the Board and Wiki of SCT.

It actually contains just a couple of notes i wrote down while creating the communitytools/examples/simpleproject - project ;) (See SimpleProject)

To get a full featured website see CommunityDraft which should work out of the box.

1. Prerequisites

Make sure you've done everything mentioned in the INSTALLATION section of the README or on the Documentation site.

2. Creating a new project

Good, this was easy ;)

kahless@localhost ~/dev/python-new/communitytools/examples $ django-admin.py startproject simpleproject
kahless@localhost ~/dev/python-new/communitytools/examples $

3. 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 settings_local.py ... This needs two things..

so at the end of settings.py add:

import os
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
LIB_PATH = os.path.join(ROOT_PATH, '..', '..', 'sphenecoll')
# import directory of settings.py
import sys
sys.path.append(ROOT_PATH)

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

Now simply create a settings_local.py in the same directory and configure all DATABASE_ settings.

And run syncdb:

kahless@localhost ~/dev/python-new/communitytools/examples/simpleproject $ ./manage.py syncdb
Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
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 'kahless'): kahless
E-mail address: herbert.poul@gmail.com
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Message model
Installing index for auth.Permission model
kahless@localhost ~/dev/python-new/communitytools/examples/simpleproject $

So ... your default django project should already run ....

kahless@localhost ~/dev/python-new/communitytools/examples/simpleproject $ ./manage.py runserver
Validating models...
0 errors found.

Django version 0.96-pre, using settings 'simpleproject.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Uh yeah .. not that new, is it ;)

4. Adding 'Sphene Community Tools' Applications

So now it is time to add the SCT applications. First of all we need to add the python library path. You might want to configure it in your mod_python config, or where ever .. since i want to keep it simple and i actually have my project under 'communitytools' .. i can simply include ../../

So let's add the following to settings.py right after were we added sys.path.append(ROOT_PATH):

sys.path.append(LIB_PATH)

Now look for your INSTALLED_APPS setting and add the default django admin application as well as the three SCT apps .. all in all it should look like:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',

    'django.contrib.admin',

    'sphene.community',
    'sphene.sphboard',
    'sphene.sphwiki',
)

5. Adding MIDDLEWARE_CLASSES and TEMPLATE_CONTEXT_PROCESSORS

SCT (currently) needs at least two middleware classes and two template context processor .. All in all the two settings should look like the following in your settings.py:

MIDDLEWARE_CLASSES = (
    'sphene.community.middleware.ThreadLocals',
    'sphene.community.middleware.GroupMiddleware',

    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.doc.XViewMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'sphene.community.context_processors.navigation',
)

6. Validating template loaders

Make sure you have the application template loader in your TEMPLATE_LOADERS setting ('django.template.loaders.app_directories.load_template_source')

for example:

TEMPLATE_LOADERS = (
    'sphene.community.groupaware_templateloader.load_template_source',
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
)

7. Adding Template Directories

We need to add our template directories ..

Therefore edit settings.py and after setting ROOT_PATH = os.path.dirname(..) we created previously add the following:

TEMPLATE_DIRS = (
    os.path.join(ROOT_PATH,'sitetemplates'),
)

8. Creating base template

SCT expects to find a 'base.html' template with a 'content' block, so we need to create a simple template. Therefore.. create the directory 'sitetemplates' and a file called 'base.html' with (for example) the following content:

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

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

9. Running syncdb (again)

Since we've now finished configuration (almost) ... run "./manage.py syncdb" again, which will create a couple of tables...

10. Creating example Group

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'.

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) ...

11. Create url conf entries for SCT

Edit urls.py and modify it to look something like:

from django.conf.urls.defaults import *
from django.conf import settings

defaultdict = { 'groupName': 'example' }

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

    # Only for development
    (r'^static/sphene/(.*)$', 'django.views.static.serve', {'document_root': settings.ROOT_PATH + '/../../static/sphene' }),

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

12. Running the project - Wiki

So .. now .. run your project again using: "./manage.py runserver" and head over to http://127.0.0.1:8000/wiki/ which redirects you to http://127.0.0.1:8000/wiki/show/Start/

This is not that spectecular ... but .. you should already see something like:

Snip Start does not yet exist. Create It.

If you click on 'Create It' you can edit it .. and save it .. hopefully .. which should give you an idea on how to use the wiki ;)

13. Configuring the Board

The board is a little more complex, since it does not yet come with custom admin interface you have to use django's. So go back to http://127.0.0.1:8000/admin/ and in Sphboard -> Categorys click 'Add' and enter the following:

After Creating this entry you can head over to http://127.0.0.1:8000/board/ and have your first Category where you can post your threads, polls & co ;)

14. Have Fun !

OK .. now .. i expect you've completed this "tutorial" and everything worked, and you are completely happy with your life ..

Anyway, if you encounter any problems don't hesitate to contact me through the Board or directly by email: herbert.poul@gmail.com

Last Modified: 2008-04-19 11:23:09 by Herbert Poul - [ Snip Changes ] [ Wiki History ]

0 Comments

No comments yet.

Post New Thread



Powered by Sphene Community Tools