From 890b8b44938b5b3c97819820df6332a816bce1ab Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Thu, 28 Nov 2019 00:12:36 +0300 Subject: [PATCH] hide mtg fields --- ...5_cyberlinabotmoduleconfig_mtg_train_new.py | 18 ++++++++++++++++++ bots/migrations/0016_auto_20191128_0011.py | 18 ++++++++++++++++++ bots/migrations/0017_auto_20191128_0012.py | 18 ++++++++++++++++++ bots/modules/cyberlina.py | 7 +++++-- 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 bots/migrations/0015_cyberlinabotmoduleconfig_mtg_train_new.py create mode 100644 bots/migrations/0016_auto_20191128_0011.py create mode 100644 bots/migrations/0017_auto_20191128_0012.py diff --git a/bots/migrations/0015_cyberlinabotmoduleconfig_mtg_train_new.py b/bots/migrations/0015_cyberlinabotmoduleconfig_mtg_train_new.py new file mode 100644 index 0000000..ac32d04 --- /dev/null +++ b/bots/migrations/0015_cyberlinabotmoduleconfig_mtg_train_new.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0rc1 on 2019-11-27 21:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bots', '0014_auto_20191127_2223'), + ] + + operations = [ + migrations.AddField( + model_name='cyberlinabotmoduleconfig', + name='mtg_train_new', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/bots/migrations/0016_auto_20191128_0011.py b/bots/migrations/0016_auto_20191128_0011.py new file mode 100644 index 0000000..f4c5c98 --- /dev/null +++ b/bots/migrations/0016_auto_20191128_0011.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0rc1 on 2019-11-27 21:11 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bots', '0015_cyberlinabotmoduleconfig_mtg_train_new'), + ] + + operations = [ + migrations.RenameField( + model_name='cyberlinabotmoduleconfig', + old_name='mtg_train', + new_name='_mtg_corpus', + ), + ] diff --git a/bots/migrations/0017_auto_20191128_0012.py b/bots/migrations/0017_auto_20191128_0012.py new file mode 100644 index 0000000..e39b19a --- /dev/null +++ b/bots/migrations/0017_auto_20191128_0012.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0rc1 on 2019-11-27 21:12 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bots', '0016_auto_20191128_0011'), + ] + + operations = [ + migrations.RenameField( + model_name='cyberlinabotmoduleconfig', + old_name='mtg_train_new', + new_name='mtg_train', + ), + ] diff --git a/bots/modules/cyberlina.py b/bots/modules/cyberlina.py index a87d281..9f62227 100644 --- a/bots/modules/cyberlina.py +++ b/bots/modules/cyberlina.py @@ -26,6 +26,7 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig): welcome_reactions = JSONField(default='[]') inline_reactions = JSONField(default='[]') _mtg_data = JSONField(default={}, blank=True, null=True) + _mtg_corpus = models.TextField(null=True, blank=True) mtg_train = models.TextField(null=True, blank=True) MODULE_NAME = 'Киберлиночка' @@ -38,7 +39,7 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig): 'welcome_reactions': JSONEditor(), 'inline_reactions': JSONEditor(), } - EXCLUDE_FIELDS = '_mtg_data', + EXCLUDE_FIELDS = '_mtg_data', '_mtg_corpus', def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -120,7 +121,9 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig): def save(self, force_insert=False, force_update=False, using=None, update_fields=None): if self.mtg_train: - self._mtg_data = markovify.Text(self.mtg_train).to_dict() + self._mtg_corpus += '\n' + self.mtg_train + self._mtg_data = markovify.Text(self._mtg_corpus).to_dict() + self.mtg_train = None super().save(force_insert, force_update, using, update_fields)