1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| class Account(object): __slots__ = ('user_id', 'user', 'user_profile', 'account_money')
def __init__(self, user_id): self.user_id = user_id self.user = Query(_User).include('avatar.url', 'password').get(user_id) self.user_profile = UserProflieModel.get_or_create_user_profile(self.user) self.account_money = None
def __setattr__(self, key, value): if key in self.__slots__: object.__setattr__(self, key, value) elif key in ('height', 'weight', 'sexuality', 'emotion', 'haunt', 'been', 'company', 'position', 'graduated', 'industry', 'salary', 'hometown') and value is not None: if key == 'hometown': value = Query(Region).equal_to('adcode', value).first() self.user_profile.set(key, value) elif key in ('avatar', 'nickname', 'birth', 'mind') and value is not None: if key == 'avatar': value = Query(_File).get(value) elif key == 'birth': value = datetime.fromtimestamp(value/1000) elif key == 'mind': if len(value) > 300: raise LeanCloudError(20504, errmsg.ERRMSG[20504]) self.user.set(key, value)
def save(self): self.user.save() self.user_profile.save() # self.account_money.save() class UserModel(object):
def __init__(self, user_id=None): self.user_id = user_id self.query = Query(_User) ... def update_profile(self, avatar=None, nickname=None, birth=None, mind=None, height=None, weight=None, sexuality=None, emotion=None, haunt=None, been=None, company=None, position=None, graduated=None, industry=None, salary=None, hometown=None): account = Account(self.user_id) account.avatar = avatar account.nickname = nickname account.birth = birth account.mind = mind account.height = height account.weight = weight account.sexuality = sexuality account.emotion = emotion account.haunt = haunt account.been = been account.company = company account.position = position account.graduated = graduated account.industry = industry account.salary = salary account.hometown = hometown
try: account.save() except LeanCloudError as e: logging.error(e) return False return True
|