b0bd4968146afd494ddccbca510c73ec21c2ea23
[cas.git] / src / accounts / models.py
1 from django.conf import settings
2 from django.db import models
3 from cas_provider.signals import cas_collect_custom_attributes
4
5
6 class Service(models.Model):
7     ordering = models.IntegerField()
8     name = models.CharField(max_length=255)
9     url = models.URLField()
10     image = models.ImageField(upload_to='accounts/service/')
11
12     class Meta:
13         ordering = ('ordering', )
14
15
16 class ServiceUser(models.Model):
17     service = models.ForeignKey(Service, on_delete=models.CASCADE)
18     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
19
20
21 class ServiceGroup(models.Model):
22     service = models.ForeignKey(Service, on_delete=models.CASCADE)
23     group = models.ForeignKey('auth.Group', on_delete=models.CASCADE)
24
25
26 def user_attributes(sender, user, **kwargs):
27     return {
28         'firstname': user.first_name,
29         'lastname': user.last_name,
30         'cn': ' '.join((user.first_name, user.last_name)),
31         'email': user.email,
32     }
33 cas_collect_custom_attributes.connect(user_attributes)