1#!/usr/bin/python2.5
2
3# Copyright (C) 2010 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16
17"""Represents user's contact information"""
18
19from google.appengine.ext import db
20
21
22class Contact(db.Model):
23  """Data model class to hold user objects."""
24
25  handle = db.StringProperty(required=True)
26  firstname = db.StringProperty()
27  lastname = db.StringProperty()
28  phone_home = db.PhoneNumberProperty()
29  phone_office = db.PhoneNumberProperty()
30  phone_mobile = db.PhoneNumberProperty()
31  email = db.EmailProperty()
32  status = db.TextProperty()
33  avatar = db.BlobProperty()
34  deleted = db.BooleanProperty()
35  updated = db.DateTimeProperty(auto_now_add=True)
36
37  @classmethod
38  def get_contact_info(cls, username):
39    if username not in (None, ''):
40      query = cls.gql('WHERE handle = :1', username)
41      return query.get()
42    return None
43
44  @classmethod
45  def get_contact_last_updated(cls, username):
46    if username not in (None, ''):
47      query = cls.gql('WHERE handle = :1', username)
48      return query.get().updated
49    return None
50
51  @classmethod
52  def get_contact_id(cls, username):
53    if username not in (None, ''):
54      query = cls.gql('WHERE handle = :1', username)
55      return query.get().key().id()
56    return None
57
58  @classmethod
59  def get_contact_status(cls, username):
60    if username not in (None, ''):
61      query = cls.gql('WHERE handle = :1', username)
62      return query.get().status
63    return None
64
65