bfe144ed6e26a6fb7786638b0c2e0db86a9dd1c3
[matthijs/upstream/django-ldapdb.git] / examples / models.py
1 # -*- coding: utf-8 -*-
2
3 # django-ldapdb
4 # Copyright (c) 2009-2010, BollorĂ© telecom
5 # All rights reserved.
6
7 # See AUTHORS file for a full list of contributors.
8
9 # Redistribution and use in source and binary forms, with or without modification,
10 # are permitted provided that the following conditions are met:
11
12 #     1. Redistributions of source code must retain the above copyright notice, 
13 #        this list of conditions and the following disclaimer.
14 #     
15 #     2. Redistributions in binary form must reproduce the above copyright 
16 #        notice, this list of conditions and the following disclaimer in the
17 #        documentation and/or other materials provided with the distribution.
18
19 #     3. Neither the name of BollorĂ© telecom nor the names of its contributors
20 #        may be used to endorse or promote products derived from this software
21 #        without specific prior written permission.
22
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
27 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34
35 from ldapdb.models.fields import CharField, ImageField, IntegerField, ListField
36 import ldapdb.models
37
38 class LdapUser(ldapdb.models.Model):
39     """
40     Class for representing an LDAP user entry.
41     """
42     # LDAP meta-data
43     base_dn = "ou=people,dc=nodomain"
44     object_classes = ['posixAccount', 'shadowAccount', 'inetOrgPerson']
45
46     # inetOrgPerson
47     first_name = CharField(db_column='givenName')
48     last_name = CharField(db_column='sn')
49     full_name = CharField(db_column='cn')
50     email = CharField(db_column='mail')
51     phone = CharField(db_column='telephoneNumber', blank=True)
52     mobile_phone = CharField(db_column='mobile', blank=True)
53     photo = ImageField(db_column='jpegPhoto')
54
55     # posixAccount
56     uid = IntegerField(db_column='uidNumber', unique=True)
57     group = IntegerField(db_column='gidNumber')
58     gecos =  CharField(db_column='gecos')
59     home_directory = CharField(db_column='homeDirectory')
60     login_shell = CharField(db_column='loginShell', default='/bin/bash')
61     username = CharField(db_column='uid', primary_key=True)
62     password = CharField(db_column='userPassword')
63
64     def __str__(self):
65         return self.username
66
67     def __unicode__(self):
68         return self.full_name
69
70 class LdapGroup(ldapdb.models.Model):
71     """
72     Class for representing an LDAP group entry.
73     """
74     # LDAP meta-data
75     base_dn = "ou=groups,dc=nodomain"
76     object_classes = ['posixGroup']
77
78     # posixGroup attributes
79     gid = IntegerField(db_column='gidNumber', unique=True)
80     name = CharField(db_column='cn', max_length=200, primary_key=True)
81     usernames = ListField(db_column='memberUid')
82
83     def __str__(self):
84         return self.name
85
86     def __unicode__(self):
87         return self.name
88