def add_company_profile(self, user_id, username): """添加企业用户信息到 Company 数据库表 Args: user_id (int) : 注册用户ID """ company = Company() logo = self.logo.data manager_img = self.manager_img.data logo_filename = self.change_img(logo, user_id) manager_img_filename = self.change_img(manager_img, user_id) company.user_id = user_id company.name = username company.logo = logo_filename company.web_url = self.web_url.data company.found_date = self.found_date.data company.city = self.city.data company.address = self.address.data company.scale = self.scale.data company.industry = self.industry.data company.email = self.email.data company.phone = self.phone.data company.fax = self.fax.data company.manager_name = self.manager_name.data company.manager_job = self.manager_job.data company.manager_photo = manager_img_filename company.slogan = self.slogan.data company.products_display = self.products_display.data company.description = self.description.data db.session.add(company) db.session.commit()
def updated_profile(self, user): user.username = self.username.data user.email = self.email.data if self.password.data: user.password = self.password.data if user.company_detail: company = user.company_detail else: company = Company() company.user_id = user.id if self.slug.data: company.slug = self.slug.data if self.location.data: company.location = self.location.data if self.site.data: company.site = self.site.data if self.logo.data: company.logo = self.logo.data if self.description.data: company.description = self.description.data if self.about.data: company.about = self.about.data db.session.add(user) db.session.add(company) db.session.commit()
def updated_profile(self, user): user.name = self.name.data user.email = self.email.data if self.password.data: user.password = self.password.data if user.company_info: company_info = user.company_info else: company_info = Company() company_info.user_id = user.id self.populate_obj(company_info) if self.company_logo.data: # 获取文件后缀 suffix = os.path.splitext(self.company_logo.data.filename)[1] # 生成随机的文件名 filename = random_string() + suffix clogo.save(self.company_logo.data, name=filename) company_info.logo = filename db.session.add(user) db.session.add(company_info) db.session.commit()