def get_company(company_external_id): company = CompaniesFinder.get_from_external_id(company_external_id) image_path = CompaniesHandler.find_image(company.name) return render_template('admin/companies/update_company.html', company=company, image=image_path, error=None)
def add_auction_participant(auction_external_id): auction = AuctionsFinder.get_auction_by_external_id(auction_external_id) if auction is None: return APIErrorValue('Couldnt find auction').json(400) company_external_id = request.form.get('company_external_id') if company_external_id is None: return redirect(url_for('admin_api.auction_participants_dashboard', auction_external_id=auction_external_id)) company = CompaniesFinder.get_from_external_id(company_external_id) if company is None: return APIErrorValue('Couldnt find company').json(400) AuctionsHandler.add_auction_participant(auction, company) return redirect(url_for('admin_api.auction_participants_dashboard', auction_external_id=auction_external_id))
def delete_company(company_external_id): company = CompaniesFinder.get_from_external_id(company_external_id) if company is None: return APIErrorValue('Couldnt find company').json(500) name = company.name for company_user in company.users: CompanyUsersHandler.delete_company_user(company_user) if CompaniesHandler.delete_company(company): return redirect(url_for('admin_api.companies_dashboard')) else: image_path = CompaniesHandler.find_image(name) return render_template('admin/companies/update_company.html', company=company, image=image_path, error="Failed to delete company!")
def update_company(company_external_id): company = CompaniesFinder.get_from_external_id(company_external_id) if company is None: return APIErrorValue('Couldnt find company').json(500) name = request.form.get('name') link = request.form.get('link') email = request.form.get('email') business_area = request.form.get('business_area') show_in_website = request.form.get('show_in_website') partnership_tier = request.form.get('partnership_tier') evf_username = request.form.get('evf_username') evf_password = request.form.get('evf_password') cvs_access = request.form.get('cvs_access') if partnership_tier == "": partnership_tier = None if show_in_website == 'True': show_in_website = True else: show_in_website = False if cvs_access == 'True': cvs_access = True else: cvs_access = False image_path = CompaniesHandler.find_image(name) old_company_name = company.name updated_company = CompaniesHandler.update_company( company=company, name=name, email=email, business_area=business_area, link=link, show_in_website=show_in_website, partnership_tier=partnership_tier, evf_username=evf_username, evf_password=evf_password, cvs_access=cvs_access) if updated_company is None: return render_template('admin/companies/update_company.html', company=company, image=image_path, error="Failed to update company!") if old_company_name != name: RenameImageService('static/companies', old_company_name, name).call() if 'file' in request.files: file = request.files['file'] result, msg = CompaniesHandler.upload_image(file, name) if result == False: return render_template('admin/companies/update_company.html', company=updated_company, image=image_path, error=msg) return redirect(url_for('admin_api.companies_dashboard'))
def create_user(): # extract form parameters name = request.form.get('name') username = request.form.get('username') email = request.form.get('email', None) role = request.form.get('role', None) post = request.form.get('post', None) evf_username = request.form.get('evf_username', None) evf_password = request.form.get('evf_password', None) # check if is creating company user company_external_id = request.form.get('company_external_id') if company_external_id is not None: company = CompaniesFinder.get_from_external_id(company_external_id) company_id = company.id if company is None: return 'No company found', 404 # extract food_manager from parameters food_manager = request.form.get('food_manager', None) if food_manager == 'True': food_manager = True elif food_manager == 'False': food_manager = False else: food_manager = None # create new company user if company_external_id: company_user = CompanyUsersHandler.create_company_user( name, username, email, company_id, post, food_manager, evf_username, evf_password) if not company_user: return render_template('admin/users/add_company_user.html', \ user=current_user, \ companies=CompaniesFinder.get_all(), \ roles=GetRolesService.call(), \ error="Failed to create user!") if not UsersHandler.join_channel(company_user.user, company.chat_id, company.chat_code): CompanyUsersHandler.delete_company_user(company_user) return render_template('admin/users/add_company_user.html', \ user=current_user, \ companies=CompaniesFinder.get_all(), \ roles=GetRolesService.call(), \ error="Failed to create user!") for activity in company_user.company.activities: if activity.chat_id: if not ActivitiesHandler.join_channel(company_user.user, activity): CompanyUsersHandler.delete_company_user(company_user) return render_template('admin/users/add_company_user.html', \ user=current_user, \ companies=CompaniesFinder.get_all(), \ roles=GetRolesService.call(), \ error="Failed to create user!") else: if role not in GetRolesService.call(): return 'Wrong role type provided', 404 else: role = RolesEnum[role] user = UsersHandler.create_user( name=name, username=username, email=email, role=role, password=GenerateCredentialsService().call()) if user is None: return render_template('admin/users/add_user.html', \ roles=GetRolesService.call(), \ error="Failed to create user!") return redirect(url_for('admin_api.users_dashboard'))