| author | cavaliet |
| Thu, 24 May 2012 16:04:07 +0200 | |
| branch | maintenance_0.21 |
| changeset 624 | 2252fb64f74e |
| parent 276 | ee792e43b36a |
| child 314 | 1a8620e5ebb0 |
| permissions | -rw-r--r-- |
|
188
74bad93d3cb7
Merge with 50dd5c3e8ab8365982cffc4f411f9f5ba7686176
ymh <ymh.work@gmail.com>
diff
changeset
|
1 |
from django.conf import settings |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
2 |
from django.contrib import admin |
| 228 | 3 |
from django.contrib.auth.models import User, UserManager, Group |
| 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 |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
6 |
import datetime |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
7 |
|
|
276
ee792e43b36a
Replace is_regular field in userprofile by django permission
verrierj
parents:
259
diff
changeset
|
8 |
|
| 155 | 9 |
class Ldt(User): |
|
129
e9f11d142db5
the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents:
111
diff
changeset
|
10 |
# irigroups = models.ManyToManyField(IriGroup, blank=True) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
11 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
12 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
13 |
verbose_name = 'iri user' |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
14 |
verbose_name_plural = 'iri users' |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
15 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
16 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
17 |
return self.username |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
18 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
19 |
|
| 155 | 20 |
class LdtManager(UserManager): |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
21 |
def create_user(self, username, email, password=None): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
22 |
"Creates and saves a User with the given username, e-mail and password." |
| 187 | 23 |
now = datetime.datetime.utcnow() |
| 169 | 24 |
new_user = Ldt(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
25 |
if password: |
| 169 | 26 |
new_user.set_password(password) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
27 |
else: |
| 169 | 28 |
new_user.set_unusable_password() |
29 |
new_user.save() |
|
| 247 | 30 |
new_user.groups.add(Group.objects.get(name=settings.PUBLIC_GROUP_NAME)) |
31 |
return new_user |
|
| 169 | 32 |
|
33 |
||
34 |
class UserProfile (models.Model): |
|
35 |
user = models.OneToOneField(User) |
|
| 175 | 36 |
language = models.CharField(max_length=2, default=settings.LANGUAGE_CODE[:2]) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
37 |
|
|
174
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
172
diff
changeset
|
38 |
@staticmethod |
|
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
172
diff
changeset
|
39 |
def create_user_profile(sender, instance, created, **kwargs): |
|
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
172
diff
changeset
|
40 |
if created: |
|
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
172
diff
changeset
|
41 |
UserProfile.objects.create(user=instance) |
|
276
ee792e43b36a
Replace is_regular field in userprofile by django permission
verrierj
parents:
259
diff
changeset
|
42 |
|
|
174
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
172
diff
changeset
|
43 |
|
|
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
172
diff
changeset
|
44 |
post_save.connect(UserProfile.create_user_profile, sender=User) |
| 169 | 45 |
|
| 155 | 46 |
User.objects = LdtManager() |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
47 |
User.objects.contribute_to_class(User, "objects") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
48 |
|
| 155 | 49 |
admin.site.register(Ldt) |