Skip to content
Snippets Groups Projects
Commit fba2fd0d authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

fix imports

parent 28e0bff4
No related branches found
No related tags found
2 merge requests!882Release,!877Fix article imports(?)
Pipeline #16285 passed
......@@ -2,7 +2,7 @@ from django import forms
from wagtail.admin.forms import WagtailAdminPageForm
from wagtail.models.collections import Collection
from shared.jekyll_import import JekyllArticleImporter
from .tasks import import_jekyll_articles
class SubscribeForm(forms.Form):
......@@ -65,19 +65,20 @@ class JekyllImportForm(WagtailAdminPageForm):
return cleaned_data
def handle_import(self, model):
def handle_import(self):
# TODO: Portable function
from .models import MainArticlePage
print("handling import")
JekyllArticleImporter(
article_parent_page=self.instance,
collection_id=self.cleaned_data["collection"].id,
url=self.cleaned_data["jekyll_repo_url"],
dry_run=self.cleaned_data["dry_run"],
use_git=True,
page_model=MainArticlePage,
).perform_import()
print(
import_jekyll_articles.delay(
article_parent_page_id=self.instance.id,
collection_id=self.cleaned_data["collection"].id,
url=self.cleaned_data["jekyll_repo_url"],
dry_run=self.cleaned_data["dry_run"],
use_git=True,
)
)
def save(self, commit=True):
if self.cleaned_data.get("do_import"):
......
......@@ -323,7 +323,8 @@ params = {}
class JekyllArticleImporter:
def __init__(
self,
article_parent_page,
article_parent_page_id: int,
article_parent_page_model,
collection_id: int,
url: str,
dry_run: bool,
......@@ -333,13 +334,19 @@ class JekyllArticleImporter:
self.page_model = page_model
# Params
self.article_parent_page = article_parent_page
self.article_parent_page_id = article_parent_page_id
self.article_parent_page_model = article_parent_page_model
self.collection = Collection.objects.get(id=collection_id)
self.dry_run = dry_run
self.use_git = use_git
self.url = url
# Computed props
# Computed proprs
import time
time.sleep(5)
self.article_parent_page = self.article_parent_page_model.objects.filter(id=self.article_parent_page_id).first()
self.path, self.repo_name = get_path_and_repo_name(self.url, self.use_git)
self.site = self.article_parent_page.get_site()
self.site_config = get_site_config(self.path)
......
import logging
from celery import shared_task
from shared.jekyll_import import JekyllArticleImporter
logger = logging.getLogger(__name__)
@shared_task()
def import_jekyll_articles(
article_parent_page_id,
collection_id,
url,
dry_run,
use_git,
):
from main.models import MainArticlePage, MainArticlesPage
return JekyllArticleImporter(
article_parent_page_id=article_parent_page_id,
article_parent_page_model=MainArticlesPage,
collection_id=collection_id,
url=url,
dry_run=dry_run,
use_git=use_git,
page_model=MainArticlePage,
).perform_import()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment