diff --git a/beat/web/accounts/models.py b/beat/web/accounts/models.py index 79b0629bda6e06f62d3e3f012418680ea968f4e7..a61ed582aff0f37e2e84ea41e9e3e6a5362d59ce 100644 --- a/beat/web/accounts/models.py +++ b/beat/web/accounts/models.py @@ -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() diff --git a/beat/web/navigation/admin.py b/beat/web/navigation/admin.py index 924827c59d2a52f2ec274662e9a9ca94eb5e3e9b..23cf9bafa8b1ad7b78acb815f2acbb6048521bcf 100644 --- a/beat/web/navigation/admin.py +++ b/beat/web/navigation/admin.py @@ -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) diff --git a/beat/web/settings/settings.py b/beat/web/settings/settings.py index 17a7b1d25b1d807ac7ea186406fd9b2e03126c96..a5c324d86df811f78a383f44ec229dae3b57c92a 100755 --- a/beat/web/settings/settings.py +++ b/beat/web/settings/settings.py @@ -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/