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 create_table_company(self, user): print(user) company = Company() company.user_id = user.id company.name = user.username db.session.add(company) db.session.commit()
def create_company(self): company = Company() company.name = self.company.data db.session.add(company) db.session.commit() self.create_user(company.id) return company
def update_user_info(self): """ 更新企业用户信息 :return: User 模型实例 """ user = self.user user.email = self.email.data user.role = User.ROLE_COMPANY if self.is_new_user: user.password = self.password.data user.username = self.username.data else: if self.password.data: user.password = self.password.data db.session.add(user) db.session.commit() if self.is_new_user: company = Company(user=user) else: company = user.company_info # logo = self.logo.data # manager_img = self.manager_img.data # if logo: # company.logo = self.change_img(logo, user.id) # if manager_img: # company.manager_photo = self.change_img(manager_img, user.id) company.name = self.name.data 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.resume_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.slogan = self.slogan.data company.products_display = self.products_display.data company.description = self.description.data db.session.add(company) db.session.commit() return user
def updated_profile(self, company: Company): company.name = self.name.data company.email = self.email.data company.phone = self.phone.data if self.password.data: company.password = self.password.data if company.detail: detail = company.detail else: detail = CompanyDetail() detail.user_id = company.id self.populate_obj(detail) db.session.add(company) db.session.add(detail) db.session.commit()
def create_user(self, role): print('start create') user = User() user.email = self.email.data user.password = self.password.data user.role = role db.session.add(user) db.session.commit() user_add = User.query.filter_by(email=self.email.data).first() if role == 20: company = Company() company.name = self.name.data company.user_id = user_add.id db.session.add(company) elif role == 10: jobseeker = Jobseeker() jobseeker.name = self.name.data jobseeker.user_id = user_add.id db.session.add(jobseeker) db.session.commit() print('create user ok')
def edit_user(user_id): user = User.query.get_or_404(user_id) if user.is_company: # 由于企业注册的时候只写了user表,没有写company表,所以需要新写入一次 if not user.company_info: company = Company() company.user_id = user.id company.name = user.name db.session.add(company) db.session.commit() form = CompanyEditForm(obj=user) else: form = UserEditForm(obj=user) if form.validate_on_submit(): form.update(user) flash('更新成功', 'success') return redirect(url_for('admin.users')) if user.is_company: form.site.data = user.company_info.website form.description.data = user.company_info.short_description return render_template('admin/edit_user.html', form=form, user=user)