| author | ymh <ymh.work@gmail.com> |
| Wed, 29 Apr 2015 00:54:01 +0200 | |
| changeset 1358 | 8c290b65505e |
| parent 1219 | dd46f7a3b064 |
| child 1369 | e7cd1595f512 |
| permissions | -rw-r--r-- |
|
188
74bad93d3cb7
Merge with 50dd5c3e8ab8365982cffc4f411f9f5ba7686176
ymh <ymh.work@gmail.com>
diff
changeset
|
1 |
from django.conf import settings |
| 1193 | 2 |
from django.contrib.auth.models import (AbstractUser, UserManager, Group, |
| 1191 | 3 |
BaseUserManager) |
| 169 | 4 |
from django.db import models |
|
174
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
172
diff
changeset
|
5 |
from django.db.models.signals import post_save |
| 1191 | 6 |
from django.utils import timezone |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
276
diff
changeset
|
7 |
from sorl.thumbnail import ImageField |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
8 |
|
| 1191 | 9 |
class LdtUserManager(BaseUserManager): |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
10 |
|
| 1191 | 11 |
def create_user(self, username, email=None, password=None, **extra_fields): |
12 |
""" |
|
13 |
Creates and saves a User with the given username, email and password. |
|
14 |
""" |
|
15 |
now = timezone.now() |
|
16 |
if not username: |
|
17 |
raise ValueError('The given username must be set') |
|
18 |
email = UserManager.normalize_email(email) |
|
19 |
user = self.model(username=username, email=email, |
|
20 |
is_staff=False, is_active=True, is_superuser=False, |
|
21 |
last_login=now, date_joined=now, **extra_fields) |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
22 |
|
| 1191 | 23 |
user.set_password(password) |
24 |
user.save(using=self._db) |
|
25 |
everyone, _ = Group.objects.get_or_create(name=settings.PUBLIC_GROUP_NAME) |
|
26 |
user.groups.add(everyone) |
|
27 |
return user |
|
28 |
||
29 |
def create_superuser(self, username, email, password, **extra_fields): |
|
30 |
u = self.create_user(username, email, password, **extra_fields) |
|
31 |
u.is_staff = True |
|
32 |
u.is_active = True |
|
33 |
u.is_superuser = True |
|
34 |
u.save(using=self._db) |
|
35 |
return u |
|
|
276
ee792e43b36a
Replace is_regular field in userprofile by django permission
verrierj
parents:
259
diff
changeset
|
36 |
|
| 325 | 37 |
class GroupProfile(models.Model): |
38 |
group = models.OneToOneField(Group, primary_key=False, related_name='profile') |
|
39 |
description = models.TextField() |
|
|
342
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
330
diff
changeset
|
40 |
image = ImageField(upload_to=settings.MEDIA_ROOT+"thumbnails/groups/", default=settings.DEFAULT_GROUP_ICON, max_length=200) |
| 325 | 41 |
|
42 |
@staticmethod |
|
43 |
def create_group_profile(sender, instance, created, **kwargs): |
|
44 |
if created: |
|
45 |
profile = GroupProfile() |
|
46 |
profile.group_id = instance.id |
|
47 |
profile.save() |
|
| 1193 | 48 |
admins = LdtUser.objects.filter(is_superuser=True) |
|
452
8e9494006e7b
segment abstracts + content images can be retrieved directly from search results page
verrierj
parents:
406
diff
changeset
|
49 |
if admins: |
| 1193 | 50 |
admin_user = admins[0] |
51 |
admin_user.groups.add(instance) |
|
52 |
admin_user.save() |
|
| 1191 | 53 |
|
54 |
class LdtUser(AbstractUser): |
|
55 |
language = models.CharField(max_length=2, default=settings.LANGUAGE_CODE[:2]) |
|
|
1219
dd46f7a3b064
Correct form management for user admin. remove unused form class.
ymh <ymh.work@gmail.com>
parents:
1195
diff
changeset
|
56 |
image = ImageField(upload_to="thumbnails/users/", default=settings.DEFAULT_USER_ICON, max_length=200) |
| 1191 | 57 |
|
58 |
objects = LdtUserManager() |
|
59 |
||
|
342
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
330
diff
changeset
|
60 |
|
|
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
330
diff
changeset
|
61 |
def get_profile(self): |
|
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
330
diff
changeset
|
62 |
return self.profile |
|
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
330
diff
changeset
|
63 |
|
| 1191 | 64 |
Group.add_to_class("get_profile", get_profile) # @UndefinedVariable |
| 325 | 65 |
post_save.connect(GroupProfile.create_group_profile, sender=Group) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
66 |