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, friends and credentials.""" 18 19 from google.appengine.ext import db 20 21 22 class User(db.Model): 23 """Data model class to hold user objects.""" 24 25 handle = db.StringProperty(required=True) 26 firstname = db.TextProperty() 27 lastname = db.TextProperty() 28 status = db.TextProperty() 29 phone_home = db.PhoneNumberProperty() 30 phone_office = db.PhoneNumberProperty() 31 phone_mobile = db.PhoneNumberProperty() 32 email = db.EmailProperty() 33 deleted = db.BooleanProperty() 34 updated = db.DateTimeProperty(auto_now_add=True) 35 36 @classmethod 37 def get_user_info(cls, username): 38 if username not in (None, ''): 39 query = cls.gql('WHERE handle = :1', username) 40 return query.get() 41 return None 42 43 @classmethod 44 def get_user_last_updated(cls, username): 45 if username not in (None, ''): 46 query = cls.gql('WHERE handle = :1', username) 47 return query.get().updated 48 return None 49 50 @classmethod 51 def get_user_id(cls, username): 52 if username not in (None, ''): 53 query = cls.gql('WHERE handle = :1', username) 54 return query.get().key().id() 55 return None 56 57 @classmethod 58 def get_user_status(cls, username): 59 if username not in (None, ''): 60 query = cls.gql('WHERE handle = :1', username) 61 return query.get().status 62 return None 63 64 65 class UserCredentials(db.Model): 66 """Data model class to hold credentials for a Voiper user.""" 67 68 username = db.StringProperty(required=True) 69 password = db.StringProperty() 70 71 @classmethod 72 def get(cls, username): 73 if username not in (None, ''): 74 query = cls.gql('WHERE username = :1', username) 75 return query.get().password 76 return None 77 78 79 class UserFriends(db.Model): 80 """Data model class to hold user's friendlist info.""" 81 82 username = db.StringProperty() 83 friend_handle = db.StringProperty(required=True) 84 updated = db.DateTimeProperty(auto_now_add=True) 85 deleted = db.BooleanProperty() 86 87 @classmethod 88 def get_friends(cls, username): 89 if username not in (None, ''): 90 query = cls.gql('WHERE username = :1', username) 91 friends = query.fetch(50) 92 return friends 93 return None