Skip to content
Snippets Groups Projects
Commit 29efc8ed authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

notify that assemblies and job are associated on log in

parent 3033bba9
No related tags found
1 merge request!24Draft: notify that assemblies and jobs are associated on log in
Pipeline #155992 passed
from basetheme_bootstrap.forms import AuthenticationForm
from django.contrib import messages
from django.contrib.auth import login
from django.contrib.messages.context_processors import messages
from django.contrib.sessions.models import Session
from django.shortcuts import render, redirect
......@@ -22,19 +24,22 @@ def loginView(request):
if session_key:
try:
session = Session.objects.get(session_key=session_key)
models.SimulatorJob.objects.filter(
owning_session=session,
).update(
owner=user,
owning_session=None,
)
models.Assembly.objects.filter(
owning_session=session,
).update(
owner=user,
owning_session=None,
)
for klass in [
models.SimulatorJob,
models.Assembly,
]:
instance_to_migrate = klass.objects.filter(
owning_session=session,
)
if instance_to_migrate.exists():
messages.success(
f"We successfully associated {instance_to_migrate.count()} "
f"{klass._meta.verbose_name_plural.title()} with your account."
)
instance_to_migrate.update(
owner=user,
owning_session=None,
)
except Session.DoesNotExist:
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment