hide mtg fields

This commit is contained in:
bakatrouble 2019-11-28 00:12:36 +03:00
parent 1f8ffb5cba
commit 890b8b4493
4 changed files with 59 additions and 2 deletions

View File

@ -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),
),
]

View File

@ -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',
),
]

View File

@ -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',
),
]

View File

@ -26,6 +26,7 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig):
welcome_reactions = JSONField(default='[]') welcome_reactions = JSONField(default='[]')
inline_reactions = JSONField(default='[]') inline_reactions = JSONField(default='[]')
_mtg_data = JSONField(default={}, blank=True, null=True) _mtg_data = JSONField(default={}, blank=True, null=True)
_mtg_corpus = models.TextField(null=True, blank=True)
mtg_train = models.TextField(null=True, blank=True) mtg_train = models.TextField(null=True, blank=True)
MODULE_NAME = 'Киберлиночка' MODULE_NAME = 'Киберлиночка'
@ -38,7 +39,7 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig):
'welcome_reactions': JSONEditor(), 'welcome_reactions': JSONEditor(),
'inline_reactions': JSONEditor(), 'inline_reactions': JSONEditor(),
} }
EXCLUDE_FIELDS = '_mtg_data', EXCLUDE_FIELDS = '_mtg_data', '_mtg_corpus',
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*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): def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
if self.mtg_train: 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) super().save(force_insert, force_update, using, update_fields)