decorator volume creator
This commit is contained in:
parent
638d9aceb5
commit
768fd10de0
@ -1,14 +1,16 @@
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db import models
|
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):
|
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)
|
port = models.PositiveIntegerField(null=False, unique=True)
|
||||||
sessionid = models.CharField(max_length=32)
|
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)
|
|
||||||
|
@ -131,3 +131,6 @@ LOGOUT_REDIRECT_URL = 'home'
|
|||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||||
|
|
||||||
|
AUTH_USER_MODEL = "MUOR.Profile"
|
||||||
|
|
||||||
|
18
MUOR/MUOR/signals.py
Normal file
18
MUOR/MUOR/signals.py
Normal 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()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user