Commit ba42bdaf authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts/navigation/settings] added Profile model to User and its related...

[accounts/navigation/settings] added Profile model to User and its related admin views and updated settings to link with user
parent 1e8c047f
Pipeline #8920 failed with stage
in 54 minutes and 35 seconds
......@@ -27,6 +27,8 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
class AccountSettings(models.Model):
......@@ -39,3 +41,43 @@ class AccountSettings(models.Model):
experiment_mail_notifications_enabled = models.BooleanField(default=True)
database_notifications_enabled = models.BooleanField(default=True)
environment_notifications_enabled = models.BooleanField(default=True)
class Profile(models.Model):
#_____ Constants __________
ACCEPTED = 'A'
REJECTED = 'R'
WAITINGVALIDATION = 'W'
BLOCKED = 'B'
PROFILE_STATUS = (
(ACCEPTED, 'Accepted'),
(REJECTED, 'Rejected'),
(WAITINGVALIDATION, 'Waiting Validation'),
(BLOCKED, 'Blocked'),
)
#_____ 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)
is_godfather = models.BooleanField(default=False)
supervisees = models.ManyToManyField(User, related_name='users', blank=True)
def __unicode__(self):
return u'User: %s' % self.user.username
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
else:
return
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
player, created = Profile.objects.get_or_create(user=instance)
instance.profile.save()
......@@ -31,6 +31,7 @@ from django.contrib.auth.models import User
from .models import Agreement
from ..accounts.models import AccountSettings
from ..accounts.models import Profile
#----------------------------------------------------------
......@@ -50,6 +51,13 @@ class AccountSettingsInline(admin.StackedInline):
#----------------------------------------------------------
class ProfileInline(admin.StackedInline):
model = Profile
#----------------------------------------------------------
class UserAdmin(UserAdmin):
def agreement_number(self, obj):
......@@ -62,6 +70,17 @@ class UserAdmin(UserAdmin):
int(obj.accountsettings.database_notifications_enabled) + \
int(obj.accountsettings.environment_notifications_enabled)
def godfather(self, obj):
return obj.profile.is_godfather
def status(self, obj):
return obj.profile.status
def supervisees(self, obj):
return obj.profile.supervisees
list_display = (
'username',
'is_staff',
......@@ -69,6 +88,9 @@ class UserAdmin(UserAdmin):
'notifications',
'agreement_number',
'last_login',
'godfather',
'status',
'supervisees',
)
ordering = (
......@@ -80,6 +102,7 @@ class UserAdmin(UserAdmin):
inlines = (
AgreementInline,
AccountSettingsInline,
ProfileInline,
)
admin.site.unregister(User)
......
......@@ -429,6 +429,8 @@ AUTHENTICATION_BACKENDS = (
ANONYMOUS_USER_ID = -1
AUTH_PROFILE_MODULE = 'accounts.Profile'
##############################################################################
#
# REST FRAMEWORK PERMISSION CLASSES: http://www.django-rest-framework.org/api-guide/permissions/
......
Supports Markdown
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