User session tracking #93587

Merged
Oleg-Komarov merged 18 commits from user-session into main 2024-08-02 16:04:09 +02:00
2 changed files with 3 additions and 3 deletions
Showing only changes of commit 1f4e4db0d6 - Show all commits

View File

@ -689,5 +689,4 @@ class UserSession(models.Model):
def device(self):
if self.user_agent:
return user_agents.parse(self.user_agent)
else:
return None
return None
Oleg-Komarov marked this conversation as resolved Outdated

superfluous else

superfluous else

View File

@ -448,7 +448,8 @@ class ActiveSessionsView(LoginRequiredMixin, TemplateView):
class TerminateSessionView(LoginRequiredMixin, View):
def post(self, request, *args, **kwargs):
if user_session := self.request.user.sessions.filter(pk=kwargs.get('pk', 0)).first():
user_session_pk = kwargs.get('pk')
Oleg-Komarov marked this conversation as resolved Outdated

getting the pk (pk = kwargs['pk']: it's fine to expect it to be present at this point) and filtering the session on the separate line would make this more readable.

getting the `pk` (`pk = kwargs['pk']`: it's fine to expect it to be present at this point) and filtering the session on the separate line would make this more readable.
if user_session := self.request.user.sessions.filter(pk=user_session_pk).first():
user_session.session.delete()
user_session.delete()
return redirect('bid_main:active_sessions')