Views¶
signup¶
- userena.views.signup(request, signup_form=<class 'userena.forms.SignupForm'>, template_name='userena/signup_form.html', success_url=None, extra_context=None)¶
Signup of an account.
Signup requiring a username, email and password. After signup a user gets an email with an activation link used to activate their account. After successful signup redirects to
success_url
.- Parameters
signup_form – Form that will be used to sign a user. Defaults to userena’s
SignupForm
.template_name – String containing the template name that will be used to display the signup form. Defaults to
userena/signup_form.html
.success_url – String containing the URI which should be redirected to after a successful signup. If not supplied will redirect to
userena_signup_complete
view.extra_context – Dictionary containing variables which are added to the template context. Defaults to a dictionary with a
form
key containing thesignup_form
.
Context
form
Form supplied by
signup_form
.
activate¶
- userena.views.activate(request, activation_key, activation_form=<class 'userena.forms.ActivationForm'>, template_name='userena/activate_form.html', fail_template_name='userena/activate_fail.html', retry_template_name='userena/activate_retry.html', success_url=None, extra_context=None)¶
Activate a user with an activation key.
The key is a nonce. When the nonce is found with an
UserenaSignup
, theUser
of that account will be activated. After a successful activation the view will redirect tosuccess_url
. If the nonce is not found, the user will be shown thetemplate_name
template displaying a fail message. If the nonce is found but expired,retry_template_name
is used instead, so the user can proceed toactivate_retry()
to get a new activation key.- Parameters
activation_key – Cryptographically generated string, 40 characters long
activation_form – Form to use for activating the user. Defaults to
ActivationForm
supplied by userena.template_name – String defining the name of the template to use. Defaults to
userena/activate_form.html
.fail_template_name – String containing the template name that is used when the
activation_key
is invalid and the activation fails. Defaults touserena/activate_fail.html
.retry_template_name – String containing the template name that is used when the
activation_key
is expired. Defaults touserena/activate_retry.html
.success_url – String containing the URL where the user should be redirected to after a successful activation. Will replace
%(username)s
with string formatting if supplied. Ifsuccess_url
is left empty, will direct touserena_profile_detail
view.extra_context – Dictionary containing variables which could be added to the template context. Default to an empty dictionary.
email_confirm¶
- userena.views.email_confirm(request, confirmation_key, template_name='userena/email_confirm_fail.html', success_url=None, extra_context=None)¶
Confirms an email address with a confirmation key.
Confirms a new email address by running
User.objects.confirm_email()
method. If the method returns anUser
the user will have his new e-mail address set and redirected tosuccess_url
. If noUser
is returned the user will be represented with a fail message fromtemplate_name
.- Parameters
confirmation_key – String with representing the confirmation key used to verify a new email address.
template_name – String containing the template name which should be rendered when confirmation fails. When confirmation is successful, no template is needed because the user will be redirected to
success_url
.success_url – String containing the URL which is redirected to after a successful confirmation. Supplied argument must be able to be rendered by
reverse
function.extra_context – Dictionary of variables that are passed on to the template supplied by
template_name
.
direct_to_user_template¶
- userena.views.direct_to_user_template(request, username, template_name, extra_context=None)¶
Simple wrapper for Django’s
direct_to_template()
view.This view is used when you want to show a template to a specific user. A wrapper for
direct_to_template()
where the template also has access to the user that is found withusername
. For ex. used after signup, activation and confirmation of a new e-mail.- Parameters
username – String defining the username of the user that made the action.
template_name – String defining the name of the template to use. Defaults to
userena/signup_complete.html
.
Keyword arguments
extra_context
A dictionary containing extra variables that should be passed to the rendered template. The
account
key is always theUser
that completed the action.
Extra context
viewed_user
The currently
User
that is viewed.
signin¶
- userena.views.signin(request, auth_form=<class 'userena.forms.AuthenticationForm'>, template_name='userena/signin_form.html', redirect_field_name='next', redirect_signin_function=<function signin_redirect>, extra_context=None)¶
Signin using email or username with password.
Signs a user in by combining email/username with password. If the combination is correct and the user
is_active()
theredirect_signin_function()
is called with the argumentsREDIRECT_FIELD_NAME
and an instance of theUser
who is is trying the login. The returned value of the function will be the URL that is redirected to.A user can also select to be remembered for
USERENA_REMEMBER_DAYS
.- Parameters
auth_form – Form to use for signing the user in. Defaults to the
AuthenticationForm
supplied by userena.template_name – String defining the name of the template to use. Defaults to
userena/signin_form.html
.redirect_field_name – Form field name which contains the value for a redirect to the succeeding page. Defaults to
next
and is set inREDIRECT_FIELD_NAME
setting.redirect_signin_function – Function which handles the redirect. This functions gets the value of
REDIRECT_FIELD_NAME
and theUser
who has logged in. It must return a string which specifies the URI to redirect to.extra_context – A dictionary containing extra variables that should be passed to the rendered template. The
form
key is always theauth_form
.
Context
form
Form used for authentication supplied by
auth_form
.
email_change¶
- userena.views.email_change(request, username, email_form=<class 'userena.forms.ChangeEmailForm'>, template_name='userena/email_form.html', success_url=None, extra_context=None)¶
Change email address
- Parameters
username – String of the username which specifies the current account.
email_form – Form that will be used to change the email address. Defaults to
ChangeEmailForm
supplied by userena.template_name – String containing the template to be used to display the email form. Defaults to
userena/email_form.html
.success_url – Named URL where the user will get redirected to when successfully changing their email address. When not supplied will redirect to
userena_email_complete
URL.extra_context – Dictionary containing extra variables that can be used to render the template. The
form
key is always the form supplied by the keyword argumentform
and theuser
key by the user whose email address is being changed.
Context
form
Form that is used to change the email address supplied by
form
.account
Instance of the
Account
whose email address is about to be changed.
Todo
Need to have per-object permissions, which enables users with the correct permissions to alter the email address of others.
password_change¶
- userena.views.password_change(request, username, template_name='userena/password_form.html', pass_form=<class 'django.contrib.auth.forms.PasswordChangeForm'>, success_url=None, extra_context=None)¶
Change password of user.
This view is almost a mirror of the view supplied in
contrib.auth.views.password_change()
, with the minor change that in this view we also use the username to change the password. This was needed to keep our URLs logical (and REST) across the entire application. And that in a later stadium administrators can also change the users password through the web application itself.- Parameters
username – String supplying the username of the user who’s password is about to be changed.
template_name – String of the name of the template that is used to display the password change form. Defaults to
userena/password_form.html
.pass_form – Form used to change password. Default is the form supplied by Django itself named
PasswordChangeForm
.success_url – Named URL that is passed onto a
reverse()
function withusername
of the active user. Defaults to theuserena_password_complete
URL.extra_context – Dictionary of extra variables that are passed on to the template. The
form
key is always used by the form supplied bypass_form
.
Context
form
Form used to change the password.
profile_edit¶
- userena.views.profile_edit(request, username, edit_profile_form=<class 'userena.forms.EditProfileForm'>, template_name='userena/profile_form.html', success_url=None, extra_context=None, **kwargs)¶
Edit profile.
Edits a profile selected by the supplied username. First checks permissions if the user is allowed to edit this profile, if denied will show a 404. When the profile is successfully edited will redirect to
success_url
.- Parameters
username – Username of the user which profile should be edited.
edit_profile_form – Form that is used to edit the profile. The
EditProfileForm.save()
method of this form will be called when the formEditProfileForm.is_valid()
. Defaults toEditProfileForm
from userena.template_name – String of the template that is used to render this view. Defaults to
userena/edit_profile_form.html
.success_url – Named URL which will be passed on to a django
reverse
function after the form is successfully saved. Defaults to theuserena_detail
url.extra_context – Dictionary containing variables that are passed on to the
template_name
template.form
key will always be the form used to edit the profile, and theprofile
key is always the edited profile.
Context
form
Form that is used to alter the profile.
profile
Instance of the
Profile
that is edited.
profile_detail¶
- userena.views.profile_detail(request, username, template_name='userena/profile_detail.html', extra_context=None, **kwargs)¶
Detailed view of an user.
- Parameters
username – String of the username of which the profile should be viewed.
template_name – String representing the template name that should be used to display the profile.
extra_context – Dictionary of variables which should be supplied to the template. The
profile
key is always the current profile.
Context
profile
Instance of the currently viewed
Profile
.
profile_list¶
- userena.views.profile_list(request, page=1, template_name='userena/profile_list.html', paginate_by=50, extra_context=None, **kwargs)¶
Returns a list of all profiles that are public.
It’s possible to disable this by changing
USERENA_DISABLE_PROFILE_LIST
toTrue
in your settings.- Parameters
page – Integer of the active page used for pagination. Defaults to the first page.
template_name – String defining the name of the template that is used to render the list of all users. Defaults to
userena/list.html
.paginate_by – Integer defining the amount of displayed profiles per page. Defaults to 50 profiles per page.
extra_context – Dictionary of variables that are passed on to the
template_name
template.
Context
profile_list
A list of profiles.
is_paginated
A boolean representing whether the results are paginated.
If the result is paginated. It will also contain the following variables.
paginator
An instance of
django.core.paginator.Paginator
.page_obj
An instance of
django.core.paginator.Page
.