Django based forum engine
Hello. I have set up a djangobb project on a site, and through the admin interface I have setup three Groups, and some Categories where the appropriate Groups have permissions.
However, when a new user is registered, they haven't any default group, so they have no permissions at all.
How can I setup a new User to belong to a specific Group by default? Note that I might have missed some step of the forum setup, all the documentation I found was scattered and mostly incomplete.
Thanks in advance.
Offline
More correct question: “as do this in django?”
Check django-registration (or what you uses?) registration.signals.user_registered signal and group in handler
Offline
I'm sorry, I'm very new with django. I assumed I could do that from the web administration interface.
I'm using a basic_project forum and the registration module, with so far untouched code. Where would I add code so that upon user registration, the user becomes automatically a member of the “Users” group?
Searching the web, I found that I got to do something along the lines:
from registration.signals import user_registered user_registered.connect(new_user_created)
Offline
Since the documentation says “connect the signal anywhere in an imported module”, I added the code in local_settings.py (I imagine it's a gross misuse of the file but it works; I will try to make it more “clean” somehow). The function “new_user_created” works now.
So I have to do something like
user.groups.add(users_group)
Edited tzot (Dec. 28, 2012 12:26:50)
Offline
put this code in models.py of your custom app:
from registration.signals import *
from django.contrib.auth.models import Group
from django.dispatch import receiver
# Create your models here.
@receiver(user_registered)
def add_group_to_user(sender, user, request, **kwargs):
defaultgroup = Group.objects.get(name = ‘normaluser’)
if defaultgroup:
user.groups.add(defaultgroup)
'normaluser' is the name of your default group
Offline
had thought about it, but did not grow together, in principle, it is easier than the current version, can be in the distant future, and implements
Offline