-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Conversation
def handle(self, *args, **options): | ||
with open("articles.json", "r", encoding="utf-8") as f: | ||
articles = json.load(f) | ||
ArticlePage.objects.all().delete() |
There was a problem hiding this comment.
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))] |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
No description provided.