4a3cb4e45d483d62ca2fdc27e31cb4512ca229c7
[matthijs/upstream/django-ldapdb.git] / examples / models.py
1 # -*- coding: utf-8 -*-
2
3 # django-ldapdb
4 # Copyright (C) 2009-2010 BollorĂ© telecom
5 # See AUTHORS file for a full list of contributors.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 from ldapdb.models.fields import CharField, ImageField, IntegerField, ListField
22 import ldapdb.models
23
24 class LdapUser(ldapdb.models.Model):
25     """
26     Class for representing an LDAP user entry.
27     """
28     # LDAP meta-data
29     base_dn = "ou=people,dc=nodomain"
30     object_classes = ['posixAccount', 'shadowAccount', 'inetOrgPerson']
31
32     # inetOrgPerson
33     first_name = CharField(db_column='givenName')
34     last_name = CharField(db_column='sn')
35     full_name = CharField(db_column='cn')
36     email = CharField(db_column='mail')
37     phone = CharField(db_column='telephoneNumber', blank=True)
38     mobile_phone = CharField(db_column='mobile', blank=True)
39     photo = ImageField(db_column='jpegPhoto')
40
41     # posixAccount
42     uid = IntegerField(db_column='uidNumber', unique=True)
43     group = IntegerField(db_column='gidNumber')
44     gecos =  CharField(db_column='gecos')
45     home_directory = CharField(db_column='homeDirectory')
46     login_shell = CharField(db_column='loginShell', default='/bin/bash')
47     username = CharField(db_column='uid', primary_key=True)
48     password = CharField(db_column='userPassword')
49
50     def __str__(self):
51         return self.username
52
53     def __unicode__(self):
54         return self.full_name
55
56 class LdapGroup(ldapdb.models.Model):
57     """
58     Class for representing an LDAP group entry.
59     """
60     # LDAP meta-data
61     base_dn = "ou=groups,dc=nodomain"
62     object_classes = ['posixGroup']
63
64     # posixGroup attributes
65     gid = IntegerField(db_column='gidNumber', unique=True)
66     name = CharField(db_column='cn', max_length=200, primary_key=True)
67     usernames = ListField(db_column='memberUid')
68
69     def __str__(self):
70         return self.name
71
72     def __unicode__(self):
73         return self.name
74