예제 #1
0
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='編集')
예제 #2
0
def edit(id: int, site_url_setting_repository: ISiteUrlSettingRepository,
         bot_repository: IBotRepository):
    site_url_setting_service = SiteUrlSettingService(
        site_url_setting_repository)
    site_url_setting = site_url_setting_service.find_by_id(id)
    site = site_url_setting.site

    bot_service = BotService(bot_repository)
    bots = bot_service.get_bots()

    form = SiteUrlSettingForm()

    if request.method == 'POST':
        site_url_setting.url_pattern = request.form['url_pattern']
        site_url_setting.bot_id = request.form['bot_id']
        site_url_setting.enable_flag = 'enable_flag' in request.form and request.form[
            'enable_flag'] == 'true'

        if form.validate_on_submit():
            site_url_setting_service.edit(site_url_setting)
            return redirect('/admin/site')

    return render_template('admin/site_url_setting/input.html',
                           site=site,
                           site_url_setting=site_url_setting,
                           bots=bots,
                           form=form,
                           operation='編集')
예제 #3
0
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))
예제 #4
0
def add(bot_repository: IBotRepository):

    bot_service = BotService(bot_repository)
    bot = bot_service.get_new_obj()
    form = BotForm()

    if request.method == 'POST':
        bot.name = request.form['name']

        if form.validate_on_submit():
            bot_service.add(bot)
            return redirect(url_for('admin/bot'))

    return render_template('admin/bot/input.html',
                           form=form,
                           bot=bot,
                           operation='追加')
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
def index(bot_repository: IBotRepository):
    bot_service = BotService(bot_repository=bot_repository)
    bots = bot_service.get_bots()

    return render_template('admin/bot/index.html', bots=bots)