~ubuntuone-pqm-team/canonical-identity-provider/trunk

« back to all changes in this revision

Viewing changes to identityprovider/models/person.py

  • Committer: Danny Tamez
  • Date: 2010-04-21 15:29:24 UTC
  • Revision ID: danny.tamez@canonical.com-20100421152924-lq1m92tstk2iz75a
Canonical SSO Provider (Open Source) - Initial Commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
from django.db import models
 
5
 
 
6
from identityprovider.models import (LPAccount, Account, Country, Language,
 
7
                                      LibraryFileAlias)
 
8
from identityprovider.models.const import AccountCreationRationale
 
9
 
 
10
__all__ = (
 
11
    'Person',
 
12
)
 
13
 
 
14
 
 
15
class Person(models.Model):
 
16
    displayname = models.TextField()
 
17
    teamowner = models.ForeignKey('self', db_column='teamowner',
 
18
                                  related_name='owned_teams',
 
19
                                  null=True, blank=True)
 
20
    teamdescription = models.TextField(null=True, blank=True)
 
21
    name = models.TextField(unique=True)
 
22
    language = models.ForeignKey(Language, db_column='language',
 
23
        null=True, blank=True)
 
24
    fti = models.TextField()  # This field type is a guess.
 
25
    defaultmembershipperiod = models.IntegerField(null=True, blank=True)
 
26
    defaultrenewalperiod = models.IntegerField(null=True, blank=True)
 
27
    subscriptionpolicy = models.IntegerField(default=1)
 
28
    merged = models.ForeignKey('self', db_column='merged',
 
29
                               related_name='merged_personas',
 
30
                               null=True, blank=True)
 
31
    datecreated = models.DateTimeField(auto_now_add=True)
 
32
    addressline1 = models.TextField(null=True, blank=True)
 
33
    addressline2 = models.TextField(null=True, blank=True)
 
34
    organization = models.TextField(null=True, blank=True)
 
35
    city = models.TextField(null=True, blank=True)
 
36
    province = models.TextField(null=True, blank=True)
 
37
    country = models.ForeignKey(Country, db_column='country',
 
38
        null=True, blank=True)
 
39
    postcode = models.TextField(null=True, blank=True)
 
40
    phone = models.TextField(null=True, blank=True)
 
41
    homepage_content = models.TextField(null=True, blank=True)
 
42
    icon = models.ForeignKey(LibraryFileAlias, db_column='icon',
 
43
                             related_name='person_icons',
 
44
                             null=True, blank=True)
 
45
    mugshot = models.ForeignKey(LibraryFileAlias, db_column='mugshot',
 
46
                                related_name='person_mugshots',
 
47
                                null=True, blank=True)
 
48
    hide_email_addresses = models.BooleanField(default=False)
 
49
    creation_rationale = models.IntegerField(null=True, blank=True,
 
50
        choices=AccountCreationRationale._get_choices())
 
51
    creation_comment = models.TextField(null=True, blank=True)
 
52
    registrant = models.ForeignKey('self', db_column='registrant',
 
53
                                   related_name='registered_teams',
 
54
                                   null=True, blank=True)
 
55
    logo = models.ForeignKey(LibraryFileAlias, db_column='logo',
 
56
                             related_name='person_logos',
 
57
                             null=True, blank=True)
 
58
    renewal_policy = models.IntegerField(default=10)
 
59
    personal_standing = models.IntegerField(default=0)
 
60
    personal_standing_reason = models.TextField(null=True, blank=True)
 
61
    mail_resumption_date = models.DateField(null=True, blank=True)
 
62
    mailing_list_auto_subscribe_policy = models.IntegerField(default=1)
 
63
    mailing_list_receive_duplicates = models.BooleanField(default=True)
 
64
    visibility = models.IntegerField(default=1)
 
65
    verbose_bugnotifications = models.BooleanField(default=False)
 
66
    lp_account = models.ForeignKey(LPAccount, db_column='account',
 
67
                                   null=True, blank=True)
 
68
 
 
69
    class Meta:
 
70
        app_label = 'identityprovider'
 
71
        db_table = u'lp_person'
 
72
 
 
73
    def __unicode__(self):
 
74
        return self.displayname
 
75
 
 
76
    def in_team(self, team):
 
77
        from identityprovider.models import TeamParticipation
 
78
        # Just to be fully compatible with
 
79
        # lp:lib/registry/model/person.py:Person.inTeam()
 
80
        if isinstance(team, (str, unicode)):
 
81
            try:
 
82
                team = Person.objects.get(name=team)
 
83
            except Person.DoesNotExist:
 
84
                return False
 
85
        try:
 
86
            tp = TeamParticipation.objects.get(team=team, person=self)
 
87
            return True
 
88
        except TeamParticipation.DoesNotExist:
 
89
            if self.id == team.teamowner.id:
 
90
                return True
 
91
            elif team.is_team() and not team.teamowner.in_team(team):
 
92
                return self.in_team(team.teamowner)
 
93
        return False
 
94
 
 
95
    @property
 
96
    def account(self):
 
97
        if self.lp_account is not None:
 
98
            accounts = Account.objects.filter(
 
99
                openid_identifier=self.lp_account.openid_identifier)
 
100
            if len(accounts) > 0:
 
101
                return accounts[0]
 
102
 
 
103
    def is_team(self):
 
104
        return self.teamowner is not None
 
105
 
 
106
    @property
 
107
    def time_zone(self):
 
108
        try:
 
109
            return self.personlocation.time_zone
 
110
        except:
 
111
            return None
 
112
 
 
113
 
 
114
class PersonLocation(models.Model):
 
115
    date_created = models.DateTimeField()
 
116
    person = models.OneToOneField(Person, db_column='person')
 
117
    latitude = models.FloatField(null=True, blank=True)
 
118
    longitude = models.FloatField(null=True, blank=True)
 
119
    time_zone = models.TextField(null=True, blank=True)
 
120
    last_modified_by = models.ForeignKey(Person, db_column='last_modified_by',
 
121
        related_name='last_modified_locations')
 
122
    date_last_modified = models.DateTimeField()
 
123
    visible = models.BooleanField(default=True)
 
124
    locked = models.BooleanField(default=False)
 
125
 
 
126
    class Meta:
 
127
        app_label = 'identityprovider'
 
128
        db_table = u'lp_personlocation'