export to JSON file

27 views
Skip to first unread message

Ian Ward

unread,
Apr 14, 2012, 8:43:31 PM4/14/12
to django-page-cms
(I guess I've been talking to myself this past few days. Here's an
update)

I'm working on this feature. Comments requested.

https://github.com/wardi/django-page-cms/tree/feature-json-export

This adds a new admin action "Export to JSON" that will export the
latest content from all the pages selected in the admin list view.

There is a new file upload widget and "Import" 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": 4,
"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,
"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), ...},
...
},
"content_language_updated_order": [lang1, ...]
},
...
]
}

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.
Reply all
Reply to author
Forward
0 new messages