User Pages
The "user" portion of the site consists of pages such as My Profile, My Portfolio, Impact and Status.
It is important to distinguish between the viewing user and data (or viewed) user:
- viewing user: The person who is logged in
- data user: The person whose data is being displayed
All user pages require a viewing user. That is, one must be logged in to view any user page. The python decorator for this is @user_criteria(logged_in)
Some user pages are @private, meaning that the viewing user must be the same as the data user (eg, when editing user data or inviting friends).
Template Variables
All user pages supply the following variables:
- user: the viewing user
- datauser: the data user
- mirror: true if the viewing user and data user are the same
URL
All user pages have a similar url naming scheme:
{% url impact user.id %}Remember that outside of the user pages there may be no viewing user. Specifically, there is a user variable, however it is an AnonymousUser? and lacks an id. Thus, user.id is blank and so {% url impact user.id %} will throw an exception.
To test whether a user is logged in use
{% if user.is_authenticated %}
user is logged in
{% else %}
user is not logged in (anonymous)
{% endif %}One can also test whether a user has staff or superuser privileges by using {% if user.is_staff %} and {% if user.is_superuser %}.