decorator volume creator

This commit is contained in:
makram89 2022-01-27 22:46:31 +01:00
parent 638d9aceb5
commit 768fd10de0
3 changed files with 29 additions and 6 deletions

View File

@ -1,14 +1,16 @@
from django.contrib.auth.models import User
from django.db import models
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import AbstractUser
class Profile(AbstractUser):
volume = models.CharField(max_length=64, null=True, blank=True)
class Session(models.Model):
user = models.ForeignKey(User, primary_key=True, on_delete=models.CASCADE)
user = models.ForeignKey(Profile, primary_key=True, on_delete=models.CASCADE)
port = models.PositiveIntegerField(null=False, unique=True)
sessionid = models.CharField(max_length=32)
container_id = models.CharField(max_length=64, null=True, blank=True)
class Profile(models.Model):
user = models.ForeignKey(User, primary_key=True, on_delete=models.CASCADE)
volume = models.CharField(max_length=64)
container_id = models.CharField(max_length=64)

View File

@ -131,3 +131,6 @@ LOGOUT_REDIRECT_URL = 'home'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
AUTH_USER_MODEL = "MUOR.Profile"

18
MUOR/MUOR/signals.py Normal file
View File

@ -0,0 +1,18 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from DockerManager import DockerManager
from models import Profile
@receiver(post_save, sender=Profile)
def profile_saved(sender, instance, **kwargs):
# Check if volume already exists and if not -> creating new volume
if instance.volume is None:
docker_manager = DockerManager()
volume = docker_manager.create_new_volume(instance.username)
instance.volume = volume
instance.save()