From e1441af9a3a78511af185d62adbe077b544b80a3 Mon Sep 17 00:00:00 2001 From: makram89 Date: Fri, 28 Jan 2022 00:00:44 +0100 Subject: [PATCH] docker - kinda works --- MUOR/MUOR/DockerManager.py | 1 - MUOR/MUOR/signals.py | 21 ++++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/MUOR/MUOR/DockerManager.py b/MUOR/MUOR/DockerManager.py index 9314ddee1..bc45f6b0d 100644 --- a/MUOR/MUOR/DockerManager.py +++ b/MUOR/MUOR/DockerManager.py @@ -1,5 +1,4 @@ import docker -from models import Profile import hashlib diff --git a/MUOR/MUOR/signals.py b/MUOR/MUOR/signals.py index 185ee0a87..799498b55 100644 --- a/MUOR/MUOR/signals.py +++ b/MUOR/MUOR/signals.py @@ -1,7 +1,7 @@ from django.db.models.signals import post_save from django.dispatch import receiver -from DockerManager import DockerManager -from models import Profile, Session +from .DockerManager import DockerManager +from .models import Profile, Session from django.contrib.auth.signals import user_logged_in, user_logged_out @@ -17,27 +17,30 @@ def profile_saved(sender, instance, **kwargs): @receiver(user_logged_in) -def profile_start_up(sender, instance, request, **kwargs): - if instance.session is None: +def profile_start_up(sender, user, request, **kwargs): + try: + user.session + + except Profile.session.RelatedObjectDoesNotExist: # Create session session = Session() - session.user = instance - session.sessionid = request.COOKIE.get('sessionid') + session.user = user + session.sessionid = request.COOKIES.get('sessionid') # TODO metoda wybierania portów port = 6969 session.port = port # Create container docker_manager = DockerManager() - container_id = docker_manager.turn_on_container(instance.volume, port) + container_id = docker_manager.turn_on_container(user.volume, port) session.container_id = container_id session.save() @receiver(user_logged_out) -def profile_logged_out(sender, instance, request, **kwargs): +def profile_logged_out(sender, user, request, **kwargs): # Obtaining container_id - session = Session.objects.get(id=instance.user_id) + session = Session.objects.get(id=user.user_id) container_id = session.container_id # Turn off and delete container