Skip to content

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouke committed Jan 8, 2014
1 parent c7e1088 commit 4a2709f
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 1 deletion.
Binary file added docs/_static/admin-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/custom-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,6 @@

# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False

from django.conf import settings
settings.configure(DEBUG=False)
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Contents:
:maxdepth: 2

installation

usage
reference


Indices and tables
Expand Down
10 changes: 10 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Reference
=========

.. autoclass:: user_sessions.views.SessionListView
.. autoclass:: user_sessions.views.SessionDeleteView

Unit tests
----------

.. autoclass:: user_sessions.utils.
39 changes: 39 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Usage
=====

Current session
---------------
The current session is available on the request, just like the normal session
middleware makes the session available::

def my_view(request):
request.session


All sessions
------------
To get the list of a user's sessions::

sessions = user.session_set.filter(expire_date__gt=now())

You could logout the user everywhere::

user.session_set.all().delete()

Generic views
-------------
There are two views included with this application,
:class:`~user_sessions.views.SessionListView` and
:class:`~user_sessions.views.SessionDeleteView`. Using this views you have a
simple, but effective, user session management that even looks great without
any additional styling:

.. image:: _static/custom-view.png

Admin views
-----------

The user's IP address and user agent are also stored on the session. This
allows to show a list of active sessions to the user in the admin:

.. image:: _static/admin-view.png
13 changes: 13 additions & 0 deletions user_sessions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ def dispatch(self, request, *args, **kwargs):


class SessionListView(LoginRequiredMixin, SessionMixin, ListView):
"""
View for listing a user's own sessions.
This view shows list of a user's currently active sessions. You can
override the template by providing your own template at
`user_sessions/session_list.html`.
"""
def get_context_data(self, **kwargs):
kwargs['session_key'] = self.request.session.session_key
return super(SessionListView, self).get_context_data(**kwargs)


class SessionDeleteView(LoginRequiredMixin, SessionMixin, DeleteView):
"""
View for deleting a user's own session.
This view allows a user to delete an active session. For example locking
out a session from a computer at the local library or a friend's place.
"""
def get_success_url(self):
return str(reverse_lazy('user_sessions:session_list'))

0 comments on commit 4a2709f

Please sign in to comment.