From b0d651ee92b4a2220f45638a28ee0c2d4e2c9622 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Sat, 19 Jan 2019 05:50:16 +0300 Subject: [PATCH] move modules out --- feeds/admin.py | 4 ++-- feeds/migrations/0003_auto_20190119_0249.py | 18 ++++++++++++++++++ feeds/models.py | 12 ------------ feeds/modules/__init__.py | 3 +++ feeds/modules/echo.py | 13 +++++++++++++ feeds/views.py | 3 ++- 6 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 feeds/migrations/0003_auto_20190119_0249.py create mode 100644 feeds/modules/__init__.py create mode 100644 feeds/modules/echo.py diff --git a/feeds/admin.py b/feeds/admin.py index a91182f..9271d17 100644 --- a/feeds/admin.py +++ b/feeds/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin -from .models import Feed, EchoFeedModuleConfig - +from .models import Feed +from feeds.modules.echo import EchoFeedModuleConfig admin.site.register(Feed) admin.site.register(EchoFeedModuleConfig) diff --git a/feeds/migrations/0003_auto_20190119_0249.py b/feeds/migrations/0003_auto_20190119_0249.py new file mode 100644 index 0000000..7066b32 --- /dev/null +++ b/feeds/migrations/0003_auto_20190119_0249.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2019-01-19 02:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('feeds', '0002_feed_lock'), + ] + + operations = [ + migrations.AlterField( + model_name='feed', + name='check_interval', + field=models.DurationField(help_text='in seconds'), + ), + ] diff --git a/feeds/models.py b/feeds/models.py index 454ea5d..d598770 100644 --- a/feeds/models.py +++ b/feeds/models.py @@ -54,15 +54,3 @@ class FeedModuleConfig(models.Model): class Meta: abstract = True - - -class EchoFeedModuleConfig(FeedModuleConfig): - message = models.TextField() - - MODULE_NAME = 'Echo' - - def execute(self, bot: TeleBot, chat_id, last_id): - bot.send_message(chat_id, self.message) - - -FEED_MODULES = [EchoFeedModuleConfig] diff --git a/feeds/modules/__init__.py b/feeds/modules/__init__.py new file mode 100644 index 0000000..db82692 --- /dev/null +++ b/feeds/modules/__init__.py @@ -0,0 +1,3 @@ +from .echo import EchoFeedModuleConfig + +FEED_MODULES = [EchoFeedModuleConfig] diff --git a/feeds/modules/echo.py b/feeds/modules/echo.py new file mode 100644 index 0000000..a6d67fe --- /dev/null +++ b/feeds/modules/echo.py @@ -0,0 +1,13 @@ +from django.db import models +from telebot import TeleBot + +from feeds.models import FeedModuleConfig + + +class EchoFeedModuleConfig(FeedModuleConfig): + message = models.TextField() + + MODULE_NAME = 'Echo' + + def execute(self, bot: TeleBot, chat_id, last_id): + bot.send_message(chat_id, self.message) diff --git a/feeds/views.py b/feeds/views.py index 062e670..827c24c 100644 --- a/feeds/views.py +++ b/feeds/views.py @@ -7,7 +7,8 @@ from django.views.generic import ListView from django.views.generic.detail import SingleObjectMixin from cabinet.utils import CabinetViewMixin -from feeds.models import Feed, FEED_MODULES +from feeds.models import Feed +from feeds.modules import * from feeds.utils import BaseFeedConfigView