Skip to content

Commit

Permalink
Implemented delete-all-but-current sessions view
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouke committed May 17, 2014
1 parent 9356e08 commit bdd56e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
11 changes: 6 additions & 5 deletions user_sessions/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf.urls import patterns, url
from user_sessions.views import SessionDeleteOtherView

from .views import SessionListView, SessionDeleteView

Expand All @@ -12,13 +13,13 @@
name='session_list',
),
url(
regex=r'^account/sessions/(?P<pk>\w+)/delete/$',
view=SessionDeleteView.as_view(),
name='session_delete',
regex=r'^account/sessions/other/delete/$',
view=SessionDeleteOtherView.as_view(),
name='session_delete_other',
),
url(
regex=r'^account/sessions/other/delete/$',
regex=r'^account/sessions/(?P<pk>\w+)/delete/$',
view=SessionDeleteView.as_view(),
name='session_delete_other',
name='session_delete',
),
)
21 changes: 19 additions & 2 deletions user_sessions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from django.core.urlresolvers import reverse_lazy
from django.utils.decorators import method_decorator
from django.utils.timezone import now
from django.views.generic import ListView, DeleteView
from django.views.generic import ListView, DeleteView, View
from django.views.generic.edit import DeletionMixin


class SessionMixin(object):
Expand Down Expand Up @@ -35,8 +36,24 @@ 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
This view allows a user to delete an active session. For example log
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'))


class SessionDeleteOtherView(LoginRequiredMixin, SessionMixin, DeletionMixin, View):
"""
View for deleting all user's sessions but the current.
This view allows a user to delete all other active session. For example
log out all sessions from a computer at the local library or a friend's
place.
"""
def get_object(self):
return super(SessionDeleteOtherView, self).get_queryset().\
exclude(session_key=self.request.session.session_key)

def get_success_url(self):
return str(reverse_lazy('user_sessions:session_list'))

0 comments on commit bdd56e0

Please sign in to comment.