From f52621a2676b6f65f05719fc2d96abd7b2bbb887 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Sun, 24 Nov 2019 17:14:32 +0300 Subject: [PATCH] allow to run feed task from interface --- feeds/templates/cabinet/feeds/feed_form.html | 5 ++++- feeds/views.py | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/feeds/templates/cabinet/feeds/feed_form.html b/feeds/templates/cabinet/feeds/feed_form.html index a625dae..7b373c1 100644 --- a/feeds/templates/cabinet/feeds/feed_form.html +++ b/feeds/templates/cabinet/feeds/feed_form.html @@ -34,7 +34,10 @@ {% bootstrap_form config_form layout='horizontal' %} diff --git a/feeds/views.py b/feeds/views.py index 2c2173e..5687487 100644 --- a/feeds/views.py +++ b/feeds/views.py @@ -10,6 +10,7 @@ from django.views.generic.detail import SingleObjectMixin from cabinet.utils import CabinetViewMixin from feeds.models import Feed from feeds.modules import * +from feeds.tasks import execute_feed from feeds.utils import BaseFeedConfigView @@ -32,9 +33,12 @@ class FeedConfigEditView(BaseFeedConfigView, SingleObjectMixin): sidebar_section = 'feeds' def form_valid(self, feed_form, config_form): - feed_form.save() + feed = feed_form.save() config_form.save() - messages.success(self.request, 'Config was successfully saved') + if 'run' in self.request.POST: + execute_feed.apply_async(args=(feed.pk,), shadow=str(feed)) + else: + messages.success(self.request, 'Config was successfully saved') return HttpResponseRedirect('') def get_content_type(self):