def get_userprop(p_key, user_id): if strutil.is_empty(p_key): raise CoreError("prop key %s of user %d can't be empty." % (p_key, user_id)) query = UserProp.all() query.filter("p_key =", p_key) query.filter("user_id =", user_id) if query.count() == 0: userprop = None elif query.count() > 1: raise CoreError("prop key %s of user %d has multiple values." % (p_key, user_id)) else: userprop = query.get() return userprop
def update_userprop(p_key, p_value, user_id, modifier_id): if strutil.is_empty(p_key): raise CoreError("the prop key can't be empty.") query = UserProp.all() query.filter("p_key =", p_key) query.filter("user_id =", user_id) if get_userprop(p_key, user_id) == None: raise CoreError("the prop key %s of user %d doesn't exist." % (p_key, user_id)) else: userprop = query.get() userprop.p_key = p_key p_value = strutil.to_str(p_value) userprop.p_value = p_value userprop.update(modifier_id)
def create_userprop(p_key, p_value, user_id, modifier_id): if strutil.is_empty(p_key): raise CoreError("user prop key can't be empty.") query = UserProp.all() query.filter("p_key =", p_key) query.filter("user_id =", user_id) if query.count() > 0: raise CoreError("the prop key %s of the user %d has existed." % (p_key, user_id)) userprop = UserProp() userprop.p_key = p_key p_value = strutil.to_str(p_value) userprop.p_value = p_value userprop.user_id = user_id userprop.create(modifier_id) return userprop
def fetch_userprops(user_id): query = UserProp.all() query.filter("user_id =", int(user_id)) return query.fetch()