Invitation to the Dance (film) (Photo credit: Wikipedia) |
Django logo (Photo credit: Wikipedia) |
In this post, I will explain you how to use the great Playing django-invitation module, which as its name indicates permits to invite people to the beta of a web app, for example.
The documentation of the django-invitation module is accessible on https://bitbucket.org/david/django-invitation/wiki/Home
To install the module, I have used:
easy_install -Z django-invitation
I have followed the documentation. It indicates to:
-
Add the setting ACCOUNT_INVITATION_DAYS to your settings file; this should be the number of days invitation keys will remain valid after an invitation is sent. Add also the INVITATIONS_PER_USER setting.
At this step, I have the following lines in my settings.py:
ACCOUNT_ACTIVATION_DAYS = 7
ACCOUNT_INVITATION_DAYS = 7
INVITATIONS_PER_USER = 3
INVITE_MODE = True
NB: they forget to talk about the INVITE_MODE setting in django-invitation's documentation. It took me half a day to figure out why invalid invitation key still led to the registration form !
Then the tutorial says to add this line to your site's root URLConf before registration urls:
-
(r'^accounts/', include('invitation.urls')),
Afterwards, modify templates to link people to /accounts/invite/ so they can start inviting. I prefer to refer to this url by its name in my template : invitation_invite (according to the source code on bit bucket)
Now create all the required templates:
- invitation/invitation_form.html displays the invitation form for users to invite contacts.
- invitation/invitation_complete.html is displayed after the invitation email has been sent, to tell the user his contact has been emailed.
- invitation/invitation_email_subject.txt is used for the subject of the invitation email.
- invitation/invitation_email.txt is used for the body of the invitation email.
- invitation/invited.html is displayed when a user attempts to register his/her account.
- invitation/wrong_invitation_key.html is displayed when a user attempts to register his/her account with a wrong/expired key.
I used a direct link to the registration page in the invitation email, as the invited page is pretty useless in my opinion. Here is my invitation_email.txt:
{% load i18n %}{% load url from future %}
{% trans "Hello," %}
{% blocktrans with site.name as sitename and invitation_key.from_user.username as username %}You have been invited by {{ username }} to join {{ sitename }}!{% endblocktrans %}
{% trans "Go to" %}
http://{{site.domain}}{% url 'registration_register' %}?invitation_key={{ invitation_key.key }}
{% trans "to join!" %}
{% blocktrans with site.name as sitename %}All the best,
The {{ sitename }} Team{% endblocktrans %}
Then just setup a cronjob calling the django command cleanupinvitation
to delete expired activation keys from the database.
Leave a Reply