Permalink
Browse files

Merge branch 'master' of https://github.com/bread-and-pepper/django-u…

  • Loading branch information...
2 parents f375fbf + e806456 commit 0aa654305ae0f56f8e06c0fbf52bb6f8ce6d0a62 BJ Dierkes committed Dec 7, 2011
View
@@ -13,6 +13,6 @@ Complete documentation about the
[F.A.Q.](http://docs.django-userena.org/en/latest/faq.html) is available on
[Read the Docs](http://docs.django-userena.org/en/latest/index.html).
-## [Demo](https://django-userena.org/)
+## [Demo](http://django-userena.org/)
-Want to test userena first, you can do just that at [django-userena.org](https://django-userena.org/).
+Want to test userena first, you can do just that at [django-userena.org](http://django-userena.org/).
View
@@ -1,2 +1,3 @@
-media/mugshots/*
-!.gitignore
+media/mugshots
+.epio-app
+settings_email.py
@@ -0,0 +1,17 @@
+# Django
+http://www.djangoproject.com/download/1.3/tarball/
+
+# Imaging library needed for easy_thumbnails
+http://effbot.org/downloads/Imaging-1.1.7.tar.gz
+
+# Thumbails used for mugshots
+easy-thumbnails
+
+# Django-guardian used for privacy settings
+django-guardian
+
+# Django-south for migrations
+South
+
+# Django-userena
+django-userena
View
@@ -0,0 +1,25 @@
+[wsgi]
+requirements = epio-requirements.txt
+
+[static]
+/media = media
+/media/admin = ../shortcuts/django-admin-media/
+/media/mugshots = ../data/mugshots
+
+[symlinks]
+media/mugshots = ../data/mugshots
+
+[services]
+postgres = true
+
+[cron]
+manage.py clean_users = 0 0 * * *
+
+[checkout]
+directory_name = demo_project
+
+[env]
+DJANGO_SETTINGS_MODULE = settings_epio
+
+[django]
+base = .
No changes.
@@ -0,0 +1,50 @@
+from django import forms
+from django.utils.translation import ugettext_lazy as _
+
+from userena.forms import SignupForm
+
+class SignupFormExtra(SignupForm):
+ """
+ A form to demonstrate how to add extra fields to the signup form, in this
+ case adding the first and last name.
+
+
+ """
+ first_name = forms.CharField(label=_(u'First name'),
+ max_length=30,
+ required=False)
+
+ last_name = forms.CharField(label=_(u'Last name'),
+ max_length=30,
+ required=False)
+
+ def __init__(self, *args, **kw):
+ """
+
+ A bit of hackery to get the first name and last name at the top of the
+ form instead at the end.
+
+ """
+ super(SignupFormExtra, self).__init__(*args, **kw)
+ # Put the first and last name at the top
+ new_order = self.fields.keyOrder[:-2]
+ new_order.insert(0, 'first_name')
+ new_order.insert(1, 'last_name')
+ self.fields.keyOrder = new_order
+
+ def save(self):
+ """
+ Override the save method to save the first and last name to the user
+ field.
+
+ """
+ # First save the parent form and get the user.
+ new_user = super(SignupFormExtra, self).save()
+
+ new_user.first_name = self.cleaned_data['first_name']
+ new_user.last_name = self.cleaned_data['last_name']
+ new_user.save()
+
+ # Userena expects to get the new user from this form, so return the new
+ # user.
+ return new_user
View
@@ -38,6 +38,7 @@
('fr', ugettext('French')),
('pl', ugettext('Polish')),
('pt', ugettext('Portugese')),
+ ('es', ugettext('Spanish')),
)
SITE_ID = 1
@@ -0,0 +1,5 @@
+from settings import *
+from settings_email import *
+from bundle_config import config
+
+DEBUG = False
View
@@ -2,12 +2,21 @@
from django.conf import settings
from django.views.generic.simple import direct_to_template
+from profiles.forms import SignupFormExtra
+
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
+
+ # Demo Override the signup form with our own, which includes a
+ # first and last name.
+ # (r'^accounts/signup/$',
+ # 'userena.views.signup',
+ # {'signup_form': SignupFormExtra}),
+
(r'^accounts/', include('userena.urls')),
(r'^messages/', include('userena.contrib.umessages.urls')),
url(r'^$',
View
@@ -1,7 +1,7 @@
.. _api-forms:
Forms
-==========
+=====
.. automodule:: userena.forms
@@ -13,13 +13,18 @@ SignupForm
.. autoclass:: userena.forms.SignupForm
:members:
+SignupFormOnlyEmail
+-------------------
+
+.. autoclass:: userena.forms.SignupFormOnlyEmail
+ :members:
+
SignupFormTos
-------------
.. autoclass:: userena.forms.SignupFormTos
:members:
-
AuthenticationForm
------------------
View
@@ -18,7 +18,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.append(os.path.abspath('..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'demo_project.settings'
-guardian = __import__('userena')
+userena = __import__('userena')
# -- General configuration -----------------------------------------------------
@@ -47,9 +47,9 @@
# built documents.
#
# The short X.Y version.
-version = '1.0.1'
+version = userena.get_version()
# The full version, including alpha/beta/rc tags.
-release = '1.0.1'
+release = userena.__version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
View
@@ -4,9 +4,95 @@ F.A.Q
=====
I get a "``Permission matching query does not exist``" exception
---------------------------------------------------------------
+----------------------------------------------------------------
Sometimes Django decides not to install the default permissions for a model
and thus the ``change_profile`` permission goes missing. To fix this, run the
``check_permissions`` in :ref:`commands`. This checks all permissions and adds
those that are missing.
+
+<ProfileModel> is already registered exception
+----------------------------------------------
+
+Userena already registered your profile model for you. If you want to
+customize the profile model, you can do so by registering your profile as
+follows:
+
+.. code-block:: python
+
+ # Unregister userena's
+ admin.site.unregister(YOUR_PROFILE_MODEL)
+
+ # Register your own admin class and attach it to the model
+ admin.site.register(YOUR_PROFILE_MODEL, YOUR_PROFILE_ADMIN)
+
+How do I add extra fields to forms?
+-----------------------------------
+
+This is done by overriding the default templates. A demo tells more than a
+thousand words. So here's how you add the first and last name to the signup
+form. First you override the signup form and add the fields.
+
+.. code-block:: python
+
+ django import forms
+ from django.utils.translation import ugettext_lazy as _
+
+ from userena.forms import SignupForm
+
+ class SignupFormExtra(SignupForm):
+ """
+ A form to demonstrate how to add extra fields to the signup form, in this
+ case adding the first and last name.
+
+
+ """
+ first_name = forms.CharField(label=_(u'First name'),
+ max_length=30,
+ required=False)
+
+ last_name = forms.CharField(label=_(u'Last name'),
+ max_length=30,
+ required=False)
+
+ def __init__(self, *args, **kw):
+ """
+
+ A bit of hackery to get the first name and last name at the top of the
+ form instead at the end.
+
+ """
+ super(SignupFormExtra, self).__init__(*args, **kw)
+ # Put the first and last name at the top
+ new_order = self.fields.keyOrder[:-2]
+ new_order.insert(0, 'first_name')
+ new_order.insert(1, 'last_name')
+ self.fields.keyOrder = new_order
+
+ def save(self):
+ """
+ Override the save method to save the first and last name to the user
+ field.
+
+ """
+ # First save the parent form and get the user.
+ new_user = super(SignupFormExtra, self).save()
+
+ new_user.first_name = self.cleaned_data['first_name']
+ new_user.last_name = self.cleaned_data['last_name']
+ new_user.save()
+
+ # Userena expects to get the new user from this form, so return the new
+ # user.
+ return new_user
+
+Finally, to use this form instead of our own, override the default URI by
+placing a new URI above it.
+
+.. code-block:: python
+
+ (r'^accounts/signup/$',
+ 'userena.views.signup',
+ {'signup_form': SignupFormExtra}),
+
+That's all there is to it!
View
@@ -13,21 +13,30 @@ downloads and installation instructions.
Installing django-userena.
--------------------------
-You can install django-userena automagicly with ``easy_install`` or ``pip``. Or
-manually placing it on on your ``PYTHON_PATH``.
+You can install django-userena automagicly with ``pip``. Or by manually
+placing it on on your ``PYTHON_PATH``. The recommended way is the shown in
+:ref:`pip-install`.
-I'm using `virtualenv <http://pypi.python.org/pypi/virtualenv>`_ to have an
-isolated python environment. This way it's possible to create a tailored
-environment for each project.
+NOTE: It is also recommended to use
+`virtualenv <http://pypi.python.org/pypi/virtualenv>`_ to have an isolated
+python environment. This way it's possible to create a tailored environment
+for each project.
-Automatic installation with easy_install.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.. _pip-install:
-Automatic install with `easy_install
-<http://peak.telecommunity.com/DevCenter/EasyInstall>`_. All you have to do is
+Automatic installation with pip.
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Automatic install with `pip
+<http://www.pip-installer.org/en/latest/index.html>`_. All you have to do is
run the following command::
- easy_install django-userena
+ pip install django-userena
+
+If you want to have a specific version of userena, you can do so by adding the
+following::
+
+ pip install django-userena==1.0.1
Manual installation with easy_install.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -42,9 +51,8 @@ Clone the Git repository from Github. Then you can direct easy_install to the
Automatic installation of development version with pip.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-You can tell `pip <http://pip.openplans.org/>`_ to install django-userena by
-supplying it with the git repository on Github. Do this by typing the following
-in your terminal::
+You can tell `pip`_ to install django-userena by supplying it with the git
+repository on Github. Do this by typing the following in your terminal::
pip install -e git+git://github.com/bread-and-pepper/django-userena.git#egg=userena
@@ -78,7 +86,9 @@ Begin by adding ``userena``, ``guardian`` and ``easy_thumbnails`` to the
Next add :class:``UserenaAuthenticationBackend`` and :class:``ObjectPermissionBackend``, from
django-guardian, at the top of ``AUTHENTICATION_BACKENDS``. If you only have
Django's default backend, adding django-guardian and that of userena will get
-the following::
+the following:
+
+.. code-block:: python
AUTHENTICATION_BACKENDS = (
'userena.backends.UserenaAuthenticationBackend',
@@ -121,7 +131,9 @@ from them:
**IMPORTANT**: The above profiles are ``abstract`` models. This means that you
cannot use them directly in ``AUTH_PROFILE_MODULE`` but you must create your
own profile model which inherits from one of the above models. This models
-must also connect itself to the :class:`User` model of Django. For ex::
+must also connect itself to the :class:`User` model of Django.
+
+.. code-block:: python
from userena.models import UserenaBaseProfile
@@ -149,14 +161,15 @@ Userena has a ``URLconf`` which set's all the url's and views for you. This
should be included in your projects root ``URLconf``.
For example, to place the URIs under the prefix ``/accounts/``, you could add
-the following to your project's root ``URLconf``::
+the following to your project's root ``URLconf``.
+
+.. code-block:: python
(r'^accounts/', include('userena.urls')),
This should have you a working accounts application for your project. See the
-:ref:`settings <settings>` and :ref:`templates <templates>` for further
-configuration options.
+:ref:`settings <settings>` for further configuration options.
Required settings
~~~~~~~~~~~~~~~~~
@@ -167,7 +180,9 @@ set this to ``-1``. As noted before, you are also required to set the
To integrate Django with userena you should alter the following three settings
to reflect the URI you have chosen for userena. For example, if userena lives
-under ``accounts``::
+under ``accounts``:
+
+.. code-block:: python
LOGIN_REDIRECT_URL = '/accounts/%(username)s/'
LOGIN_URL = '/accounts/signin/'
Oops, something went wrong.

0 comments on commit 0aa6543

Please sign in to comment.