def update_contact(self, kwargs): """ 更新联系方式(姓名、电话号码、QQ号、微信号) :param kwargs: :return: """ try: realName = dict_get(kwargs, 'realName') phoneNumber = dict_get(kwargs, 'phoneNumber') qqNumber = dict_get(kwargs, 'qqNumber') weixinNumber = dict_get(kwargs, 'weixinNumber') if phoneNumber is not None: self.phoneNumber = phoneNumber if qqNumber is not None: self.qqNumber = qqNumber if weixinNumber is not None: self.weixinNumber = weixinNumber if not phoneNumber and not qqNumber and not weixinNumber: # 三种联系方式不能都为None return False self.realName = self.nickName if realName is None else realName self.save() return True except Exception as e: print('Exception ', e) return False
def edit_item(self, kwargs): """ 编辑物品信息 :param kwargs: 物品类别 物品姓名 物品描述 物品图片地址 物品价格 :return: """ try: type = dict_get(kwargs, 'itemType') itemName = dict_get(kwargs, 'itemName') des = dict_get(kwargs, 'des') srcs = dict_get(kwargs, 'srcs') price = dict_get(kwargs, 'price') if type is not None: self.type = type if itemName is not None: self.itemName = itemName if des is not None: self.des = des if srcs is not None: self.srcs = srcs if price is not None: self.price = price self.save() return True except Exception as e: print(e) return False
def update_avatar(self, kwargs): """ 更新头像和姓名 :param kwargs: :return: """ try: avatarUrl = dict_get(kwargs, 'avatarUrl') nickName = dict_get(kwargs, 'nickName') if avatarUrl is not None: self.avatarUrl = avatarUrl if nickName is not None: self.nickName = nickName if avatarUrl is None and nickName is None: # 两者不能都为空 return False self.save() return True except Exception as e: print('Exception ', e) return False
def create_item(kwargs, user): """ 创建物品 :param kwargs: 物品类别 物品姓名 物品描述 物品图片地址 物品原价 物品价格 :param user: 用户对象 :return: """ try: print(kwargs) item = Item() item.type = dict_get(kwargs, 'type', ItemTypeEnum.OTHER_PRODUCTS.value) item.itemName = dict_get(kwargs, 'itemName', '') item.des = item.itemName + "\n" + dict_get(kwargs, 'des', '') # 描述中最前面是物品名称 item.time = datetime.datetime.now() item.srcs = dict_get(kwargs, 'srcs', '') item.originPrice = dict_get(kwargs, 'originPrice', -1) item.price = dict_get(kwargs, 'price', -1) item.user_id = user.id user.update_contact(kwargs) item.save() return True except Exception as e: print(e) return False