Commit 300b3942 authored by André Anjos's avatar André Anjos

Merge branch 'fix_backup_restore' into 'master'

Fix backup/restore

See merge request !277
parents 9f92f26e df4024ce
Pipeline #28009 passed with stages
in 16 minutes and 56 seconds
......@@ -33,79 +33,109 @@ from django.dispatch import receiver
import random
import string
class AccountSettings(models.Model):
class AccountSettingsManager(models.Manager):
def get_by_natural_key(self, owner):
return self.get(owner=owner)
class AccountSettings(models.Model):
class Meta:
verbose_name_plural = "account settings"
owner = models.OneToOneField(User)
daily_summary = models.BooleanField(default=True)
experiment_mail_notifications_enabled = models.BooleanField(default=True)
database_notifications_enabled = models.BooleanField(default=True)
environment_notifications_enabled = models.BooleanField(default=True)
objects = AccountSettingsManager()
def natural_key(self):
return (self.owner,)
class SupervisionTrack(models.Model):
#_____ Fields __________
# _____ Fields __________
supervisee = models.ForeignKey(User, on_delete=models.CASCADE,
related_name='supervisors')
supervisor = models.ForeignKey(User, on_delete=models.CASCADE,
related_name='supervisees')
is_valid = models.BooleanField(default=False)
start_date = models.DateTimeField(null=True, blank=True)
expiration_date = models.DateTimeField(null=True, blank=True)
supervisee = models.ForeignKey(
User, on_delete=models.CASCADE, related_name="supervisors"
)
supervisor = models.ForeignKey(
User, on_delete=models.CASCADE, related_name="supervisees"
)
is_valid = models.BooleanField(default=False)
start_date = models.DateTimeField(null=True, blank=True)
expiration_date = models.DateTimeField(null=True, blank=True)
last_validation_date = models.DateTimeField(null=True, blank=True)
supervision_key = models.CharField(max_length=40, null=True, blank=True)
supervision_key = models.CharField(max_length=40, null=True, blank=True)
def __unicode__(self):
return u'Supervisor: %s, Supervisee, %s, Validity: %s' % (self.supervisor.username, self.supervisee.username, self.is_valid)
return u"Supervisor: %s, Supervisee, %s, Validity: %s" % (
self.supervisor.username,
self.supervisee.username,
self.is_valid,
)
class ProfileManager(models.Manager):
def get_by_natural_key(self, user):
return self.get(user=user)
class Profile(models.Model):
#_____ Constants __________
#New account creation 'N'/'W'
#Supervisor acceptance/rejection 'A'/'R'
#Yearly revalidation/blockage 'Y'/'B'
NEWUSER = 'N'
WAITINGVALIDATION = 'W'
ACCEPTED = 'A'
REJECTED = 'R'
YEARREVALIDATION = 'Y'
BLOCKED = 'B'
# _____ Constants __________
# New account creation 'N'/'W'
# Supervisor acceptance/rejection 'A'/'R'
# Yearly revalidation/blockage 'Y'/'B'
NEWUSER = "N"
WAITINGVALIDATION = "W"
ACCEPTED = "A"
REJECTED = "R"
YEARREVALIDATION = "Y"
BLOCKED = "B"
PROFILE_STATUS = (
(NEWUSER, 'New User'),
(WAITINGVALIDATION, 'Waiting Validation'),
(ACCEPTED, 'Accepted'),
(REJECTED, 'Rejected'),
(YEARREVALIDATION, 'Yearly revalidation'),
(BLOCKED, 'Blocked no supervisor'),
(NEWUSER, "New User"),
(WAITINGVALIDATION, "Waiting Validation"),
(ACCEPTED, "Accepted"),
(REJECTED, "Rejected"),
(YEARREVALIDATION, "Yearly revalidation"),
(BLOCKED, "Blocked no supervisor"),
)
#_____ Fields __________
# _____ Fields __________
# This field is required.
user = models.OneToOneField(User, on_delete=models.CASCADE)
# Other fields here
status = models.CharField(max_length=1, choices=PROFILE_STATUS, default=BLOCKED)
status = models.CharField(max_length=1, choices=PROFILE_STATUS, default=BLOCKED)
is_supervisor = models.BooleanField(default=False)
supervision = models.ManyToManyField(SupervisionTrack, related_name='profiles', blank=True)
supervision = models.ManyToManyField(
SupervisionTrack, related_name="profiles", blank=True
)
supervision_key = models.CharField(max_length=40, null=True, blank=True)
registration_date = models.DateTimeField(null=True, blank=True)
rejection_date = models.DateTimeField(null=True, blank=True)
objects = ProfileManager()
def __unicode__(self):
return u'User: %s' % self.user.username
return u"User: %s" % self.user.username
def _generate_current_supervision_key(self):
length = 40
return ''.join(random.choice(string.ascii_letters + string.digits) for _
in range(length))
length = 40
return "".join(
random.choice(string.ascii_letters + string.digits) # nosec
for _ in range(length)
)
def natural_key(self):
return (self.user,)
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
......@@ -114,6 +144,7 @@ def create_user_profile(sender, instance, created, **kwargs):
else:
return
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
player, created = Profile.objects.get_or_create(user=instance)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment