From 6058272af00e1f2eeae534b20e17e77a441321e9 Mon Sep 17 00:00:00 2001 From: kemu3007 Date: Mon, 2 Nov 2020 14:25:22 +0900 Subject: [PATCH] =?UTF-8?q?#214=20term=E3=81=AB\xa0=E3=81=8C=E5=90=AB?= =?UTF-8?q?=E3=81=BE=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=81=B8=E3=81=AE=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog.rst | 2 +- .../versions/aa8a8e0293ac_replace_nbsp.py | 36 +++++++++++++++++++ src/haro/plugins/create.py | 4 +++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/alembic/migrations/versions/aa8a8e0293ac_replace_nbsp.py diff --git a/ChangeLog.rst b/ChangeLog.rst index 6972a3b..afa077b 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -5,7 +5,7 @@ Unreleased Release Notes - 2020-11-02 -------------------------- - [#213] リリースノートの最新バージョンの記述を返すversionコマンドを追加 - +- [#214] URLを含む語録が削除できないバグ修正 Release Notes - 2020-10-30 -------------------------- diff --git a/src/alembic/migrations/versions/aa8a8e0293ac_replace_nbsp.py b/src/alembic/migrations/versions/aa8a8e0293ac_replace_nbsp.py new file mode 100644 index 0000000..8459571 --- /dev/null +++ b/src/alembic/migrations/versions/aa8a8e0293ac_replace_nbsp.py @@ -0,0 +1,36 @@ +"""replace   + +Revision ID: aa8a8e0293ac +Revises: 98ecbc1e5b66 +Create Date: 2020-11-02 12:48:17.045798 + +""" +import os + +import sqlalchemy as sa +from sqlalchemy.orm import sessionmaker + +from alembic import op +from haro.plugins.create_models import Term + +# revision identifiers, used by Alembic. +revision = 'aa8a8e0293ac' +down_revision = '98ecbc1e5b66' +branch_labels = None +depends_on = None + +engine = sa.create_engine(os.environ.get("SQLALCHEMY_URL")) +Session = sessionmaker(bind=engine) + +def upgrade(): + # ハイパーリンクがTerm.wordに含まれている場合、半角スペースが\xa0になってしまっているケースが存在するため置き換える + s = Session() + terms = s.query(Term).filter(Term.word.like('%\xa0%')) + print(terms) + for term in terms: + term.word = term.word.replace('\xa0', ' ') + s.commit() + + +def downgrade(): + pass diff --git a/src/haro/plugins/create.py b/src/haro/plugins/create.py index 15a6b65..09c7c24 100644 --- a/src/haro/plugins/create.py +++ b/src/haro/plugins/create.py @@ -308,6 +308,8 @@ def del_term(message, command, word): :param str command: 登録済のコマンド名 :param str word: 削除する語録 """ + # ハイパーリンクをコピペした際前後のスペースが\xa0になっているケースがあるため変換 + word = word.replace('\xa0', ' ') s = Session() term = (s.query(Term) .filter(Term.create_command == command.id) @@ -330,6 +332,8 @@ def add_term(message, command, word): :param str command: 登録済のコマンド名 :param str word: 登録する語録 """ + # ハイパーリンクをコピペした際前後のスペースが\xa0になっているケースがあるため変換 + word = word.replace('\xa0', ' ') s = Session() term = (s.query(Term) .select_from(join(Term, CreateCommand))