Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import script #46

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Add import script #46

wants to merge 11 commits into from

Conversation

codiebeulaine
Copy link
Contributor

No description provided.

def handle(self, *args, **options):
with open("articles.json", "r", encoding="utf-8") as f:
articles = json.load(f)
ArticlePage.objects.all().delete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be deleting all the pages?
If we import NiNyampinga content and then later Springster content this will delete all the NiNyampinga content, right?
Maybe filter by site instead?

body_raw = EditorHTMLConverter().from_database_format(
articles[article]["body"]
)
body = [("paragraph", RichText(body_raw))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this take into account articles with multiple paragraph blocks in the body or image blocks in the body?

slug=articles[article]["parent_section_slug"], locale=locale
)
parent.add_child(instance=article_page)
article_page.save_revision().publish()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there should be a "live" field in the exported data and we only publish if it was live on that side?
Or are we only exporting live content?



class Command(BaseCommand):
def handle(self, *args, **options):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably need to take in the ID of the site/homepage that we want to import this content to.

def handle(self, *args, **options):
with open("sections.json", "r", encoding="utf-8") as f:
sections = json.load(f)
SectionPage.objects.all().delete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about deleting all the section pages

for section in sections.keys():
locale = Locale.objects.get(language_code=sections[section]["locale"])
try:
new_section = SectionPage.objects.get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about handling duplicates on the site

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might have missed this comment. We should check if the section page already exists before trying to create it

sections[section]["section_parent_pk"]
]["locale"]
parent = SectionPage.objects.get(
slug=parent_slug, locale__language_code=parent_locale
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably need to be filtered by site as well

HomePage.objects.get(locale=locale)
.get_children()
.filter(title="Sections")
.first()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and a site filter here too

.first()
)
parent.add_child(instance=new_section)
new_section.save_revision().publish()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same comment here about checking if the section page is live in the export

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants