def edit(id: int, bot_repository: IBotRepository): # bot data 取得 bot_service = BotService(bot_repository) bot = bot_service.find_by_id(id) if bot is None: return render_template('admin/404.html'), 404 form = BotForm() if request.method == 'POST': bot.name = request.form['name'] bot.enable_flag = 'enable_flag' in request.form and request.form[ 'enable_flag'] == 'true' if form.validate_on_submit(): bot_service.edit(bot) return redirect(url_for('admin/bot.detail', id=id)) return render_template('admin/bot/input.html', form=form, bot=bot, operation='編集')
def fit(id: int, faq_list_id: int, faq_list_repository: IFaqListRepository, bot_repository: IBotRepository, faq_repository: IFaqRepository): # bot data bot_service = BotService(bot_repository) bot = bot_service.find_by_id(id) # faq_list data faq_list_service = FaqListService(faq_list_repository, faq_repository) faq_list = faq_list_service.find_by_id(faq_list_id) # check exist if bot is None or faq_list is None: return render_template('admin/404.html'), 404 bot_service.fit(bot_id=id, faq_list_id=faq_list_id) return redirect(url_for('admin/bot.detail', id=id))
def file_upload(id: int, faq_repository: IFaqRepository, faq_list_repository: IFaqListRepository, bot_repository: IBotRepository): bot_service = BotService(bot_repository) bot = bot_service.find_by_id(id) if bot is None: return render_template('admin/404.html'), 404 faq_file_import_service = FaqFileImportService( faq_repository=faq_repository, faq_list_repository=faq_list_repository) faq_file_import = faq_file_import_service.get_new_obj(bot=bot) form = FaqFileUploadForm() if request.method == 'POST': faq_file_import.name = request.form['name'] if form.validate_on_submit(): # build file_path file = request.files['faq_list'] filename = secure_filename(file.filename) file_path = os.path.join(current_app.config['FAQ_FILE_UPLOAD_DIR'], filename) # file save file.save(file_path) faq_file_import.file_path = file_path # import faq_file_import_service.import_tsv(faq_file_import) return redirect(url_for('admin/bot.detail', id=id)) return render_template('admin/faq/file_import.html', faq_file_import=faq_file_import, form=form)
def detail(id: int, bot_repository: IBotRepository): bot_service = BotService(bot_repository) bot = bot_service.find_by_id(id) return render_template('admin/bot/detail.html', bot=bot)