There will be a new admin action "Export to JSON" that will export the
latest content from all the pages selected in the admin list view.
There will be a new file upload widget and "Import from JSON" button
at the bottom of the admin view that will update or create all the
pages in the JSON file uploaded.
Importing will fail with an error message and no pages will be imported if:
- a template in any exported page doesn't exist in the current site
- any content blocks in exported page don't exist in corresponding
template on current site
- a page was exported without all its parent pages also being
exported and any of those missing parent pages don't already exist in
the current site (i.e. empty parent pages will not be created)
- none of the languages in the pages exported exist in the current site
Importing will discard data with a warning, but still proceed with the
import if:
- some languages in the pages exported don't exist in the current site
- page author doesn't exist in current site (will use current user instead)
- site domains are not available in current site (use current one instead)
This is the format of the JSON file. Pages are in-order (top to bottom
in the admin list view). Any fields set to null in the model are not
included as keys in the page object exported:
{
"gerbi_cms_page_export_version": 1,
"pages": [
{
"complete_slug": {lang1: get_complete_slug(lang1), ...},
# root slug always included
"title": {lang1: title(lang1), ...},
"author_email": author.email,
"creation_date": creation_date,
"publication_date": publication_date,
"publication_end_date": publication_end_date,
"last_modification_date": last_modification_date,
"status": get_status_display(),
"template": template,
"delegate_to": delegate_to, # I'm not sure how this one works
"freeze_date": freeze_date,
"sites": [site1.domainname, ...],
"redirect_to_url": redirect_to_url,
"redirect_to_complete_slug": {lang1:
redirect_to.get_complete_slug(lang1), ...},
"content": {
ctype1: {lang1: get_content(lang1, ctype1), ...},
...
}
},
...
]
}
This proposal doesn't cover tags. I don't use taggit myself, so I
don't know what's involved with including them.
Open question: can I just include "delegate_to" as text in the JSON
file and expect it to do something reasonable when imported? I'm not
sure how this feature works.
Ian
This code is working really well for me now with Django 1.2 and 1.4.
I've also just fixed a poor javascript interaction when
expanding/collapsing/moving pages in the admin list and using the
select-all box.
I've manually tested it on the example site and a client's site data
with about 150 pages with most pages in two languages. The
redirect_to pages are working. The "language up to date" status of
every page is also correct after importing.
User docs and automated testing is the next part that is required.
Ian
If anyone would like to follow along my progress is up at:
https://github.com/wardi/django-page-cms/tree/feature-json-export
It's build on some changes I made to support django 1.4 but it should
be easy to rebase if you don't want those changes:
git rebase --onto $whatever django-1.4-compat feature-json-export
i.e. the relevant changes are:
git log django-1.4-compat..feature-json-export