src/ldt/ldt/user/models.py
author cavaliet
Wed, 10 Aug 2011 16:45:51 +0200
branchgroup_management
changeset 129 e9f11d142db5
parent 111 4535dafa6007
child 130 1cc949de2d1f
permissions -rw-r--r--
the code works, but is not totally clean. all the parts meant to be removed are commented.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     1
from django.contrib import admin
129
e9f11d142db5 the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents: 111
diff changeset
     2
from django.contrib.auth.models import User, UserManager#, Group
e9f11d142db5 the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents: 111
diff changeset
     3
#from django.db import models
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     4
import datetime
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     5
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     6
129
e9f11d142db5 the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents: 111
diff changeset
     7
#class IriGroup(Group):
e9f11d142db5 the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents: 111
diff changeset
     8
#    description = models.TextField(null=True, blank=True)
e9f11d142db5 the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents: 111
diff changeset
     9
#    
e9f11d142db5 the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents: 111
diff changeset
    10
#    def __unicode__(self):
e9f11d142db5 the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents: 111
diff changeset
    11
#        return self.name
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    12
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    13
            
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    14
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
    15
#    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
    16
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    17
    class Meta:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    18
        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
    19
        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
    20
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    21
    def __unicode__(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    22
        return self.username
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    23
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    24
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    25
class ldtManager(UserManager):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    26
    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
    27
        "Creates and saves a User with the given username, e-mail and password."
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    28
        now = datetime.datetime.now()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    29
        user = ldt(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    30
        if password:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    31
            user.set_password(password)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    32
        else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    33
            user.set_unusable_password()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    34
        user.save()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    35
        return user   
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    36
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    37
User.objects = ldtManager()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    38
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
    39
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    40
admin.site.register(ldt)
129
e9f11d142db5 the code works, but is not totally clean. all the parts meant to be removed are commented.
cavaliet
parents: 111
diff changeset
    41
#admin.site.register(IriGroup)