allow to run feed task from interface

This commit is contained in:
bakatrouble 2019-11-24 17:14:32 +03:00
parent 71d7ea7147
commit f52621a267
2 changed files with 10 additions and 3 deletions

View File

@ -34,7 +34,10 @@
{% bootstrap_form config_form layout='horizontal' %}
</div>
<footer class="card-footer text-right">
{% if feed %}<a href="#delete-modal" class="modal-basic btn btn-danger">Delete</a>{% endif %}
{% if feed %}
<a href="#delete-modal" class="modal-basic btn btn-danger">Delete</a>
<button type="submit" name="run" class="btn btn-secondary">Run now</button>
{% endif %}
<button type="submit" class="btn btn-primary">Save</button>
</footer>
</form>

View File

@ -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):