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 fake_company(self): for company in self.lagou.company: c = User( name=company['companyShortName'], email=fake.email(), role=User.ROLE_COMPANY ) c.password = '******' db.session.add(c) try: db.session.commit() except: db.session.rollback() continue d = Company( logo='https://static.lagou.com/thumbnail_160x160/' + company['companyLogo'], site='https://shiyanlou.com', location=company['city'], field=company['industryField'], finance_stage=company['financeStage'] ) d.user_id = c.id db.session.add(d) 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 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 fake_company(self): for company in self.lagou.company: c = User( name=company['companyShortName'], email=fake.email(), role=User.ROLE_COMPANY ) c.password = '******' db.session.add(c) try: db.session.commit() except: db.session.rollback() continue d = Company( name=company['companyShortName'], logo_uri='https://static.lagou.com/thumbnail_160x160/' + company['companyLogo'], website='https://shiyanlou.com', introduction=['companyFeatures'], city=company['city'], domain=company['industryField'], finance=company['financeStage'] ) d.user_id = c.id db.session.add(d) db.session.commit()
def update_profile(self, user): if user.company: company = user.company else: company = Company() company.user_id = user.id self.populate_obj(company) db.session.add(user) db.session.add(company) db.session.commit()
def create_company(self): company = Company() company.user_id = current_user.id company.company_name = self.company_name.data company.offical_websit = self.offical_websit.data company.address = self.offical_websit.data company.company_TEL = self.company_TEL.data company.description = self.description.data db.session.add(company) db.session.commit() return company
def update(self, company): if self.password.data: company.password = self.password.data if company.company_msg: company_msg = company.company_msg else: company_msg = Company() company_msg.user_id = company.id self.populate_obj(company) self.populate_obj(company_msg) db.session.add(company_msg) db.session.add(company) db.session.commit()
def fake_data(self): for company in self.companies[:]: print(company["name"]) # 创建企业用户 c = User( username=company["name"], email=fake.email(), role=User.ROLE_COMPANY ) c.password = "******" db.session.add(c) try: db.session.commit() except: db.session.rollback() continue # 创建企业信息 d = Company( name=company["name"], email=c.email, logo=company["logo"], site=company["site"], location=company["localtion"], description = company["description"], about = company["about"].strip("0/1000取消保存").strip("关于我们"), tags=company["tags"] ) d.user_id = c.id db.session.add(d) db.session.commit() # 发布企业职位 job_list = self.get_job(company["id"]) for item in job_list: job = Job( name=item["name"], salary_low=int(item["salary_low"].strip("k")) * 1000, salary_high=int(item["salary_high"].strip("k")) * 1000, location=item["location"], tags=item["tags"], experience_requirement=item["experience_requirement"], degree_requirement=item["degree_requirement"], description =item["raw_description"] ) job.company_id = d.id db.session.add(job) db.session.commit()
def update_profile(self, user): user.username = self.username.data user.email = self.email.data if user.detail: detail = user.detail else: detail = Company() detail.user_id = user.id detail.contact = 'x' self.populate_obj(detail) db.session.add(user) db.session.add(detail) db.session.commit()
def updated_profile(self, company): company.name = self.name.data company.email = self.email.data if self.password.data: company.password = self.password.data if company.company_msg: company_msg = company.company_msg else: company_msg = Company() company_msg.user_id = company.id self.populate_obj(company_msg) db.session.add(company_msg) db.session.add(company) db.session.commit()
def ComupForm(self, user): user.username = self.name.data user.email = self.email.data user.role = 20 if self.password.data: user.password = self.password.data if user.company: company = user.company else: company = Company() company.user_id = user.id self.populate_obj(company) 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.detail: detail = user.detail else: detail = Company() detail.user_id = user.id self.populate_obj(detail) db.session.add(user) db.session.add(detail) db.session.commit()
def update(self, company): company.username = self.username.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 = Company() detail.user_id = company.id detail.website = self.website.data detail.description = self.description.data db.session.add(company) db.session.add(detail) db.session.commit()
def updated_profile(self, user): """ 更新 """ user.username = self.name.data user.email = self.email.data if self.password.data: user.password = self.password.data if user.company: company = user.company else: company = Company() company.user_id = user.id self.populate_obj(company) db.session.add(user) db.session.add(company) db.session.commit()
def update(self, 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.company: companydetail = company.company else: companydetail = Company() companydetail.user_id = company.id companydetail.website = self.website.data companydetail.description = self.description.data self.populate_obj(companydetail) db.session.add(company) db.session.add(companydetail) db.session.commit()
def update(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 company_info.website = self.site.data company_info.short_description = self.description.data db.session.add(user) db.session.add(company_info) db.session.commit()
def update(self, company): company.name = self.name.data company.email = self.email.data company.mobile = self.mobile.data if self.password.data: company.password = self.password.data if company.company_detail: company_detail = company.company_detail else: company_detail = Company() company_detail.user_id = company.id company_detail.site = self.site.data company_detail.description = self.description.data db.session.add(company) db.session.add(company_detail) db.session.commit()
def update_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: company = user.company else: company = Company() company.user_id = user.id self.populate_obj(obj=company) db.session.add(user) db.session.add(company) db.session.commit()
def company_add(): company = Company() user = User() user.role = 20 company.user_id = user.id form = CompanyForm() if form.validate_on_submit(): if Company.query.filter_by(name=form.name.data): flash ('公司名称已存在' ,'success') return render_template('/admin/company_add.html', form=form) form.populate_obj(company) user.password = form.password.data db.session.add(company) db.session.add(user) db.session.commit() flash('编辑用户信息成功', 'success') return redirect(url_for('admin.users')) return render_template('/admin/company_edit.html', form=form)
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 iter_companies(): with open(os.path.join(os.path.dirname(__file__), '..', 'datas', 'companies.json')) as f: companies = json.load(f) for i, company in enumerate(companies): user = User.query.get(i+1) #一个企业用户对应一个企业信息 company = Company( name = company['name'], logo = company['logo'], site = fake_cn.url(), addr = company['addr'], email = fake_cn.email(), description = company['description'], about = company['about'], tags = company['tags'], welfares = company['welfares'], ) company.user_id = user.id company.user = user db.session.add(company) db.session.commit()
def Company_update(self, user): user.username = self.username.data user.email = self.email.data if self.password.data: #密码判断,如果修改了,则保存新密码 user.password = self.password.data if user.company: #判断用户在公司数据库中是否存在 tmp = user.company #如果存在,获取公司数据表对象 else: tmp = Company() #如果不存在,新建公司数据表对象 tmp.user_id = user.id #公司数据表外链到用户表id中 self.populate_obj(tmp) #提交表单数据赋值到公司表中 db.session.add(user) db.session.add(tmp) try: db.session.commit() except: db.session.rollback() flash('数据提交失败', 'success') return user
def profile(): company = Company.query.filter_by(user_id=current_user.id) if not company: company = Company() company.user_id = current_user.id form = CompanyForm() else: form = CompanyForm(obj=company) if form.validate_on_submit: if not company.name: if Company.query.filter_by(name=form.name.data): flash('公司名已被注册', 'success') return render_tempalte('company/profile.html', form=form) else: if company.name != form.name.data: if Company.query.filter_by(name=form.name.data): flash('公司名已被注册', 'success') return render_tempalte('company/profile.html', form=form) form.populate_obj(company) form.create_company(company) flash('编辑成功', 'success') return render_tempalte('company/profile.html', form=form)
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()
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)